aboutsummaryrefslogtreecommitdiff
path: root/src/MoonP/moon_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MoonP/moon_parser.cpp')
-rw-r--r--src/MoonP/moon_parser.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp
index 7cc4129..d3c0ed2 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -26,9 +26,9 @@ std::unordered_set<std::string> State::keywords = {
26 "in", "local", "nil", "not", "or", 26 "in", "local", "nil", "not", "or",
27 "repeat", "return", "then", "true", "until", 27 "repeat", "return", "then", "true", "until",
28 "while", // Lua keywords 28 "while", // Lua keywords
29 "class", "continue", "export", "extends", "from", 29 "as", "class", "continue", "export", "extends",
30 "import", "switch", "unless", "using", "when", 30 "from", "import", "switch", "unless", "using",
31 "with" // Moon keywords 31 "when", "with" // Moon keywords
32}; 32};
33 33
34rule plain_space = *set(" \t"); 34rule plain_space = *set(" \t");
@@ -160,9 +160,16 @@ rule colon_import_name = sym('\\') >> Space >> Variable;
160rule ImportName = colon_import_name | Space >> Variable; 160rule ImportName = colon_import_name | Space >> Variable;
161rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); 161rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName);
162 162
163extern rule Exp; 163extern rule Exp, TableLit;
164 164
165rule Import = key("import") >> ImportNameList >> *SpaceBreak >> key("from") >> Exp; 165rule import_literal_inner = (range('a', 'z') | range('A', 'Z') | set("_-")) >> *(AlphaNum | '-');
166rule import_literal_chain = Seperator >> import_literal_inner >> *(expr('.') >> import_literal_inner);
167rule ImportLiteral = sym('\'') >> import_literal_chain >> symx('\'') | sym('"') >> import_literal_chain >> symx('"');
168
169rule ImportFrom = ImportNameList >> *SpaceBreak >> key("from") >> Exp;
170rule ImportAs = ImportLiteral >> -(key("as") >> (Space >> Variable | TableLit));
171
172rule Import = key("import") >> (ImportAs | ImportFrom);
166rule BreakLoop = (expr("break") | expr("continue")) >> not_(AlphaNum); 173rule BreakLoop = (expr("break") | expr("continue")) >> not_(AlphaNum);
167 174
168extern rule ExpListLow, ExpList, Assign; 175extern rule ExpListLow, ExpList, Assign;
@@ -301,12 +308,12 @@ rule Value = SimpleValue | simple_table | ChainValue | String;
301extern rule LuaString; 308extern rule LuaString;
302 309
303rule single_string_inner = expr("\\'") | "\\\\" | not_(expr('\'')) >> Any; 310rule single_string_inner = expr("\\'") | "\\\\" | not_(expr('\'')) >> Any;
304rule SingleString = symx('\'') >> *single_string_inner >> sym('\''); 311rule SingleString = symx('\'') >> *single_string_inner >> symx('\'');
305rule interp = symx("#{") >> Exp >> sym('}'); 312rule interp = symx("#{") >> Exp >> sym('}');
306rule double_string_plain = expr("\\\"") | "\\\\" | not_(expr('"')) >> Any; 313rule double_string_plain = expr("\\\"") | "\\\\" | not_(expr('"')) >> Any;
307rule double_string_inner = +(not_(interp) >> double_string_plain); 314rule double_string_inner = +(not_(interp) >> double_string_plain);
308rule double_string_content = double_string_inner | interp; 315rule double_string_content = double_string_inner | interp;
309rule DoubleString = symx('"') >> Seperator >> *double_string_content >> sym('"'); 316rule DoubleString = symx('"') >> Seperator >> *double_string_content >> symx('"');
310rule String = Space >> (DoubleString | SingleString | LuaString); 317rule String = Space >> (DoubleString | SingleString | LuaString);
311 318
312rule lua_string_open = '[' >> *expr('=') >> '['; 319rule lua_string_open = '[' >> *expr('=') >> '[';