mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-23 04:15:31 +00:00
52 lines
2.3 KiB
Plaintext
52 lines
2.3 KiB
Plaintext
|
|
PROGRAM <- _ STATEMENTS
|
|
|
|
STATEMENTS <- (EXPRESSION (';' _)?)*
|
|
|
|
EXPRESSION <- ASSIGNMENT / PRIMARY
|
|
ASSIGNMENT <- MUTABLE IDENTIFIER '=' _ EXPRESSION
|
|
WHILE <- 'while' _ EXPRESSION BLOCK
|
|
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
|
|
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
|
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
|
|
PARAMETER <- MUTABLE IDENTIFIER
|
|
FUNCTION_CALL <- IDENTIFIER ARGUMENTS
|
|
ARGUMENTS <- '(' _ (EXPRESSION (', ' _ EXPRESSION)*)? ')' _
|
|
|
|
PRIMARY <- LOGICAL_OR ('||' _ LOGICAL_OR)*
|
|
LOGICAL_OR <- LOGICAL_AND ('&&' _ LOGICAL_AND)*
|
|
LOGICAL_AND <- CONDITION (CONDITION_OPERATOR CONDITION)*
|
|
CONDITION <- TERM (TERM_OPERATOR TERM)*
|
|
TERM <- UNARY_PLUS_OPERATOR? UNARY_PLUS
|
|
UNARY_PLUS <- UNARY_MINUS_OPERATOR? UNARY_MINUS
|
|
UNARY_MINUS <- UNARY_NOT_OPERATOR? UNARY_NOT
|
|
UNARY_NOT <- FACTOR (FACTOR_OPERATOR FACTOR)*
|
|
FACTOR <- WHILE / IF / FUNCTION / FUNCTION_CALL / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / IDENTIFIER / '(' _ EXPRESSION ')' _
|
|
|
|
BLOCK <- '{' _ STATEMENTS '}' _
|
|
|
|
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
|
TERM_OPERATOR <- < [-+] > _
|
|
UNARY_PLUS_OPERATOR <- < '+' > _
|
|
UNARY_MINUS_OPERATOR <- < '-' > _
|
|
UNARY_NOT_OPERATOR <- < '!' > _
|
|
FACTOR_OPERATOR <- < [*/%] > _
|
|
|
|
IDENTIFIER <- < [a-zA-Z_][a-zA-Z0-9_]* > _
|
|
|
|
NUMBER <- < [0-9]+ > _
|
|
BOOLEAN <- < ('true' / 'false') > _
|
|
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)
|
|
|