Skip to content

Commit 76fce89

Browse files
committed
Introduce FLOC and use it
1 parent 642da94 commit 76fce89

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/lpython/parser/parser.yy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ script_unit
315315
;
316316

317317
statements
318-
: TK_INDENT statements1 TK_DEDENT { @$.first = @2.first; LLOC(@$,@2); $$ = $2; }
318+
: TK_INDENT statements1 TK_DEDENT { FLOC(@$, @2); LLOC(@$,@2); $$ = $2; }
319319
;
320320

321321
sep_statements
322-
: sep statements { @$.first = @2.first; $$ = $2; }
323-
| type_ignore_sep statements { @$.first = @2.first; $$ = $2; }
322+
: sep statements { FLOC(@$, @2); $$ = $2; }
323+
| type_ignore_sep statements { FLOC(@$, @2); $$ = $2; }
324324
;
325325

326326
body_stmts
@@ -700,7 +700,7 @@ function_def
700700
: decorators_opt KW_DEF id "(" parameter_list_opt ")" ":"
701701
body_stmts { $$ = FUNCTION_01($1, $3, $5, $8, @$); }
702702
| decorators_opt KW_DEF id "(" parameter_list_opt ")" "->" expr ":"
703-
body_stmts { @$.first = @2.first; $$ = FUNCTION_02($1, $3, $5, $8, $10, @$); }
703+
body_stmts { FLOC(@$, @2); $$ = FUNCTION_02($1, $3, $5, $8, $10, @$); }
704704
| decorators_opt KW_DEF id "(" parameter_list_opt ")" ":"
705705
TK_TYPE_COMMENT sep statements {
706706
$$ = FUNCTION_03($1, $3, $5, $10, $8, @$); }
@@ -719,7 +719,7 @@ class_def
719719
: decorators_opt KW_CLASS id ":" body_stmts {
720720
$$ = CLASS_01($1, $3, $5, @$); }
721721
| decorators_opt KW_CLASS id "(" call_arguement_list ")" ":" body_stmts {
722-
@$.first = @2.first; $$ = CLASS_02($1, $3, $5, $8, @$); }
722+
FLOC(@$, @2); $$ = CLASS_02($1, $3, $5, $8, @$); }
723723
;
724724

725725
async_func_def

src/lpython/parser/semantics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static inline T** vec_cast(const Vec<ast_t*> &x) {
5858
return s;
5959
}
6060

61-
// Assign last location to `a` from `b`
61+
// Assign first/last location to `a` from `b`
62+
#define FLOC(a, b) a.first = b.first;
6263
#define LLOC(a, b) a.last = b.last;
6364

6465

0 commit comments

Comments
 (0)