mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2025-01-22 21:35:29 +00:00
Code cleanup.
This commit is contained in:
parent
456ce928ea
commit
3eded9ea36
@ -4,43 +4,43 @@ using namespace peglib;
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static auto g_grammar = R"(
|
static auto g_grammar = R"(
|
||||||
PROGRAM <- _ STATEMENTS
|
PROGRAM <- _ STATEMENTS
|
||||||
|
|
||||||
STATEMENTS <- EXPRESSION*
|
STATEMENTS <- EXPRESSION*
|
||||||
|
|
||||||
EXPRESSION <- ASSIGNMENT / PRIMARY
|
EXPRESSION <- ASSIGNMENT / PRIMARY
|
||||||
ASSIGNMENT <- IDENTIFIER '=' _ EXPRESSION
|
ASSIGNMENT <- IDENTIFIER '=' _ EXPRESSION
|
||||||
WHILE <- 'while' _ EXPRESSION BLOCK
|
WHILE <- 'while' _ EXPRESSION BLOCK
|
||||||
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
|
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
|
||||||
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
||||||
PARAMETERS <- '(' _ IDENTIFIER* ')' _
|
PARAMETERS <- '(' _ IDENTIFIER* ')' _
|
||||||
FUNCTION_CALL <- IDENTIFIER ARGUMENTS
|
FUNCTION_CALL <- IDENTIFIER ARGUMENTS
|
||||||
ARGUMENTS <- '(' _ EXPRESSION* ')' _
|
ARGUMENTS <- '(' _ EXPRESSION* ')' _
|
||||||
|
|
||||||
PRIMARY <- CONDITION (CONDITION_OPERATOR CONDITION)?
|
PRIMARY <- CONDITION (CONDITION_OPERATOR CONDITION)?
|
||||||
CONDITION <- TERM (TERM_OPERATOR TERM)*
|
CONDITION <- TERM (TERM_OPERATOR TERM)*
|
||||||
TERM <- FACTOR (FACTOR_OPERATOR FACTOR)*
|
TERM <- FACTOR (FACTOR_OPERATOR FACTOR)*
|
||||||
FACTOR <- WHILE / IF / FUNCTION / FUNCTION_CALL / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / IDENTIFIER / '(' _ EXPRESSION ')' _
|
FACTOR <- WHILE / IF / FUNCTION / FUNCTION_CALL / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / IDENTIFIER / '(' _ EXPRESSION ')' _
|
||||||
|
|
||||||
BLOCK <- '{' _ STATEMENTS '}' _
|
BLOCK <- '{' _ STATEMENTS '}' _
|
||||||
|
|
||||||
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
||||||
TERM_OPERATOR <- < [-+] > _
|
TERM_OPERATOR <- < [-+] > _
|
||||||
FACTOR_OPERATOR <- < [*/%] > _
|
FACTOR_OPERATOR <- < [*/%] > _
|
||||||
IDENTIFIER <- < [a-zA-Z_]+ > _
|
IDENTIFIER <- < [a-zA-Z_]+ > _
|
||||||
|
|
||||||
NUMBER <- < [0-9]+ > _
|
NUMBER <- < [0-9]+ > _
|
||||||
BOOLEAN <- < ('true' / 'false') > _
|
BOOLEAN <- < ('true' / 'false') > _
|
||||||
STRING <- ['] < (!['] .)* > ['] _
|
STRING <- ['] < (!['] .)* > ['] _
|
||||||
|
|
||||||
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION '}' / INTERPOLATED_CONTENT)* '"' _
|
INTERPOLATED_STRING <- '"' ('{' _ EXPRESSION '}' / INTERPOLATED_CONTENT)* '"' _
|
||||||
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
|
INTERPOLATED_CONTENT <- (!["{] .) (!["{] .)*
|
||||||
|
|
||||||
~_ <- (Space / EndOfLine / Comment)*
|
~_ <- (Space / EndOfLine / Comment)*
|
||||||
Space <- ' ' / '\t'
|
Space <- ' ' / '\t'
|
||||||
EndOfLine <- '\r\n' / '\n' / '\r'
|
EndOfLine <- '\r\n' / '\n' / '\r'
|
||||||
EndOfFile <- !.
|
EndOfFile <- !.
|
||||||
Comment <- '/*' (!'*/' .)* '*/' / ('#' / '//') (!(EndOfLine / EndOfFile) .)* (EndOfLine / EndOfFile)
|
Comment <- '/*' (!'*/' .)* '*/' / ('#' / '//') (!(EndOfLine / EndOfFile) .)* (EndOfLine / EndOfFile)
|
||||||
)";
|
)";
|
||||||
|
|
||||||
peglib::peg& get_parser()
|
peglib::peg& get_parser()
|
||||||
|
Loading…
Reference in New Issue
Block a user