From fa375615cda0b0a4723e6f555ea5b675bb929d38 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 22 Dec 2015 15:28:00 -0500 Subject: [PATCH] Grammar: Added regex support --- src/Grammar.cpp | 8 +++++--- src/grammar.cfg | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Grammar.cpp b/src/Grammar.cpp index f6a0d192..49fcd410 100644 --- a/src/Grammar.cpp +++ b/src/Grammar.cpp @@ -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 diff --git a/src/grammar.cfg b/src/grammar.cfg index d1ce0c44..e55b758c 100644 --- a/src/grammar.cfg +++ b/src/grammar.cfg @@ -18,18 +18,18 @@ # A -> B 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