mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Added grammar for Culebra language.
This commit is contained in:
parent
36e58a6c7b
commit
6d8826741a
51
grammar/culebra.peg
Normal file
51
grammar/culebra.peg
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user