Skip to content

Commit

Permalink
fix comment parsing with Assign, fix #39
Browse files Browse the repository at this point in the history
  • Loading branch information
boolangery committed Oct 27, 2024
1 parent fe8e483 commit e1fb334
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions luaparser/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def visitStat_assignment(self, ctx: LuaParser.Stat_assignmentContext):
return self.add_context(ctx, Assign(
targets=_listify(self.visit(ctx.varlist())),
values=_listify(self.visit(ctx.explist())),
))
), allow_right_ctx=True)

# Visit a parse tree produced by LuaParser#stat_functioncall.
def visitStat_functioncall(self, ctx: LuaParser.Stat_functioncallContext):
Expand All @@ -185,7 +185,7 @@ def visitStat_label(self, ctx: LuaParser.Stat_labelContext):

# Visit a parse tree produced by LuaParser#stat_break.
def visitStat_break(self, ctx: LuaParser.Stat_breakContext):
return self.add_context(ctx, Break())
return self.add_context(ctx, Break(), allow_right_ctx=True)

# Visit a parse tree produced by LuaParser#stat_goto.
def visitStat_goto(self, ctx: LuaParser.Stat_gotoContext):
Expand Down
28 changes: 28 additions & 0 deletions luaparser/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,31 @@ def test_cont_int_12(self):
])
)
self.assertEqual(exp, tree)

# Comments with Chinese characters are discarded #39
def test_cont_int_13(self):
tree = ast.parse(textwrap.dedent("""
function setupRichText()
richText.fitArea = false -- 是否根据内容自适应高度
richText.fitPerHeight = nil -- 自适应的单行高度
return richText
end
"""))
exp = Chunk(
Block([
Function(
name=Name("setupRichText"),
args=[],
body=Block([
Assign([Index(Name("fitArea"), Name("richText"))], [FalseExpr()], comments=[
Comment('-- 是否根据内容自适应高度')
]),
Assign([Index(Name("fitPerHeight"), Name("richText"))], [Nil()], comments=[
Comment('-- 自适应的单行高度')
]),
Return([Name("richText")])
])
)
])
)
self.assertEqual(exp, tree)

0 comments on commit e1fb334

Please sign in to comment.