mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-23 04:15:31 +00:00
63 lines
2.9 KiB
Plaintext
63 lines
2.9 KiB
Plaintext
|
|
PROGRAM <- _ STATEMENTS
|
|
STATEMENTS <- (EXPRESSION (';' _)?)*
|
|
EXPRESSION <- ASSIGNMENT / LOGICAL_OR
|
|
|
|
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)*
|
|
|
|
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)?
|
|
|
|
PRIMARY <- WHILE / IF / FUNCTION / OBJECT / ARRAY / UNDEFINED / BOOLEAN / NUMBER / IDENTIFIER / STRING / INTERPOLATED_STRING / '(' _ EXPRESSION ')' _
|
|
|
|
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
|
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
|
|
PARAMETER <- MUTABLE IDENTIFIER
|
|
|
|
BLOCK <- '{' _ STATEMENTS '}' _
|
|
|
|
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
|
ADDITIVE_OPERATOR <- < [-+] > _
|
|
UNARY_PLUS_OPERATOR <- < '+' > _
|
|
UNARY_MINUS_OPERATOR <- < '-' > _
|
|
UNARY_NOT_OPERATOR <- < '!' > _
|
|
MULTIPLICATIVE_OPERATOR <- < [*/%] > _
|
|
|
|
IDENTIFIER <- < [a-zA-Z_][a-zA-Z0-9_]* > _
|
|
|
|
OBJECT <- '{' _ (OBJECT_PROPERTY (',' _ OBJECT_PROPERTY)*)? '}' _
|
|
OBJECT_PROPERTY <- MUTABLE IDENTIFIER ':' _ EXPRESSION
|
|
|
|
ARRAY <- '[' _ (EXPRESSION (',' _ EXPRESSION)*)? ']' _
|
|
|
|
UNDEFINED <- < 'undefined' > _
|
|
BOOLEAN <- < ('true' / 'false') > _
|
|
NUMBER <- < [0-9]+ > _
|
|
STRING <- ['] < (!['] .)* > ['] _
|
|
|
|
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION '}' / INTERPOLATED_CONTENT)* '"' _
|
|
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
|
|
|
|
MUTABLE <- < 'mut'? > _
|
|
|
|
~_ <- (Space / EndOfLine / Comment)*
|
|
Space <- ' ' / '\t'
|
|
EndOfLine <- '\r\n' / '\n' / '\r'
|
|
EndOfFile <- !.
|
|
Comment <- '/*' (!'*/' .)* '*/' / ('#' / '//') (!(EndOfLine / EndOfFile) .)* (EndOfLine / EndOfFile)
|
|
|