diff options
Diffstat (limited to 'src/MoonP/moon_parser.cpp')
-rw-r--r-- | src/MoonP/moon_parser.cpp | 21 |
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 | ||
34 | rule plain_space = *set(" \t"); | 34 | rule plain_space = *set(" \t"); |
@@ -160,9 +160,16 @@ rule colon_import_name = sym('\\') >> Space >> Variable; | |||
160 | rule ImportName = colon_import_name | Space >> Variable; | 160 | rule ImportName = colon_import_name | Space >> Variable; |
161 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); | 161 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); |
162 | 162 | ||
163 | extern rule Exp; | 163 | extern rule Exp, TableLit; |
164 | 164 | ||
165 | rule Import = key("import") >> ImportNameList >> *SpaceBreak >> key("from") >> Exp; | 165 | rule import_literal_inner = (range('a', 'z') | range('A', 'Z') | set("_-")) >> *(AlphaNum | '-'); |
166 | rule import_literal_chain = Seperator >> import_literal_inner >> *(expr('.') >> import_literal_inner); | ||
167 | rule ImportLiteral = sym('\'') >> import_literal_chain >> symx('\'') | sym('"') >> import_literal_chain >> symx('"'); | ||
168 | |||
169 | rule ImportFrom = ImportNameList >> *SpaceBreak >> key("from") >> Exp; | ||
170 | rule ImportAs = ImportLiteral >> -(key("as") >> (Space >> Variable | TableLit)); | ||
171 | |||
172 | rule Import = key("import") >> (ImportAs | ImportFrom); | ||
166 | rule BreakLoop = (expr("break") | expr("continue")) >> not_(AlphaNum); | 173 | rule BreakLoop = (expr("break") | expr("continue")) >> not_(AlphaNum); |
167 | 174 | ||
168 | extern rule ExpListLow, ExpList, Assign; | 175 | extern rule ExpListLow, ExpList, Assign; |
@@ -301,12 +308,12 @@ rule Value = SimpleValue | simple_table | ChainValue | String; | |||
301 | extern rule LuaString; | 308 | extern rule LuaString; |
302 | 309 | ||
303 | rule single_string_inner = expr("\\'") | "\\\\" | not_(expr('\'')) >> Any; | 310 | rule single_string_inner = expr("\\'") | "\\\\" | not_(expr('\'')) >> Any; |
304 | rule SingleString = symx('\'') >> *single_string_inner >> sym('\''); | 311 | rule SingleString = symx('\'') >> *single_string_inner >> symx('\''); |
305 | rule interp = symx("#{") >> Exp >> sym('}'); | 312 | rule interp = symx("#{") >> Exp >> sym('}'); |
306 | rule double_string_plain = expr("\\\"") | "\\\\" | not_(expr('"')) >> Any; | 313 | rule double_string_plain = expr("\\\"") | "\\\\" | not_(expr('"')) >> Any; |
307 | rule double_string_inner = +(not_(interp) >> double_string_plain); | 314 | rule double_string_inner = +(not_(interp) >> double_string_plain); |
308 | rule double_string_content = double_string_inner | interp; | 315 | rule double_string_content = double_string_inner | interp; |
309 | rule DoubleString = symx('"') >> Seperator >> *double_string_content >> sym('"'); | 316 | rule DoubleString = symx('"') >> Seperator >> *double_string_content >> symx('"'); |
310 | rule String = Space >> (DoubleString | SingleString | LuaString); | 317 | rule String = Space >> (DoubleString | SingleString | LuaString); |
311 | 318 | ||
312 | rule lua_string_open = '[' >> *expr('=') >> '['; | 319 | rule lua_string_open = '[' >> *expr('=') >> '['; |