aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/moon_parser.cpp
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2019-10-06 17:30:11 +0800
committerLi Jin <dragon-fly@qq.com>2019-10-06 17:30:11 +0800
commit055fcb596781a8488afeb0030e9ef4295e3d7017 (patch)
tree0512d6d9660e563be37af5b6ac1bb888a9023e6a /MoonParser/moon_parser.cpp
parent2de63a85a87c9a64032602fdd3736f69e73efbc5 (diff)
downloadyuescript-055fcb596781a8488afeb0030e9ef4295e3d7017.tar.gz
yuescript-055fcb596781a8488afeb0030e9ef4295e3d7017.tar.bz2
yuescript-055fcb596781a8488afeb0030e9ef4295e3d7017.zip
updating
Diffstat (limited to 'MoonParser/moon_parser.cpp')
-rw-r--r--MoonParser/moon_parser.cpp47
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
3std::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
3std::unordered_set<std::string> State::keywords = { 11std::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
11rule plain_space = *set(" \t"); 21rule plain_space = *set(" \t");
@@ -44,12 +54,9 @@ rule Seperator = true_();
44 54
45rule Variable = user(Name, [](const item_t& item) { 55rule 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
255extern rule Chain; 262extern rule AssignableChain;
256 263
257rule Assignable = Chain | Space >> Variable | SelfName; 264rule Assignable = AssignableChain | Space >> Variable | SelfName;
258 265
259extern rule Value; 266extern rule Value;
260 267
261rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; 268rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value;
262rule Exp = Value >> *exp_op_value; 269rule Exp = Value >> *exp_op_value;
263 270
264extern rule Callable, InvokeArgs; 271extern rule Chain, Callable, InvokeArgs;
265 272
266rule ChainValue = (Chain | Callable) >> -InvokeArgs; 273rule ChainValue = Seperator >> (Chain | Callable) >> -InvokeArgs;
267 274
268extern rule KeyValue, String, SimpleValue; 275extern rule KeyValue, String, SimpleValue;
269 276
@@ -321,10 +328,10 @@ rule chain_call = (Callable | String) >> ChainItems;
321rule chain_item = and_(set(".\\")) >> ChainItems; 328rule chain_item = and_(set(".\\")) >> ChainItems;
322rule chain_dot_chain = DotChainItem >> -ChainItems; 329rule chain_dot_chain = DotChainItem >> -ChainItems;
323 330
324rule Chain = Seperator >> ( 331rule Chain = chain_call | chain_item |
325 chain_call | 332 Space >> (chain_dot_chain | ColonChain);
326 chain_item | 333
327 Space >> (chain_dot_chain | ColonChain)); 334rule AssignableChain = Seperator >> Chain;
328 335
329extern rule ChainItem; 336extern rule ChainItem;
330 337
@@ -491,4 +498,6 @@ rule Body = -Space >> Break >> *EmptyLine >> InBlock | Statement;
491rule empty_line_stop = Space >> and_(Stop); 498rule empty_line_stop = Space >> and_(Stop);
492rule Line = CheckIndent >> Statement | empty_line_stop; 499rule Line = CheckIndent >> Statement | empty_line_stop;
493rule Block = Seperator >> Line >> *(+Break >> Line); 500rule Block = Seperator >> Line >> *(+Break >> Line);
494rule BlockEnd = Block >> eof(); 501
502rule Shebang = expr("#!") >> *(not_(Stop) >> Any);
503rule File = White >> -Shebang >> Block >> eof();