start: prologue ( query | update ) queryunit: prologue query query: selectquery | constructquery | describequery | askquery prologue: basedecl? prefixdecl* basedecl: "BASE" IRIREF prefixdecl: "PREFIX" PNAME_NS IRIREF selectquery: project datasetclause* whereclause solutionmodifier subselect: project whereclause solutionmodifier project: "SELECT" ( "DISTINCT"| "REDUCED" )? ( ( var | aggregate | builtincall | functioncall | ( "(" expression ( "AS" var )? ")" ) )+ | "*" ) constructquery: "CONSTRUCT" constructtemplate datasetclause* whereclause solutionmodifier describequery: "DESCRIBE" ( varoririref+ | "*" ) datasetclause* whereclause? solutionmodifier askquery: "ASK" datasetclause* whereclause datasetclause: "FROM" ( defaultgraphclause | namedgraphclause ) defaultgraphclause: sourceselector namedgraphclause: "NAMED" sourceselector sourceselector: iriref whereclause: "WHERE"? groupgraphpattern solutionmodifier: groupclause? havingclause? orderclause? limitoffsetclauses? groupclause: "GROUP" "BY" groupcondition+ groupcondition: ( builtincall | functioncall | "(" expression ( "AS" var )? ")"| var ) havingclause: "HAVING" havingcondition+ havingcondition: constraint orderclause: "ORDER" "BY" ordercondition+ ordercondition: ( ( "ASC"| "DESC" ) brackettedexpression ) | ( constraint | var ) limitoffsetclauses: ( limitclause offsetclause? | offsetclause limitclause? ) limitclause: "LIMIT" INT offsetclause: "OFFSET" INT updateunit: prologue update update: update1+ update1: modify | insert | delete | load | clear | create | drop modify: "MODIFY" graphiri* "DELETE" constructtemplate "INSERT" constructtemplate updatepattern? delete: "DELETE" ( deletedata | deletetemplate ) deletedata: "DATA" ( "FROM"? iriref )* constructtemplate deletetemplate: ( "FROM"? iriref )* constructtemplate updatepattern? insert: "INSERT" ( insertdata | inserttemplate ) insertdata: "DATA" ( "INTO"? iriref )* constructtemplate inserttemplate: ( "INTO"? iriref )* constructtemplate updatepattern? graphiri: "GRAPH" iriref load: "LOAD" iriref+ ( "INTO" iriref )? clear: "CLEAR" graphiri? create: "CREATE" "SILENT"? graphiri drop: "DROP" "SILENT"? graphiri updatepattern: "WHERE"? groupgraphpattern groupgraphpattern: "{" ( subselect | groupgraphpatternsub ) "}" groupgraphpatternsub: triplesblock? ( ( graphpatternnottriples | filter ) "."? triplesblock? )* triplesblock: triplessamesubjectpath ( "." triplesblock? )? graphpatternnottriples: optionalgraphpattern | grouporuniongraphpattern | graphgraphpattern | existselt | notexistselt optionalgraphpattern: "OPTIONAL" groupgraphpattern graphgraphpattern: "GRAPH" varoririref groupgraphpattern existselt: "EXISTS" groupgraphpattern notexistselt: ( "UNSAID" | "NOT EXISTS" ) groupgraphpattern grouporuniongraphpattern: groupgraphpattern ( "UNION" groupgraphpattern )* filter: "FILTER" constraint constraint: brackettedexpression | builtincall | functioncall functioncall: iriref arglist arglist: ( NIL | "(" expression ( "," expression )* ")" ) constructtemplate: "{" constructtriples? "}" constructtriples: triplessamesubject ( "." triplessamesubject )* "."? triplessamesubject: varorterm propertylistnotempty | triplesnode propertylist propertylistnotempty: verb objectlist ( ";" ( verb objectlist )? )* propertylist: propertylistnotempty? objectlist: object ( "," object )* object: graphnode verb: varoririref | "a" triplessamesubjectpath: varorterm propertylistnotemptypath | triplesnode propertylistpath propertylistnotemptypath: ( verbpath | verbsimple ) objectlist ( ";" ( ( verbpath | verbsimple ) objectlist )? )* propertylistpath: propertylistnotempty? verbpath: path verbsimple: var path: pathalternative pathalternative: pathsequence ( "|" pathsequence )* pathsequence: patheltorreverse ( "/" patheltorreverse | "^" pathelt )* pathelt: pathprimary pathmod? patheltorreverse: pathelt | "^" pathelt pathmod: ( "*"| "?"| "+"| "{" ( integer ( "," ( "}"| integer "}" ) | "}" ) ) ) pathprimary: ( iriref | "a"| "(" path ")" ) integer: INT triplesnode: collection | blanknodepropertylist blanknodepropertylist: "[" propertylistnotempty "]" collection: "(" graphnode+ ")" graphnode: varorterm | triplesnode varorterm: var | graphterm varoririref: var | iriref var: VAR1 | VAR2 graphterm: iriref | rdfliteral | numericliteral | booleanliteral | blanknode | NIL expression: conditionalorexpression conditionalorexpression: conditionalandexpression ( "||" conditionalandexpression )* conditionalandexpression: valuelogical ( "&&" valuelogical )* valuelogical: relationalexpression relationalexpression: numericexpression ( "=" numericexpression | "!=" numericexpression | "<" numericexpression | ">" numericexpression | "<=" numericexpression | ">=" numericexpression )? numericexpression: additiveexpression additiveexpression: multiplicativeexpression ( "+" multiplicativeexpression | "-" multiplicativeexpression | ( numericliteralpositive | numericliteralnegative ) ( ( "*" unaryexpression ) | ( "/" unaryexpression ) )? )* multiplicativeexpression: unaryexpression ( "*" unaryexpression | "/" unaryexpression )* unaryexpression: "!" primaryexpression | "+" primaryexpression | "-" primaryexpression | primaryexpression primaryexpression: brackettedexpression | builtincall | irireforfunction | rdfliteral | numericliteral | booleanliteral | var | aggregate brackettedexpression: "(" expression ")" builtincall: "STR" "(" expression ")" | "LANG" "(" expression ")"| "LANGMATCHES" "(" expression "," expression ")"| "DATATYPE" "(" expression ")"| "BOUND" "(" var ")"| "COALESCE" arglist | "IF" "(" expression "," expression "," expression ")"| "sameTerm" "(" expression "," expression ")"| "isIRI" "(" expression ")"| "isURI" "(" expression ")"| "isBLANK" "(" expression ")"| "isLITERAL" "(" expression ")"| regexexpression | existsfunc | notexistsfunc regexexpression: "REGEX" "(" expression "," expression ( "," expression )? ")" existsfunc: "EXISTS" groupgraphpattern notexistsfunc: ( "UNSAID" | "NOT EXISTS" ) groupgraphpattern aggregate: ( "COUNT" "(" ( "*"| var | "DISTINCT" ( "*"| var ) ) ")"| "SUM" "(" expression ")"| "MIN" "(" expression ")"| "MAX" "(" expression ")"| "AVG" "(" expression ")" ) irireforfunction: iriref arglist? rdfliteral: string ( LANGTAG | ( "^^" iriref ) )? numericliteral: numericliteralunsigned | numericliteralpositive | numericliteralnegative numericliteralunsigned: INT | DECIMAL | DOUBLE numericliteralpositive: INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE numericliteralnegative: INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE booleanliteral: "true" | "false" string: STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 iriref: IRIREF | prefixedname prefixedname: PNAME_LN | PNAME_NS blanknode: BLANK_NODE_LABEL | ANON %import common (NUMBER, LETTER, ESCAPED_STRING, WS, DECIMAL, INT) %import common.SIGNED_FLOAT -> DOUBLE %import common._EXP -> EXPONENT PN_PREFIX: PN_CHARS_BASE ((PN_CHARS | ".")* PN_CHARS)? PNAME_LN: PNAME_NS PN_LOCAL PNAME_NS: PN_PREFIX? ":" ANON_WS: " " | "\t" | "\r" | "\n" ANON: "[" ANON_WS* "]" BASE_DIRECTIVE: "@base" BLANK_NODE_LABEL: "_:" (PN_CHARS_U | INT) ((PN_CHARS | ".")* PN_CHARS)? BOOLEAN_LITERAL: "true" | "false" ECHAR: "\\" /[\t\b\n\r\f"']/ EOL: /[\r\n]/+ // IRIREF: "<" (/[^\x00-\x20<>"{}|^`\\]/ | UCHAR | WS)* ">" // IRIREF: "<" (/[^\x00-\x20<>"{}|^`\\]/ | UCHAR)* ">" // IRIREF: "<" (PNCHARS | \x23 | \x25 | \x26 | \x28 | \x29 | \x2E | \x2F | \x3A | \x40 | \x5C | UCHAR)* ">" IRIREF: "<" (PN_CHARS | "." | ":" | "/" | "\\" | "#" | "@" | "%" | "&" | UCHAR )* ">" LANGTAG: "@" LETTER+ ("-" (LETTER INT)+ )* MACRO: "#Mode:" MACRO_VAL MACRO_VAL: "REPLACE" | "ADD" | "REMOVE" | "INITIAL_ONLY" NUMERIC_LITERAL: INT | DECIMAL | DOUBLE INTEGER_POSITIVE: "+" INT DECIMAL_POSITIVE: "+" DECIMAL DOUBLE_POSITIVE: "+" DOUBLE INTEGER_NEGATIVE: "-" INT DECIMAL_NEGATIVE: "-" DECIMAL DOUBLE_NEGATIVE: "-" DOUBLE PN_CHARS_BASE: /[A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\U00010000-\U000EFFFF]/ PN_CHARS_U: PN_CHARS_BASE | "_" PN_CHARS: PN_CHARS_U | /[\-0-9\u00B7\u0300-\u036F\u203F-\u2040]/ PN_LOCAL: (PN_CHARS_U | ":" | /[0-9]/ | PLX) ((PN_CHARS | "." | ":" | PLX)* (PN_CHARS | ":" | PLX))? PLX: PERCENT | PN_LOCAL_ESC PERCENT: "%" HEX~2 HEX: /[0-9A-Fa-f]/ PN_LOCAL_ESC: "\\" /[_~\.\-!$&'()*+,;=\/?#@%]/ BASE: ("B"|"b") ("A"|"a") ("S"|"s") ("E"|"e") PREFIX: ("P"|"p") ("R"|"r") ("E"|"e") ("F"|"f") ("I"|"i") ("X"|"x") QUICK_VAR_NAME: "?" PN_LOCAL UCHAR: "\\u" HEX~4 | "\\U" HEX~8 STRING: LONG_STRING | STRING_LITERAL_QUOTE | STRING_LITERAL_SINGLE_QUOTE FULLSTRING: STRING_LITERAL_QUOTE | STRING_LITERAL_SINGLE_QUOTE | STRING_LITERAL_LONG_SINGLE_QUOTE | STRING_LITERAL_LONG_QUOTE STRING_LITERAL1: STRING_LITERAL_QUOTE STRING_LITERAL2: STRING_LITERAL_SINGLE_QUOTE STRING_LITERAL_LONG1: STRING_LITERAL_LONG_SINGLE_QUOTE STRING_LITERAL_LONG2: STRING_LITERAL_LONG_QUOTE STRING_LITERAL_LONG_QUOTE: "\"\"\"" (/"|""/? (/[^"\\]/ | ECHAR | UCHAR))* "\"\"\"" STRING_LITERAL_LONG_SINGLE_QUOTE: "'''" (/'|''/? (/[^'\\]/ | ECHAR | UCHAR))* "'''" STRING_LITERAL_QUOTE: "\"" (/[^\x22\x5C\x0A\x0D]/ | ECHAR | UCHAR)* "\"" STRING_LITERAL_SINGLE_QUOTE: "'" (/[^\x27\x5C\x0A\x0D]/ | ECHAR | UCHAR)* "'" STD_STRING: /([ubf]?r?|r[ubf])("(?!"").*?(?