Skip to content

Commit 2fda6cb

Browse files
Merge pull request #976 from akshanshbhatt/pr_fix_multi_comm
2 parents 0204dcc + 08d877f commit 2fda6cb

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/lpython/parser/parser.yy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ statements1
326326

327327
single_line_statements
328328
: single_line_multi_statements TK_NEWLINE { $$ = $1; }
329-
| single_line_multi_statements TK_COMMENT TK_NEWLINE { $$ = $1; }
329+
| single_line_multi_statements TK_EOLCOMMENT { $$ = $1; }
330330
| single_line_statement TK_NEWLINE { $$ = A2LIST(p.m_a, $1); }
331331
| single_line_statement TK_SEMICOLON TK_NEWLINE { $$ = A2LIST(p.m_a, $1); }
332-
| single_line_statement TK_SEMICOLON TK_COMMENT TK_NEWLINE { $$ = A2LIST(p.m_a, $1); }
333-
| single_line_statement TK_COMMENT TK_NEWLINE { $$ = A2LIST(p.m_a, $1); }
332+
| single_line_statement TK_SEMICOLON TK_EOLCOMMENT { $$ = A2LIST(p.m_a, $1); }
333+
| single_line_statement TK_EOLCOMMENT { $$ = A2LIST(p.m_a, $1); }
334334
;
335335

336336
single_line_multi_statements

tests/parser/if1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
pass
3636
else: a = b
3737

38+
if a == b: pass # comment
39+
if a == b: pass; # comment
40+
if a == b: x = a + b; break # comment
41+
if a == b: x = a + b; break; # comment
42+
3843
# TODO: Make this work (basically separated by multiple sep(s)).
3944
# at present, it only works with a single newline separator.
4045

tests/reference/ast_new-if1-db43586.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-if1-db43586",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/if1.py",
5-
"infile_hash": "f6b4162b0a0f7d4040292c998d464fb0b8613ce2f1f696035a7243d4",
5+
"infile_hash": "22ff1df9592cea862ebc5a2a03f872b87d7ef6cf7101670e8fc566da",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-if1-db43586.stdout",
9-
"stdout_hash": "08138f8420c2f2f5b8b8c072456203a6d5912fd7259984cc062b2cd3",
9+
"stdout_hash": "267cff14e40641f5155167245af70ec048b692c5644aaf4d60d4334d",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(Module [(Assign [(Name x Store)] (ConstantInt 10 ()) ()) (Assign [(Name y Store)] (ConstantInt 14 ()) ()) (Assign [(Name z Store)] (ConstantInt 12 ()) ()) (If (BoolOp And [(Compare (Name x Load) GtE [(Name y Load)]) (Compare (Name x Load) GtE [(Name z Load)])]) [(Assign [(Name largest Store)] (Name x Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name x Load)] []))] [(If (BoolOp And [(Compare (Name y Load) GtE [(Name x Load)]) (Compare (Name y Load) GtE [(Name z Load)])]) [(Assign [(Name largest Store)] (Name y Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name y Load)] []))] [(Assign [(Name largest Store)] (Name z Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name z Load)] []))])]) (If (Compare (Name y Load) Gt [(ConstantInt 10 ())]) [(Expr (Call (Name print Load) [(ConstantStr "Above ten," ())] [])) (If (Compare (Name y Load) Gt [(ConstantInt 20 ())]) [(Expr (Call (Name print Load) [(ConstantStr "and also above 20!" ())] []))] [(Expr (Call (Name print Load) [(ConstantStr "but not above 20." ())] []))])] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Expr (ConstantEllipsis ())) (AugAssign (Name a Store) Add (Name b Load))] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Expr (ConstantEllipsis ())) (AugAssign (Name a Store) Add (Name b Load))] []) (If (Name b Load) [(Expr (ConstantEllipsis ()))] [(Assign [(Name a Store)] (Name b Load) ())]) (If (Name b Load) [(Expr (ConstantEllipsis ()))] [(Assign [(Name a Store)] (Name b Load) ())]) (If (Name b Load) [(Pass)] [(Assign [(Name a Store)] (Name b Load) ())])] [])
1+
(Module [(Assign [(Name x Store)] (ConstantInt 10 ()) ()) (Assign [(Name y Store)] (ConstantInt 14 ()) ()) (Assign [(Name z Store)] (ConstantInt 12 ()) ()) (If (BoolOp And [(Compare (Name x Load) GtE [(Name y Load)]) (Compare (Name x Load) GtE [(Name z Load)])]) [(Assign [(Name largest Store)] (Name x Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name x Load)] []))] [(If (BoolOp And [(Compare (Name y Load) GtE [(Name x Load)]) (Compare (Name y Load) GtE [(Name z Load)])]) [(Assign [(Name largest Store)] (Name y Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name y Load)] []))] [(Assign [(Name largest Store)] (Name z Load) ()) (Expr (Call (Name print Load) [(ConstantStr "Largest: " ()) (Name z Load)] []))])]) (If (Compare (Name y Load) Gt [(ConstantInt 10 ())]) [(Expr (Call (Name print Load) [(ConstantStr "Above ten," ())] [])) (If (Compare (Name y Load) Gt [(ConstantInt 20 ())]) [(Expr (Call (Name print Load) [(ConstantStr "and also above 20!" ())] []))] [(Expr (Call (Name print Load) [(ConstantStr "but not above 20." ())] []))])] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Expr (ConstantEllipsis ())) (AugAssign (Name a Store) Add (Name b Load))] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Expr (ConstantEllipsis ())) (AugAssign (Name a Store) Add (Name b Load))] []) (If (Name b Load) [(Expr (ConstantEllipsis ()))] [(Assign [(Name a Store)] (Name b Load) ())]) (If (Name b Load) [(Expr (ConstantEllipsis ()))] [(Assign [(Name a Store)] (Name b Load) ())]) (If (Name b Load) [(Pass)] [(Assign [(Name a Store)] (Name b Load) ())]) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Pass)] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Pass)] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Assign [(Name x Store)] (BinOp (Name a Load) Add (Name b Load)) ()) (Break)] []) (If (Compare (Name a Load) Eq [(Name b Load)]) [(Assign [(Name x Store)] (BinOp (Name a Load) Add (Name b Load)) ()) (Break)] [])] [])

0 commit comments

Comments
 (0)