BNF for AQL.jj

TOKENS

<DEFAULT> TOKEN : {
<CARET: "^">
}

   
<DEFAULT> TOKEN : {
<DATASET: "dataset">
}

   
<DEFAULT> TOKEN : {
<LEFTPAREN: "(">
}

   
<DEFAULT> TOKEN : {
<RIGHTPAREN: ")">
}

   
<DEFAULT> TOKEN : {
<INTEGER_LITERAL: (<DIGIT>)+>
}

   
<DEFAULT> TOKEN : {
<NULL: "null">
}

   
<DEFAULT> TOKEN : {
<TRUE: "true">
}

   
<DEFAULT> TOKEN : {
<FALSE: "false">
}

   
<DEFAULT> TOKEN : {
<#DIGIT: ["0"-"9"]>
}

   
<DEFAULT> TOKEN : {
<DOUBLE_LITERAL: <INTEGER> | <INTEGER> ("." <INTEGER>)? | "." <INTEGER>>
| <FLOAT_LITERAL: <INTEGER> ("f" | "F") | <INTEGER> ("." <INTEGER> ("f" | "F"))? | "." <INTEGER> ("f" | "F")>
| <INTEGER: (<DIGIT>)+>
}

   
<DEFAULT> TOKEN : {
<#LETTER: ["A"-"Z","a"-"z"]>
}

   
<DEFAULT> TOKEN : {
<SPECIALCHARS: ["$","_","-"]>
}

   
<DEFAULT> TOKEN : {
<STRING_LITERAL: "\"" (<EscapeQuot> | ~["\""])* "\"" | "\'" (<EscapeApos> | ~["\'"])* "\'">
| <#EscapeQuot: "\\\"">
| <#EscapeApos: "\\\'">
}

   
<DEFAULT> TOKEN : {
<IDENTIFIER: (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
}

   
<DEFAULT> TOKEN : {
<VARIABLE: "$" <IDENTIFIER>>
}

   
<DEFAULT> SKIP : {
" "
| "\t"
| "\r"
| "\n"
}

   
<DEFAULT> SKIP : {
<"//" (~["\n"])* "\n">
}

   
<DEFAULT> SKIP : {
<"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")?>
}

   
<DEFAULT> SKIP : {
"/*" : INSIDE_COMMENT
}

   
<INSIDE_COMMENT> SPECIAL : {
<"+" (" ")* (~["*"])*>
}

   
<INSIDE_COMMENT> SKIP : {
"/*" : {
}

   
<INSIDE_COMMENT> SKIP : {
"*/" : {
| <~[]>
}

   

NON-TERMINALS

Statement ::= ( ( ( "use" | "declare" "function" | "create" ( "type" | "nodegroup" | "external" <DATASET> | <DATASET> | "index" | "dataverse" ) | "load" | "enlist" | "drop" ( <DATASET> | "index" | "nodegroup" | "type" | "dataverse" ) | "write" | "set" | "insert" | "delete" | "update" )* ( Query )? ) <EOF> )
InsertStatement ::= "into" <DATASET> <IDENTIFIER> <LEFTPAREN> Query <RIGHTPAREN> ";"
DeleteStatement ::= Variable "from" <DATASET> <IDENTIFIER> ( "where" Expression )? ";"
UpdateStatement ::= Variable "in" Expression "where" Expression <LEFTPAREN> ( UpdateClause ( "," UpdateClause )* ) <RIGHTPAREN> ";"
UpdateClause ::= "set" Expression ":=" Expression
| "insert" InsertStatement
| "delete" DeleteStatement
| "update" UpdateStatement
| "if" <LEFTPAREN> Expression <RIGHTPAREN> "then" UpdateClause ( "else" UpdateClause )?
SetStatement ::= <IDENTIFIER> <STRING_LITERAL> ";"
WriteStatement ::= ( ( "output" "to" <IDENTIFIER> ":" <STRING_LITERAL> ( "using" <STRING_LITERAL> )? ) | ( "into" <DATASET> <IDENTIFIER> <LEFTPAREN> Query <RIGHTPAREN> ) ) ";"
CreateIndexStatement ::= <IDENTIFIER> ( "if not exists" )? "on" <IDENTIFIER> <LEFTPAREN> ( <IDENTIFIER> ) ( "," <IDENTIFIER> )* <RIGHTPAREN> ( "type" ( "btree" | "keyword" | "qgram" | "rtree" ) ";" | ";" )
DataverseDeclaration ::= "dataverse" <IDENTIFIER> ";"
DropStatement ::= <IDENTIFIER> ( "if exists" )? ";"
IndexDropStatement ::= <IDENTIFIER> "." <IDENTIFIER> ( "if exists" )? ";"
NodeGroupDropStatement ::= <IDENTIFIER> ( "if exists" )? ";"
TypeDropStatement ::= <IDENTIFIER> ( "if exists" )? ";"
DataverseDropStatement ::= <IDENTIFIER> ( "if exists" )? ";"
CreateDataverseStatement ::= <IDENTIFIER> ( "if not exists" )? ( "with format" <STRING_LITERAL> )? ";"
LoadStatement ::= <DATASET> <IDENTIFIER> "from" ( <IDENTIFIER> ":" <STRING_LITERAL> ) ( "," <IDENTIFIER> ":" <STRING_LITERAL> )* ( "delimited" "by" <STRING_LITERAL> )? ( "pre-sorted" )? ";"
EnlistStatement ::= <DATASET> <IDENTIFIER> ";"
DatasetDeclaration ::= <IDENTIFIER> ( "if not exists" )? ( <LEFTPAREN> <IDENTIFIER> <RIGHTPAREN> )?
InternalDatasetDeclaration ::= "partitioned" "by" "key" <IDENTIFIER> ( "," <IDENTIFIER> )* "on" <IDENTIFIER> ";"
ExternalDatasetDeclaration ::= ( "hdfs" ( <STRING_LITERAL> ) | "splits" ( <IDENTIFIER> ":" <STRING_LITERAL> ) ( "," <IDENTIFIER> ":" <STRING_LITERAL> )* ) "using" ( <STRING_LITERAL> <LEFTPAREN> ( ( <LEFTPAREN> ( <STRING_LITERAL> ":" <STRING_LITERAL> ) <RIGHTPAREN> ) ( "," <LEFTPAREN> ( <STRING_LITERAL> ":" <STRING_LITERAL> ) <RIGHTPAREN> )* )? <RIGHTPAREN> ) ";"
NodegroupDeclaration ::= <IDENTIFIER> ( "if not exists" )? "on" <IDENTIFIER> ( "," <IDENTIFIER> )* ";"
TypeDeclaration ::= <IDENTIFIER> ( "if not exists" )? "as" ( TypeExpr )
TypeExpr ::= ( RecordTypeDef | TypeReference | OrderedListTypeDef | UnorderedListTypeDef )
RecordTypeDef ::= ( "closed" | "open" )? "{" ( RecordField ( "," RecordField )* )? "}"
RecordField ::= <IDENTIFIER> ":" ( TypeExpr ) ( "?" )?
TypeReference ::= <IDENTIFIER>
OrderedListTypeDef ::= "[" ( TypeExpr ) "]"
UnorderedListTypeDef ::= "<" ( TypeExpr ) ">"
FunctionDeclaration ::= <IDENTIFIER> <LEFTPAREN> ( <VARIABLE> ( "," <VARIABLE> )* )? <RIGHTPAREN> "{" Expression "}"
Query ::= Expression
Expression ::= ( OperatorExpr | IfThenElse | FLWOGR | QuantifiedExpression )
OperatorExpr ::= AndExpr ( "or" AndExpr )*
AndExpr ::= RelExpr ( "and" RelExpr )*
RelExpr ::= AddExpr ( ( "<" | ">" | "<=" | ">=" | "=" | "!=" | "~=" ) AddExpr )?
AddExpr ::= MultExpr ( ( "+" | "-" ) MultExpr )*
MultExpr ::= UnionExpr ( ( "*" | "/" | "%" | <CARET> | "idiv" ) UnionExpr )*
UnionExpr ::= UnaryExpr ( "union" ( UnaryExpr ) )*
UnaryExpr ::= ( ( "+" | "-" ) )? ValueExpr
ValueExpr ::= FieldOrIndexAccessor
FieldOrIndexAccessor ::= ( PrimaryExpr ) ( ( Field ) | ( Index ) )*
Field ::= "." <IDENTIFIER>
Index ::= "[" ( Expression | "?" ) "]"
PrimaryExpr ::= ( Literal | FunctionCallExpr | VariableRef | ListConstructor | RecordConstructor | ParenthesizedExpression )
Literal ::= ( <STRING_LITERAL> | <INTEGER_LITERAL> | <FLOAT_LITERAL> | <DOUBLE_LITERAL> | <NULL> | <TRUE> | <FALSE> )
VariableRef ::= <VARIABLE>
Variable ::= <VARIABLE>
ListConstructor ::= ( OrderedListConstructor | UnorderedListConstructor )
OrderedListConstructor ::= "[" ( Expression ( "," Expression )* )? "]"
UnorderedListConstructor ::= "<" ( Expression ( "," Expression )* )? ">"
RecordConstructor ::= "{" ( FieldBinding ( "," FieldBinding )* )? "}"
FieldBinding ::= Expression ":" Expression
FunctionCallExpr ::= ( <IDENTIFIER> | <DATASET> ) <LEFTPAREN> ( Expression ( "," Expression )* )? <RIGHTPAREN>
ParenthesizedExpression ::= <LEFTPAREN> Expression <RIGHTPAREN>
IfThenElse ::= "if" <LEFTPAREN> Expression <RIGHTPAREN> "then" Expression "else" Expression
FLWOGR ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
Clause ::= ( ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause )
ForClause ::= "for" Variable ( "at" Variable )? "in" ( Expression )
LetClause ::= "let" Variable ":=" Expression
WhereClause ::= "where" Expression
OrderbyClause ::= ( "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )* )
GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
LimitClause ::= "limit" Expression ( "offset" Expression )?
DistinctClause ::= "distinct" "by" Expression ( "," Expression )*
QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression