Updated grammar file for culebra language.

This commit is contained in:
yhirose 2015-09-16 12:01:40 -04:00
parent 6a6fb4a262
commit 83874e0924

View File

@ -1,78 +1,86 @@
PROGRAM <- _ STATEMENTS
STATEMENTS <- (STATEMENT (';' _)?)*
STATEMENT <- DEBUGGER / RETURN / EXPRESSION
PROGRAM <- _ STATEMENTS _
STATEMENTS <- (STATEMENT (_sp_ (';' / _nl_) (_ STATEMENT)?)*)?
STATEMENT <- DEBUGGER / RETURN / EXPRESSION
DEBUGGER <- debugger
RETURN <- return End _ / return EXPRESSION
DEBUGGER <- debugger
RETURN <- return (_sp_ !_nl_ EXPRESSION)?
EXPRESSION <- ASSIGNMENT / LOGICAL_OR
EXPRESSION <- ASSIGNMENT / LOGICAL_OR
ASSIGNMENT <- MUTABLE PRIMARY (ARGUMENTS / INDEX / DOT)* '=' _ EXPRESSION
ASSIGNMENT <- MUTABLE _ PRIMARY (_ (ARGUMENTS / INDEX / DOT))* _ '=' _ EXPRESSION
LOGICAL_OR <- LOGICAL_AND ('||' _ LOGICAL_AND)*
LOGICAL_AND <- CONDITION ('&&' _ CONDITION)*
CONDITION <- ADDITIVE (CONDITION_OPERATOR ADDITIVE)*
ADDITIVE <- UNARY_PLUS (ADDITIVE_OPERATOR UNARY_PLUS)*
UNARY_PLUS <- UNARY_PLUS_OPERATOR? UNARY_MINUS
UNARY_MINUS <- UNARY_MINUS_OPERATOR? UNARY_NOT
UNARY_NOT <- UNARY_NOT_OPERATOR? MULTIPLICATIVE
MULTIPLICATIVE <- CALL (MULTIPLICATIVE_OPERATOR CALL)*
LOGICAL_OR <- LOGICAL_AND (_ '||' _ LOGICAL_AND)*
LOGICAL_AND <- CONDITION (_ '&&' _ CONDITION)*
CONDITION <- ADDITIVE (_ CONDITION_OPERATOR _ ADDITIVE)*
ADDITIVE <- UNARY_PLUS (_ ADDITIVE_OPERATOR _ UNARY_PLUS)*
UNARY_PLUS <- UNARY_PLUS_OPERATOR? UNARY_MINUS
UNARY_MINUS <- UNARY_MINUS_OPERATOR? UNARY_NOT
UNARY_NOT <- UNARY_NOT_OPERATOR? MULTIPLICATIVE
MULTIPLICATIVE <- CALL (_ MULTIPLICATIVE_OPERATOR _ CALL)*
CALL <- PRIMARY (ARGUMENTS / INDEX / DOT)*
ARGUMENTS <- '(' _ (EXPRESSION (',' _ EXPRESSION)*)? ')' _
INDEX <- '[' _ EXPRESSION ']' _
DOT <- '.' _ IDENTIFIER
CALL <- PRIMARY (_ (ARGUMENTS / INDEX / DOT))*
ARGUMENTS <- '(' _ (EXPRESSION (_ ',' _ EXPRESSION)*)? _ ')'
INDEX <- '[' _ EXPRESSION _ ']'
DOT <- '.' _ IDENTIFIER
WHILE <- while EXPRESSION BLOCK
IF <- if EXPRESSION BLOCK (else if EXPRESSION BLOCK)* (else BLOCK)?
WHILE <- while _ EXPRESSION _ BLOCK
IF <- if _ EXPRESSION _ BLOCK (_ else _ if _ EXPRESSION _ BLOCK)* (_ else _ BLOCK)?
PRIMARY <- WHILE / IF / FUNCTION / OBJECT / ARRAY / UNDEFINED / BOOLEAN / NUMBER / IDENTIFIER / STRING / INTERPOLATED_STRING / '(' _ EXPRESSION ')' _
PRIMARY <- WHILE / IF / FUNCTION / OBJECT / ARRAY / UNDEFINED / BOOLEAN / NUMBER / IDENTIFIER / STRING / INTERPOLATED_STRING / '(' _ EXPRESSION _ ')'
FUNCTION <- fn PARAMETERS BLOCK
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
PARAMETER <- MUTABLE IDENTIFIER
FUNCTION <- fn _ PARAMETERS _ BLOCK
PARAMETERS <- '(' _ (PARAMETER (_ ',' _ PARAMETER)*)? _ ')'
PARAMETER <- MUTABLE _ IDENTIFIER
BLOCK <- '{' _ STATEMENTS '}' _
BLOCK <- '{' _ STATEMENTS _ '}'
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
ADDITIVE_OPERATOR <- < [-+] > _
UNARY_PLUS_OPERATOR <- < '+' > _
UNARY_MINUS_OPERATOR <- < '-' > _
UNARY_NOT_OPERATOR <- < '!' > _
MULTIPLICATIVE_OPERATOR <- < [*/%] > _
CONDITION_OPERATOR <- '==' / '!=' / '<=' / '<' / '>=' / '>'
ADDITIVE_OPERATOR <- [-+]
UNARY_PLUS_OPERATOR <- '+'
UNARY_MINUS_OPERATOR <- '-'
UNARY_NOT_OPERATOR <- '!'
MULTIPLICATIVE_OPERATOR <- [*/%]
IDENTIFIER <- < IdentInitChar IdentChar* > _
MUTABLE <- < ('mut' _wd_)? >
OBJECT <- '{' _ (OBJECT_PROPERTY (',' _ OBJECT_PROPERTY)*)? '}' _
OBJECT_PROPERTY <- MUTABLE IDENTIFIER ':' _ EXPRESSION
IDENTIFIER <- < IdentInitChar IdentChar* >
ARRAY <- '[' _ (EXPRESSION (',' _ EXPRESSION)*)? ']' _
OBJECT <- '{' _ (OBJECT_PROPERTY (_ ',' _ OBJECT_PROPERTY)*)? _ '}'
OBJECT_PROPERTY <- MUTABLE _ IDENTIFIER _ ':' _ EXPRESSION
UNDEFINED <- < 'undefined' > __
BOOLEAN <- < ('true' / 'false') > __
MUTABLE <- (< 'mut' > __)?
ARRAY <- '[' _ (EXPRESSION (',' _ EXPRESSION)*)? ']'
~debugger <- 'debugger' __
~return <- 'return' !IdentInitChar Space*
~while <- 'while' __
~if <- 'if' __
~else <- 'else' __
~fn <- 'fn' __
UNDEFINED <- < 'undefined' _wd_ >
BOOLEAN <- < ('true' / 'false') _wd_ >
NUMBER <- < [0-9]+ > _
STRING <- ['] < (!['] .)* > ['] _
NUMBER <- < [0-9]+ >
STRING <- ['] < (!['] .)* > [']
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION '}' / INTERPOLATED_CONTENT)* '"' _
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION _ '}' / INTERPOLATED_CONTENT)* '"'
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
~_ <- (Space / End)*
__ <- !IdentInitChar (Space / End)*
~Space <- ' ' / '\t' / Comment
~End <- EndOfLine / EndOfFile
Comment <- '/*' (!'*/' .)* '*/' / ('#' / '//') (!End .)* &End
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
IdentInitChar <- [a-zA-Z_]
IdentChar <- [a-zA-Z0-9_]
~debugger <- 'debugger' _wd_
~while <- 'while' _wd_
~if <- 'if' _wd_
~else <- 'else' _wd_
~fn <- 'fn' _wd_
~return <- 'return' _wd_
~_ <- (WhiteSpace / End)*
~_sp_ <- SpaceChar*
~_nl_ <- LineComment? End
~_wd_ <- !IdentInitChar
WhiteSpace <- SpaceChar / Comment
End <- EndOfLine / EndOfFile
Comment <- BlockComment / LineComment
SpaceChar <- ' ' / '\t'
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
IdentInitChar <- [a-zA-Z_]
IdentChar <- [a-zA-Z0-9_]
BlockComment <- '/*' (!'*/' .)* '*/'
LineComment <- ('#' / '//') (!End .)* &End