@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix n3: <http://www.w3.org/2000/10/swap/grammar/notation3#>.
@prefix : <http://www.w3.org/2000/10/swap/grammar/notation3#>.
@prefix re: <http://www.w3.org/2000/10/swap/grammar/regex#>.
@prefix g: <http://www.w3.org/2000/10/swap/grammar/ebnf#>.

:language rdfs:isDefinedBy <>; g:start :document.

:document rdfs:label "document"; rdf:value "1";
 rdfs:comment "[1] document ::= (statement \".\")*";
  g:star 
    [ g:seq (
      :statement
      "."
     ) ]
.

:formulacontent rdfs:label "formulacontent"; rdf:value "2";
 rdfs:comment "[2] formulacontent ::= (statement (\".\" statement)*)?";
  g:opt 
    [ g:seq (
      :statement
      [ g:star 
        [ g:seq (
          "."
          :statement
         ) ]
       ]
     ) ]
.

:statement rdfs:label "statement"; rdf:value "3";
 rdfs:comment "[3] statement  ::= declaration | universal | existential | simpleStatement";
  g:alt (
    :declaration
    :universal
    :existential
    :simpleStatement
   )
.

:universal rdfs:label "universal"; rdf:value "4";
 rdfs:comment "[4] universal ::= \"@forAll\" varlist";
  g:seq (
    "@forAll"
    :varlist
   )
.

:existential rdfs:label "existential"; rdf:value "5";
 rdfs:comment "[5] existential ::= \"@forSome\" varlist";
  g:seq (
    "@forSome"
    :varlist
   )
.

:varlist rdfs:label "varlist"; rdf:value "6";
 rdfs:comment "[6] varlist ::= (symbol (\",\" symbol)*)?";
  g:opt 
    [ g:seq (
      :symbol
      [ g:star 
        [ g:seq (
          ","
          :symbol
         ) ]
       ]
     ) ]
.

:declaration rdfs:label "declaration"; rdf:value "7";
 rdfs:comment "[7] declaration ::= \"@prefix\" prefix uriref |   \"@keywords\" (barename (\",\" barename)*)?";
  g:alt (
    [ g:seq (
      "@prefix"
      :prefix
      :uriref
     ) ]
    [ g:seq (
      "@keywords"
      [ g:opt 
        [ g:seq (
          :barename
          [ g:star 
            [ g:seq (
              ","
              :barename
             ) ]
           ]
         ) ]
       ]
     ) ]
   )
.

:barename rdfs:label "barename"; rdf:value "8";
 rdfs:comment "[8] barename ::= qname";
  g:seq ( :qname )
.

:simpleStatement rdfs:label "simpleStatement"; rdf:value "9";
 rdfs:comment "[9] simpleStatement ::= term propertylist";
  g:seq (
    :term
    :propertylist
   )
.

:propertylist rdfs:label "propertylist"; rdf:value "10";
 rdfs:comment "[10] propertylist ::= (property (\";\" property)*)?";
  g:opt 
    [ g:seq (
      :property
      [ g:star 
        [ g:seq (
          ";"
          :property
         ) ]
       ]
     ) ]
.

:property rdfs:label "property"; rdf:value "11";
 rdfs:comment "[11] property ::= (verb | inverb) term (\",\" term)*";
  g:seq (
    [ g:alt (
      :verb
      :inverb
     ) ]
    :term
    [ g:star 
      [ g:seq (
        ","
        :term
       ) ]
     ]
   )
.

:verb rdfs:label "verb"; rdf:value "12";
 rdfs:comment "[12] verb ::= \"@has\"? term | \"@a\" | \"=\" | \"=>\" | \"<=\"";
  g:alt (
    [ g:seq (
      [ g:opt 
        "@has"
       ]
      :term
     ) ]
    "@a"
    "="
    "=>"
    "<="
   )
.

:inverb rdfs:label "inverb"; rdf:value "12a";
 rdfs:comment "[12a] inverb ::= \"@is\" term \"@of\"";
  g:seq (
    "@is"
    :term
    "@of"
   )
.

:term rdfs:label "term"; rdf:value "13";
 rdfs:comment "[13] term ::= pathitem pathtail";
  g:seq (
    :pathitem
    :pathtail
   )
.

:pathtail rdfs:label "pathtail"; rdf:value "14";
 rdfs:comment "[14] pathtail ::= | \"!\" term | \"^\" term";
  g:alt (
    [ g:seq (
     ) ]
    [ g:seq (
      "!"
      :term
     ) ]
    [ g:seq (
      "^"
      :term
     ) ]
   )
.

:pathitem rdfs:label "pathitem"; rdf:value "15";
 rdfs:comment "[15] pathitem ::= symbol | evar | uvar | numeral | literal | \"{\" formulacontent \"}\" | \"[\" propertylist \"]\" |  \"(\"  term* \")\" | boolean";
  g:alt (
    :symbol
    :evar
    :uvar
    :numeral
    :literal
    [ g:seq (
      "{"
      :formulacontent
      "}"
     ) ]
    [ g:seq (
      "["
      :propertylist
      "]"
     ) ]
    [ g:seq (
      "("
      [ g:star 
        :term
       ]
      ")"
     ) ]
    :boolean
   )
.

:literal rdfs:label "literal"; rdf:value "16";
 rdfs:comment "[16] literal ::= (STRING_LITERAL2 | STRING_LITERAL_LONG2) (\"^^\" symbol) | langstring";
  g:alt (
    [ g:seq (
      [ g:alt (
        :STRING_LITERAL2
        :STRING_LITERAL_LONG2
       ) ]
      [ g:seq (
        "^^"
        :symbol
       ) ]
     ) ]
    :langstring
   )
.

:boolean rdfs:label "boolean"; rdf:value "17";
 rdfs:comment "[17] boolean ::= \"@true\" | \"@false\"";
  g:alt (
    "@true"
    "@false"
   )
.

:symbol rdfs:label "symbol"; rdf:value "18";
 rdfs:comment "[18] symbol ::= uriref | qname";
  g:alt (
    :uriref
    :qname
   )
.

:numeral rdfs:label "numeral"; rdf:value "19";
 rdfs:comment "[19] numeral ::= integer | double | decimal";
  g:alt (
    :integer
    :double
    :decimal
   )
.

:integer rdfs:label "integer"; rdf:value "26";
 rdfs:comment "[26] integer ::= [+-]? [0-9]+";
  re:seq (
    [ re:opt 
      [  re:matches "[+-]"  ]
     ]
    [ re:plus 
      [  re:matches "[0-9]"  ]
     ]
   )
.

:double rdfs:label "double"; rdf:value "27";
 rdfs:comment "[27] double	::= [+-]? [0-9]+ (\".\" [0-9]+)? ( [eE] [+-]? [0-9]+)";
  re:seq (
    [ re:opt 
      [  re:matches "[+-]"  ]
     ]
    [ re:plus 
      [  re:matches "[0-9]"  ]
     ]
    [ re:opt 
      [ re:seq (
        "."
        [ re:plus 
          [  re:matches "[0-9]"  ]
         ]
       ) ]
     ]
    [ re:seq (
      [  re:matches "[eE]"  ]
      [ re:opt 
        [  re:matches "[+-]"  ]
       ]
      [ re:plus 
        [  re:matches "[0-9]"  ]
       ]
     ) ]
   )
.

:decimal rdfs:label "decimal"; rdf:value "28";
 rdfs:comment "[28] decimal	::= [+-]? [0-9]+ (\".\" [0-9]+)?";
  re:seq (
    [ re:opt 
      [  re:matches "[+-]"  ]
     ]
    [ re:plus 
      [  re:matches "[0-9]"  ]
     ]
    [ re:opt 
      [ re:seq (
        "."
        [ re:plus 
          [  re:matches "[0-9]"  ]
         ]
       ) ]
     ]
   )
.

:uriref rdfs:label "uriref"; rdf:value "29";
 rdfs:comment "[29] uriref ::=	'<' ([^<>'{}|^`]-[#x01-#x20])* '>'";
  re:seq (
    "<"
    [ re:star 
      [ re:diff (
        [  re:matches "[^<>'{}|^`]"  ]
        [  re:matches "[\u0001-\u0020]"  ]
       ) ]
     ]
    ">"
   )
.

:qname rdfs:label "qname"; rdf:value "30";
 rdfs:comment "[30] qname  ::= prefix? localname";
  re:seq (
    [ re:opt 
      :prefix
     ]
    :localname
   )
.

:localname rdfs:label "localname"; rdf:value "31";
 rdfs:comment "[31] localname ::= (NameStartChar3|\"_\") NameChar3*";
  re:seq (
    [ re:alt (
      :NameStartChar3
      "_"
     ) ]
    [ re:star 
      :NameChar3
     ]
   )
.

:prefix rdfs:label "prefix"; rdf:value "32";
 rdfs:comment "[32] prefix  ::= ((\"_\" NameChar3+) | (NameStartChar3 NameChar3*))? \":\"";
  re:seq (
    [ re:opt 
      [ re:alt (
        [ re:seq (
          "_"
          [ re:plus 
            :NameChar3
           ]
         ) ]
        [ re:seq (
          :NameStartChar3
          [ re:star 
            :NameChar3
           ]
         ) ]
       ) ]
     ]
    ":"
   )
.

:NameStartChar3 rdfs:label "NameStartChar3"; rdf:value "33";
 rdfs:comment "[33] NameStartChar3	   ::=   	[A-Z] | [a-z]";
  re:alt (
    [  re:matches "[A-Z]"  ]
    [  re:matches "[a-z]"  ]
   )
.

:NameChar3 rdfs:label "NameChar3"; rdf:value "34";
 rdfs:comment "[34]   	NameChar3	   ::=   	NameStartChar3 | \"-\" | \"_\" | [0-9]";
  re:alt (
    :NameStartChar3
    "-"
    "_"
    [  re:matches "[0-9]"  ]
   )
.

:NameStartChar3x rdfs:label "NameStartChar3x"; rdf:value "33x";
 rdfs:comment "[33x] NameStartChar3x	   ::=   	[A-Z] | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]";
  re:alt (
    [  re:matches "[A-Z]"  ]
    [  re:matches "[a-z]"  ]
    [  re:matches "[\u00C0-\u00D6]"  ]
    [  re:matches "[\u00D8-\u00F6]"  ]
    [  re:matches "[\u00F8-\u02FF]"  ]
    [  re:matches "[\u0370-\u037D]"  ]
    [  re:matches "[\u037F-\u1FFF]"  ]
    [  re:matches "[\u200C-\u200D]"  ]
    [  re:matches "[\u2070-\u218F]"  ]
    [  re:matches "[\u2C00-\u2FEF]"  ]
    [  re:matches "[\u3001-\uD7FF]"  ]
    [  re:matches "[\uF900-\uFDCF]"  ]
    [  re:matches "[\uFDF0-\uFFFD]"  ]
    [  re:matches "[\u0000-\uFFFF]"  ]
   )
.

:NameChar3x rdfs:label "NameChar3x"; rdf:value "34x";
 rdfs:comment "[34x]   	NameChar3x	   ::=   	NameStartChar3 | \"-\" | \"_\" | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]";
  re:alt (
    :NameStartChar3
    "-"
    "_"
    [  re:matches "[0-9]"  ]
    [  re:matches "[\u00B7]"  ]
    [  re:matches "[\u0300-\u036F]"  ]
    [  re:matches "[\u203F-\u2040]"  ]
   )
.

:uvar rdfs:label "uvar"; rdf:value "35";
 rdfs:comment "[35] uvar ::= \"?\" localname";
  re:seq (
    "?"
    :localname
   )
.

:evar rdfs:label "evar"; rdf:value "36";
 rdfs:comment "[36] evar ::= \"_:\" localname";
  re:seq (
    "_:"
    :localname
   )
.

:langstring rdfs:label "langstring"; rdf:value "37";
 rdfs:comment "[37] langstring ::= (STRING_LITERAL2 | STRING_LITERAL_LONG2) \"@\" [a-z]+ (\"-\" [a-z0-9]+)*";
  re:seq (
    [ re:alt (
      :STRING_LITERAL2
      :STRING_LITERAL_LONG2
     ) ]
    "@"
    [ re:plus 
      [  re:matches "[a-z]"  ]
     ]
    [ re:star 
      [ re:seq (
        "-"
        [ re:plus 
          [  re:matches "[a-z0-9]"  ]
         ]
       ) ]
     ]
   )
.

:STRING_LITERAL2 rdfs:label "STRING_LITERAL2"; rdf:value "38";
 rdfs:comment "[38] STRING_LITERAL2 ::= '\"' ( [^#x22#x5C#x0A#x0D] | ECHAR | UCHAR)* '\"'";
  re:seq (
    "\""
    [ re:star 
      [ re:alt (
        [  re:matches "[^\u0022\\\u005C\u000A\u000D]"  ]
        :ECHAR
        :UCHAR
       ) ]
     ]
    "\""
   )
.

:STRING_LITERAL_LONG2 rdfs:label "STRING_LITERAL_LONG2"; rdf:value "39";
 rdfs:comment "[39] STRING_LITERAL_LONG2 ::= '\"\"\"' ( ( '\"' | '\"\"' )? ( [^#x22#x5C] | ECHAR | UCHAR ) )* '\"\"\"'";
  re:seq (
    "\"\"\""
    [ re:star 
      [ re:seq (
        [ re:opt 
          [ re:alt (
            "\""
            "\"\""
           ) ]
         ]
        [ re:alt (
          [  re:matches "[^\u0022\\\u005C]"  ]
          :ECHAR
          :UCHAR
         ) ]
       ) ]
     ]
    "\"\"\""
   )
.

:ECHAR rdfs:label "ECHAR"; rdf:value "40";
 rdfs:comment "[40] ECHAR ::= #x5C [tbnrf#x5C#x22']";
  re:seq (
    [  re:matches "[\\\u005C]"  ]
    [  re:matches "[tbnrf\\\u005C\u0022']"  ]
   )
.

:UCHAR rdfs:label "UCHAR"; rdf:value "41";
 rdfs:comment "[41]   UCHAR                   ::=   '\\' ( 'u' HEX HEX HEX HEX | 'U' HEX HEX HEX HEX HEX HEX HEX HEX )";
  re:seq (
    "\\"
    [ re:alt (
      [ re:seq (
        "u"
        :HEX
        :HEX
        :HEX
        :HEX
       ) ]
      [ re:seq (
        "U"
        :HEX
        :HEX
        :HEX
        :HEX
        :HEX
        :HEX
        :HEX
        :HEX
       ) ]
     ) ]
   )
.

:HEX rdfs:label "HEX"; rdf:value "42";
 rdfs:comment "[42]   HEX                     ::=   [0-9] | [A-F] | [a-f]";
  re:alt (
    [  re:matches "[0-9]"  ]
    [  re:matches "[A-F]"  ]
    [  re:matches "[a-f]"  ]
   )
.
