DOCUMENT START TOKENS // -------- PATH TOKEN : { | | | "> | } // ------------------------------------------ // Tokens // Comments and whitespace SKIP : { " " | "\t" | "\n" | "\r" | "\f" } TOKEN : { <#WS: " " | "\t" | "\n" | "\r" | "\f"> } SPECIAL : { } // ------------------------------------------------- // Keyworks : directives before LANGTAG // Before any HEX rule! TOKEN : { | | } TOKEN [IGNORE_CASE] : { | | > | )+ "." ()* | "." ()+)> | | "." (["0"-"9"])+ | (["0"-"9"])+ )> | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+> | <#QUOTE_3D: "\"\"\""> | <#QUOTE_3S: "\'\'\'"> | | )* "\'"> | )* "\""> | (~["\'","\\"] | | "\'" ~["\'"] | "\'\'" ~["\'"])* > | (~["\"","\\"] | | "\"" ~["\""] | "\"\"" ~["\""])* > | } TOKEN : { ","<","\"","{","}","^","\\","|","`","\u0000"-" "])* ">"> | )? ":"> | > | > | > | ()+ ("-" ()+)*> | <#A2Z: ["a"-"z","A"-"Z"]> | <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]> } TOKEN : { | | ( | )* > | | | | | ( | )* > | | | } // Operator TOKEN : { "> | | | | | | | | | } TOKEN : { <#PN_CHARS_BASE: ["A"-"Z"] | ["a"-"z"] | ["\u00c0"-"\u00d6"] | ["\u00d8"-"\u00f6"] | ["\u00f8"-"\u02ff"] | ["\u0370"-"\u037d"] | ["\u037f"-"\u1fff"] | ["\u200c"-"\u200d"] | ["\u2070"-"\u218f"] | ["\u2c00"-"\u2fef"] | ["\u3001"-"\ud7ff"] | ["\uf900"-"\ufffd"]> | <#PN_CHARS_U: | "_"> | <#PN_CHARS: | "-" | ["0"-"9"] | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"]> | <#PN_PREFIX: (( | ".")* )?> | <#PN_LOCAL: ( | ["0"-"9"]) (( | ".")* )?> | <#VARNAME: ( | ["0"-"9"]) ( | ["0"-"9"] | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"])*> } // Catch-all tokens. Must be last. // Any non-whitespace. Causes a parser exception, rather than a // token manager error (with hidden line numbers). // Only bad IRIs (e.g. spaces) now give unhelpful parse errors. TOKEN : { <#UNKNOWN: (~[" ","\t","\n","\r","\f"])+> } NON-TERMINALS // --- Entry point parse := ( Statement )* Statement := ( Directive | TriplesSameSubject ) Directive := IRI_REF | IRI_REF // N3 // ---- TRIPLES // <<<<< SPARQL extract TriplesSameSubject := VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList PropertyList := ( PropertyListNotEmpty )? // >>>>> SPARQL extract // Non-recursive for Turtle long PropertyList tests PropertyListNotEmpty := Verb ObjectList ( ( Verb ObjectList )? )* // Non-recursive for Turtle long PropertyList tests ObjectList := Object ( Object )* Object := GraphNode // <<<<< SPARQL extract Verb := ( IRIref | | ) // -------- Triple expansions // Anything that can stand in a node slot and which is // a number of triples TriplesNode := Collection | BlankNodePropertyList BlankNodePropertyList := PropertyListNotEmpty // ------- RDF collections // Code not as SPARQL/ARQ because of output ordering. Collection := ( GraphNode )+ // -------- Nodes in a graph pattern or template GraphNode := VarOrTerm | TriplesNode VarOrTerm := ( Var | GraphTerm | Formula ) Formula := TriplesSameSubject ( ( TriplesSameSubject )? )* // >>>>> SPARQL extract Var := GraphTerm := IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | // ---- Basic terms NumericLiteral := | | // >>>>> SPARQL extract // Langtag oddity. RDFLiteral := String ( Langtag | ( IRIref ) )? Langtag := ( | ) // >>>>> SPARQL extract BooleanLiteral := | // <<<<< SPARQL extract String := ( | | | ) IRIref := IRI_REF | PrefixedName PrefixedName := ( | ) BlankNode := | IRI_REF := DOCUMENT END