1 ////////////////////////////////////////////////////////////////////////////////
3 // Copyright 2015 - 2017, Paul Beckingham, Federico Hernandez.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // http://www.opensource.org/licenses/mit-license.php
25 ////////////////////////////////////////////////////////////////////////////////
42 Token (const std::string& value) { _token = value; }
43 void tag (const std::string& tag) { _tags.insert (tag); }
44 bool hasTag (const std::string& tag) const { return _tags.find (tag) != _tags.end (); };
45 std::string dump () const;
47 enum class Quantifier { one, zero_or_one, one_or_more, zero_or_more };
48 enum class Lookahead { none, positive, negative };
50 std::string _token {};
51 std::set <std::string> _tags {};
52 Quantifier _quantifier {Quantifier::one};
53 Lookahead _lookahead {Lookahead::none};
54 // TODO Added Lexer::Type support, which allows the PEG to specify
55 // "<Lexer::Type>" as a built-in type.
58 class Production : public std::vector <Token>
62 class Rule : public std::vector <Production>
67 void loadFromFile (File&);
68 void loadFromString (const std::string&);
69 std::map <std::string, PEG::Rule> syntax () const;
70 std::string firstRule () const;
73 std::string dump () const;
76 std::vector <std::string> loadImports (const std::vector <std::string>&);
77 void validate () const;
82 std::map <std::string, PEG::Rule> _rules {};
83 std::string _start {};
86 std::vector <std::string> _imports {};