Grammar: Added regex support

This commit is contained in:
Paul Beckingham 2015-12-22 15:28:00 -05:00
parent ee667cb68c
commit fa375615cd
2 changed files with 13 additions and 11 deletions

View file

@ -156,7 +156,7 @@ std::string Grammar::dump () const
{
out << term._token;
if (term._decoration != "")
out << term._decoration;
out << " " << term._decoration;
out << " ";
}
@ -187,7 +187,8 @@ void Grammar::validate () const
{
for (auto& token : production)
{
if (token._token.front () != '"')
if (token._token.front () != '"' and
token._token.front () != '/')
allTokens.push_back (token._token);
if (token._token == production[0]._token &&
@ -213,7 +214,8 @@ void Grammar::validate () const
throw format ("Definition '{1}' is left recursive.", lr);
for (auto& r : allRules)
if (r[0] == '"')
if (r[0] == '"' or
r[0] == '/')
throw format ("Definition '{1}' must not be a literal.");
// Unused definitions - these are names in _rules that are never

View file

@ -18,18 +18,18 @@
# A -> B <op> A
# B
cli: "start":ai
"stop":ai
"track":ai
cli: "start" :ai
"stop" :ai
"track" :ai
help # Non-terminal, cannot contain є.
є
help: "help":ai topic
"help":ai
help: "help" :ai topic
"help" :ai
topic: "usage":ai
"dates":ai
"times":ai
topic: "usage" :ai
/dates?/ :ai
/times?/ :ai