diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-28 00:41:53 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-28 01:10:31 +0800 |
commit | fb47c11bd942c83317f1f9a2e255535649401cbf (patch) | |
tree | 3fb35b9b23911a37c4e4499cf650792ba2b8b21c /src/MoonP/moon_parser.cpp | |
parent | 27717564cb1ab72c88c10a8392b6795ddea7a0ef (diff) | |
download | yuescript-fb47c11bd942c83317f1f9a2e255535649401cbf.tar.gz yuescript-fb47c11bd942c83317f1f9a2e255535649401cbf.tar.bz2 yuescript-fb47c11bd942c83317f1f9a2e255535649401cbf.zip |
Add multi-line comment support. Add escape new line symbol. Add back call syntax.
Diffstat (limited to 'src/MoonP/moon_parser.cpp')
-rw-r--r-- | src/MoonP/moon_parser.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 6d1b86c..baea9bf 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -37,8 +37,13 @@ rule Any = Break | any(); | |||
37 | rule White = *(set(" \t") | Break); | 37 | rule White = *(set(" \t") | Break); |
38 | rule Stop = Break | eof(); | 38 | rule Stop = Break | eof(); |
39 | rule Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); | 39 | rule Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); |
40 | rule Indent = *set(" \t"); | 40 | rule multi_line_open = expr("--[["); |
41 | rule Space = plain_space >> -Comment; | 41 | rule multi_line_close = expr("]]"); |
42 | rule multi_line_content = *(not_(multi_line_close) >> Any); | ||
43 | rule MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; | ||
44 | rule Indent = plain_space; | ||
45 | rule EscapeNewLine = expr('\\') >> plain_space >> -Comment >> Break; | ||
46 | rule Space = *(set(" \t") | MultiLineComment | EscapeNewLine) >> -Comment; | ||
42 | rule SomeSpace = +set(" \t") >> -Comment; | 47 | rule SomeSpace = +set(" \t") >> -Comment; |
43 | rule SpaceBreak = Space >> Break; | 48 | rule SpaceBreak = Space >> Break; |
44 | rule EmptyLine = SpaceBreak; | 49 | rule EmptyLine = SpaceBreak; |
@@ -287,13 +292,15 @@ rule BinaryOperator = | |||
287 | expr("//") | | 292 | expr("//") | |
288 | set("+-*/%^><|&"); | 293 | set("+-*/%^><|&"); |
289 | 294 | ||
295 | rule BackcallOperator = expr("|>"); | ||
296 | |||
290 | extern rule AssignableChain; | 297 | extern rule AssignableChain; |
291 | 298 | ||
292 | rule Assignable = AssignableChain | Space >> Variable | SelfName; | 299 | rule Assignable = AssignableChain | Space >> Variable | SelfName; |
293 | 300 | ||
294 | extern rule Value; | 301 | extern rule Value; |
295 | 302 | ||
296 | rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; | 303 | rule exp_op_value = Space >> (BackcallOperator | BinaryOperator) >> *SpaceBreak >> Value; |
297 | rule Exp = Value >> *exp_op_value; | 304 | rule Exp = Value >> *exp_op_value; |
298 | 305 | ||
299 | extern rule Chain, Callable, InvokeArgs, existential_op; | 306 | extern rule Chain, Callable, InvokeArgs, existential_op; |
@@ -334,7 +341,7 @@ rule LuaStringClose = pl::user(lua_string_close, [](const item_t& item) | |||
334 | return st->stringOpen == count; | 341 | return st->stringOpen == count; |
335 | }); | 342 | }); |
336 | 343 | ||
337 | rule LuaStringContent = *(not_(LuaStringClose) >> (Break | Any)); | 344 | rule LuaStringContent = *(not_(LuaStringClose) >> Any); |
338 | 345 | ||
339 | rule LuaString = pl::user(LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose, [](const item_t& item) | 346 | rule LuaString = pl::user(LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose, [](const item_t& item) |
340 | { | 347 | { |
@@ -474,6 +481,8 @@ rule NameList = Seperator >> Space >> Variable >> *(sym(',') >> Space >> Variabl | |||
474 | rule NameOrDestructure = Space >> Variable | TableLit; | 481 | rule NameOrDestructure = Space >> Variable | TableLit; |
475 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); | 482 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); |
476 | 483 | ||
484 | rule Backcall = -FnArgsDef >> Space >> symx("<-") >> Space >> ChainValue; | ||
485 | |||
477 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); | 486 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); |
478 | rule ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> Exp); | 487 | rule ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> Exp); |
479 | 488 | ||
@@ -518,7 +527,7 @@ rule Statement = | |||
518 | ( | 527 | ( |
519 | Import | While | For | ForEach | | 528 | Import | While | For | ForEach | |
520 | Return | Local | Export | Space >> BreakLoop | | 529 | Return | Local | Export | Space >> BreakLoop | |
521 | ExpListAssign | 530 | Backcall | ExpListAssign |
522 | ) >> Space >> | 531 | ) >> Space >> |
523 | -statement_appendix; | 532 | -statement_appendix; |
524 | 533 | ||