Skip to content

Commit a5b59f3

Browse files
committed
improve col_offset in new line and lalr
1 parent d5a208c commit a5b59f3

6 files changed

Lines changed: 34 additions & 34 deletions

‎core/src/location.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Location {
5656

5757
pub fn newline(&mut self) {
5858
self.row += 1;
59-
self.column = 1;
59+
self.column = 0;
6060
}
6161
}
6262

‎parser/python.lalrpop‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ ShiftOp: ast::Operator = {
871871
};
872872

873873
ArithmeticExpression: ast::Expr = {
874-
<a:ArithmeticExpression> <location:@L> <op:AddOp> <b:Term> <end_location:@R> => ast::Expr {
874+
<location:@L> <a:ArithmeticExpression> <op:AddOp> <b:Term> <end_location:@R> => ast::Expr {
875875
location,
876876
end_location: Some(end_location),
877877
custom: (),

‎parser/src/parser.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
3535
/// assert_eq!(
3636
/// expr,
3737
/// ast::Expr {
38-
/// location: ast::Location::new(1, 2),
38+
/// location: ast::Location::new(1, 0),
3939
/// end_location: Some(ast::Location::new(1, 5)),
4040
/// custom: (),
4141
/// node: ast::ExprKind::BinOp {

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_class.snap‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
1111
end_location: Some(
1212
Location {
1313
row: 5,
14-
column: 7,
14+
column: 6,
1515
},
1616
),
1717
custom: (),
@@ -58,12 +58,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
5858
Located {
5959
location: Location {
6060
row: 2,
61-
column: 2,
61+
column: 1,
6262
},
6363
end_location: Some(
6464
Location {
6565
row: 4,
66-
column: 2,
66+
column: 1,
6767
},
6868
),
6969
custom: (),
@@ -75,12 +75,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
7575
Located {
7676
location: Location {
7777
row: 2,
78-
column: 15,
78+
column: 14,
7979
},
8080
end_location: Some(
8181
Location {
8282
row: 2,
83-
column: 19,
83+
column: 18,
8484
},
8585
),
8686
custom: (),
@@ -101,12 +101,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
101101
Located {
102102
location: Location {
103103
row: 3,
104-
column: 3,
104+
column: 2,
105105
},
106106
end_location: Some(
107107
Location {
108108
row: 3,
109-
column: 7,
109+
column: 6,
110110
},
111111
),
112112
custom: (),
@@ -121,12 +121,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
121121
Located {
122122
location: Location {
123123
row: 4,
124-
column: 2,
124+
column: 1,
125125
},
126126
end_location: Some(
127127
Location {
128128
row: 5,
129-
column: 7,
129+
column: 6,
130130
},
131131
),
132132
custom: (),
@@ -138,12 +138,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
138138
Located {
139139
location: Location {
140140
row: 4,
141-
column: 26,
141+
column: 25,
142142
},
143143
end_location: Some(
144144
Location {
145145
row: 4,
146-
column: 30,
146+
column: 29,
147147
},
148148
),
149149
custom: (),
@@ -156,12 +156,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
156156
Located {
157157
location: Location {
158158
row: 4,
159-
column: 32,
159+
column: 31,
160160
},
161161
end_location: Some(
162162
Location {
163163
row: 4,
164-
column: 35,
164+
column: 34,
165165
},
166166
),
167167
custom: (),
@@ -180,12 +180,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
180180
Located {
181181
location: Location {
182182
row: 4,
183-
column: 36,
183+
column: 35,
184184
},
185185
end_location: Some(
186186
Location {
187187
row: 4,
188-
column: 45,
188+
column: 44,
189189
},
190190
),
191191
custom: (),
@@ -202,12 +202,12 @@ expression: "parse_program(source, \"<test>\").unwrap()"
202202
Located {
203203
location: Location {
204204
row: 5,
205-
column: 3,
205+
column: 2,
206206
},
207207
end_location: Some(
208208
Location {
209209
row: 5,
210-
column: 7,
210+
column: 6,
211211
},
212212
),
213213
custom: (),

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expression: parse_ast
1111
end_location: Some(
1212
Location {
1313
row: 3,
14-
column: 9,
14+
column: 8,
1515
},
1616
),
1717
custom: (),
@@ -75,25 +75,25 @@ expression: parse_ast
7575
Located {
7676
location: Location {
7777
row: 2,
78-
column: 1,
78+
column: 0,
7979
},
8080
end_location: Some(
8181
Location {
8282
row: 3,
83-
column: 1,
83+
column: 0,
8484
},
8585
),
8686
custom: (),
8787
node: If {
8888
test: Located {
8989
location: Location {
9090
row: 2,
91-
column: 6,
91+
column: 5,
9292
},
9393
end_location: Some(
9494
Location {
9595
row: 2,
96-
column: 7,
96+
column: 6,
9797
},
9898
),
9999
custom: (),
@@ -108,25 +108,25 @@ expression: parse_ast
108108
Located {
109109
location: Location {
110110
row: 2,
111-
column: 9,
111+
column: 8,
112112
},
113113
end_location: Some(
114114
Location {
115115
row: 2,
116-
column: 11,
116+
column: 10,
117117
},
118118
),
119119
custom: (),
120120
node: Expr {
121121
value: Located {
122122
location: Location {
123123
row: 2,
124-
column: 9,
124+
column: 8,
125125
},
126126
end_location: Some(
127127
Location {
128128
row: 2,
129-
column: 11,
129+
column: 10,
130130
},
131131
),
132132
custom: (),
@@ -144,25 +144,25 @@ expression: parse_ast
144144
Located {
145145
location: Location {
146146
row: 3,
147-
column: 7,
147+
column: 6,
148148
},
149149
end_location: Some(
150150
Location {
151151
row: 3,
152-
column: 9,
152+
column: 8,
153153
},
154154
),
155155
custom: (),
156156
node: Expr {
157157
value: Located {
158158
location: Location {
159159
row: 3,
160-
column: 7,
160+
column: 6,
161161
},
162162
end_location: Some(
163163
Location {
164164
row: 3,
165-
column: 9,
165+
column: 8,
166166
},
167167
),
168168
custom: (),

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_named_expression_generator_comprehension.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Located {
4848
value: Located {
4949
location: Location {
5050
row: 1,
51-
column: 8,
51+
column: 6,
5252
},
5353
end_location: Some(
5454
Location {

0 commit comments

Comments
 (0)