cpp-peglib/grammar/culebra.peg

62 lines
2.8 KiB
Plaintext
Raw Normal View History

2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
PROGRAM <- _ STATEMENTS
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
STATEMENTS <- (EXPRESSION (';' _)?)*
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
EXPRESSION <- ASSIGNMENT / LOGICAL_OR
ASSIGNMENT <- MUTABLE IDENTIFIER '=' _ EXPRESSION
WHILE <- 'while' _ EXPRESSION BLOCK
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
2015-07-08 14:30:11 +00:00
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)*
2015-07-23 01:14:55 +00:00
CALL <- PRIMARY (ARGUMENTS / INDEX / DOT)*
2015-07-08 14:30:11 +00:00
ARGUMENTS <- '(' _ (EXPRESSION (',' _ EXPRESSION)*)? ')' _
INDEX <- '[' _ EXPRESSION ']' _
2015-07-23 01:14:55 +00:00
DOT <- '.' _ IDENTIFIER
2015-07-23 01:14:55 +00:00
PRIMARY <- WHILE / IF / FUNCTION / IDENTIFIER / OBJECT / ARRAY / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / '(' _ EXPRESSION ')' _
2015-07-08 14:30:11 +00:00
FUNCTION <- 'fn' _ PARAMETERS BLOCK
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
PARAMETER <- MUTABLE IDENTIFIER
2015-06-26 00:06:00 +00:00
2015-07-08 14:30:11 +00:00
BLOCK <- '{' _ STATEMENTS '}' _
2015-06-26 00:06:00 +00:00
2015-07-08 14:30:11 +00:00
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
ADDITIVE_OPERATOR <- < [-+] > _
UNARY_PLUS_OPERATOR <- < '+' > _
UNARY_MINUS_OPERATOR <- < '-' > _
UNARY_NOT_OPERATOR <- < '!' > _
MULTIPLICATIVE_OPERATOR <- < [*/%] > _
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
IDENTIFIER <- < [a-zA-Z_][a-zA-Z0-9_]* > _
2015-06-13 05:32:23 +00:00
2015-07-23 01:14:55 +00:00
OBJECT <- '{' _ (OBJECT_PROPERTY (',' _ OBJECT_PROPERTY)*)? '}' _
OBJECT_PROPERTY <- IDENTIFIER ':' _ EXPRESSION
2015-07-21 10:45:24 +00:00
ARRAY <- '[' _ (EXPRESSION (',' _ EXPRESSION)*)? ']' _
2015-07-23 01:14:55 +00:00
2015-07-08 14:30:11 +00:00
NUMBER <- < [0-9]+ > _
BOOLEAN <- < ('true' / 'false') > _
STRING <- ['] < (!['] .)* > ['] _
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION '}' / INTERPOLATED_CONTENT)* '"' _
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
MUTABLE <- < 'mut'? > _
2015-06-13 05:32:23 +00:00
2015-07-08 14:30:11 +00:00
~_ <- (Space / EndOfLine / Comment)*
Space <- ' ' / '\t'
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
Comment <- '/*' (!'*/' .)* '*/' / ('#' / '//') (!(EndOfLine / EndOfFile) .)* (EndOfLine / EndOfFile)
2015-06-13 05:32:23 +00:00