mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2025-04-04 18:02:07 +00:00
Fixed keyword boundary problem.
This commit is contained in:
parent
6b690dd3cb
commit
ef476b87cf
@ -20,21 +20,21 @@ auto grammar = R"(
|
|||||||
program <- _ block '.' _
|
program <- _ block '.' _
|
||||||
|
|
||||||
block <- const var procedure statement
|
block <- const var procedure statement
|
||||||
const <- ('CONST' _ ident '=' _ number (',' _ ident '=' _ number)* ';' _)?
|
const <- ('CONST' __ ident '=' _ number (',' _ ident '=' _ number)* ';' _)?
|
||||||
var <- ('VAR' _ ident (',' _ ident)* ';' _)?
|
var <- ('VAR' __ ident (',' _ ident)* ';' _)?
|
||||||
procedure <- ('PROCEDURE' _ ident ';' _ block ';' _)*
|
procedure <- ('PROCEDURE' __ ident ';' _ block ';' _)*
|
||||||
|
|
||||||
statement <- (assignment / call / statements / if / while / out / in)?
|
statement <- (assignment / call / statements / if / while / out / in)?
|
||||||
assignment <- ident ':=' _ expression
|
assignment <- ident ':=' _ expression
|
||||||
call <- 'CALL' _ ident
|
call <- 'CALL' __ ident
|
||||||
statements <- 'BEGIN' _ statement (';' _ statement )* 'END' _
|
statements <- 'BEGIN' __ statement (';' _ statement )* 'END' __
|
||||||
if <- 'IF' _ condition 'THEN' _ statement
|
if <- 'IF' __ condition 'THEN' __ statement
|
||||||
while <- 'WHILE' _ condition 'DO' _ statement
|
while <- 'WHILE' __ condition 'DO' __ statement
|
||||||
out <- ('out' / 'write' / '!') _ expression
|
out <- ('out' __ / 'write' __ / '!' _) expression
|
||||||
in <- ('in' / 'read' / '?') _ ident
|
in <- ('in' __ / 'read' __ / '?' _) ident
|
||||||
|
|
||||||
condition <- odd / compare
|
condition <- odd / compare
|
||||||
odd <- 'ODD' _ expression
|
odd <- 'ODD' __ expression
|
||||||
compare <- expression compare_op expression
|
compare <- expression compare_op expression
|
||||||
compare_op <- < '=' / '#' / '<=' / '<' / '>=' / '>' > _
|
compare_op <- < '=' / '#' / '<=' / '<' / '>=' / '>' > _
|
||||||
|
|
||||||
@ -47,10 +47,11 @@ auto grammar = R"(
|
|||||||
|
|
||||||
factor <- ident / number / '(' _ expression ')' _
|
factor <- ident / number / '(' _ expression ')' _
|
||||||
|
|
||||||
ident <- < [a-z] ([a-z] / [0-9])* > _
|
ident <- < [a-z] [a-z0-9]* > _
|
||||||
number <- < [0-9]+ > _
|
number <- < [0-9]+ > _
|
||||||
|
|
||||||
~_ <- [ \t\r\n]*
|
~_ <- [ \t\r\n]*
|
||||||
|
~__ <- ![a-z0-9_] _
|
||||||
)";
|
)";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user