diff options
Diffstat (limited to '')
| -rw-r--r-- | MoonParser/moon_parser.cpp | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/MoonParser/moon_parser.cpp b/MoonParser/moon_parser.cpp index 481c885..ad86020 100644 --- a/MoonParser/moon_parser.cpp +++ b/MoonParser/moon_parser.cpp | |||
| @@ -1,11 +1,21 @@ | |||
| 1 | #include "moon_parser.h" | 1 | #include "moon_parser.h" |
| 2 | 2 | ||
| 3 | std::unordered_set<std::string> State::luaKeywords = { | ||
| 4 | "and", "break", "do", "else", "elseif", | ||
| 5 | "end", "false", "for", "function", "if", | ||
| 6 | "in", "local", "nil", "not", "or", | ||
| 7 | "repeat", "return", "then", "true", "until", | ||
| 8 | "while" | ||
| 9 | }; | ||
| 10 | |||
| 3 | std::unordered_set<std::string> State::keywords = { | 11 | std::unordered_set<std::string> State::keywords = { |
| 4 | "and", "while", "else", "using", "continue", | 12 | "and", "break", "do", "else", "elseif", |
| 5 | "local", "not", "then", "return", "from", | 13 | "end", "false", "for", "function", "if", |
| 6 | "extends", "for", "do", "or", "export", | 14 | "in", "local", "nil", "not", "or", |
| 7 | "class", "in", "unless", "when", "elseif", | 15 | "repeat", "return", "then", "true", "until", |
| 8 | "switch", "break", "if", "with", "import", "true", "false", "nil" | 16 | "while", // Lua keywords |
| 17 | "class", "continue", "export", "extends", | ||
| 18 | "import", "switch", "unless", "using", "with" // Moon keywords | ||
| 9 | }; | 19 | }; |
| 10 | 20 | ||
| 11 | rule plain_space = *set(" \t"); | 21 | rule plain_space = *set(" \t"); |
| @@ -44,12 +54,9 @@ rule Seperator = true_(); | |||
| 44 | 54 | ||
| 45 | rule Variable = user(Name, [](const item_t& item) { | 55 | rule Variable = user(Name, [](const item_t& item) { |
| 46 | State* st = reinterpret_cast<State*>(item.user_data); | 56 | State* st = reinterpret_cast<State*>(item.user_data); |
| 47 | for (auto it = item.begin; it != item.end; ++it) st->buffer << static_cast<char>(*it); | 57 | for (auto it = item.begin; it != item.end; ++it) st->buffer += static_cast<char>(*it); |
| 48 | std::string name; | 58 | auto it = st->keywords.find(st->buffer); |
| 49 | st->buffer >> name; | ||
| 50 | st->buffer.str(""); | ||
| 51 | st->buffer.clear(); | 59 | st->buffer.clear(); |
| 52 | auto it = st->keywords.find(name); | ||
| 53 | return it == st->keywords.end(); | 60 | return it == st->keywords.end(); |
| 54 | }); | 61 | }); |
| 55 | 62 | ||
| @@ -252,18 +259,18 @@ rule BinaryOperator = | |||
| 252 | expr("//") | | 259 | expr("//") | |
| 253 | set("+-*/%^><|&"); | 260 | set("+-*/%^><|&"); |
| 254 | 261 | ||
| 255 | extern rule Chain; | 262 | extern rule AssignableChain; |
| 256 | 263 | ||
| 257 | rule Assignable = Chain | Space >> Variable | SelfName; | 264 | rule Assignable = AssignableChain | Space >> Variable | SelfName; |
| 258 | 265 | ||
| 259 | extern rule Value; | 266 | extern rule Value; |
| 260 | 267 | ||
| 261 | rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; | 268 | rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; |
| 262 | rule Exp = Value >> *exp_op_value; | 269 | rule Exp = Value >> *exp_op_value; |
| 263 | 270 | ||
| 264 | extern rule Callable, InvokeArgs; | 271 | extern rule Chain, Callable, InvokeArgs; |
| 265 | 272 | ||
| 266 | rule ChainValue = (Chain | Callable) >> -InvokeArgs; | 273 | rule ChainValue = Seperator >> (Chain | Callable) >> -InvokeArgs; |
| 267 | 274 | ||
| 268 | extern rule KeyValue, String, SimpleValue; | 275 | extern rule KeyValue, String, SimpleValue; |
| 269 | 276 | ||
| @@ -321,10 +328,10 @@ rule chain_call = (Callable | String) >> ChainItems; | |||
| 321 | rule chain_item = and_(set(".\\")) >> ChainItems; | 328 | rule chain_item = and_(set(".\\")) >> ChainItems; |
| 322 | rule chain_dot_chain = DotChainItem >> -ChainItems; | 329 | rule chain_dot_chain = DotChainItem >> -ChainItems; |
| 323 | 330 | ||
| 324 | rule Chain = Seperator >> ( | 331 | rule Chain = chain_call | chain_item | |
| 325 | chain_call | | 332 | Space >> (chain_dot_chain | ColonChain); |
| 326 | chain_item | | 333 | |
| 327 | Space >> (chain_dot_chain | ColonChain)); | 334 | rule AssignableChain = Seperator >> Chain; |
| 328 | 335 | ||
| 329 | extern rule ChainItem; | 336 | extern rule ChainItem; |
| 330 | 337 | ||
| @@ -491,4 +498,6 @@ rule Body = -Space >> Break >> *EmptyLine >> InBlock | Statement; | |||
| 491 | rule empty_line_stop = Space >> and_(Stop); | 498 | rule empty_line_stop = Space >> and_(Stop); |
| 492 | rule Line = CheckIndent >> Statement | empty_line_stop; | 499 | rule Line = CheckIndent >> Statement | empty_line_stop; |
| 493 | rule Block = Seperator >> Line >> *(+Break >> Line); | 500 | rule Block = Seperator >> Line >> *(+Break >> Line); |
| 494 | rule BlockEnd = Block >> eof(); | 501 | |
| 502 | rule Shebang = expr("#!") >> *(not_(Stop) >> Any); | ||
| 503 | rule File = White >> -Shebang >> Block >> eof(); | ||
