Skip to content

Commit 4f14fc7

Browse files
committed
improve col_offset in new line and lalr
1 parent c816b0b commit 4f14fc7

7 files changed

+34
-62
lines changed

Lib/test/test_ast.py

-28
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,6 @@ def bad_normalize(*args):
655655
with support.swap_attr(unicodedata, 'normalize', bad_normalize):
656656
self.assertRaises(TypeError, ast.parse, '\u03D5')
657657

658-
# TODO: RUSTPYTHON
659-
@unittest.expectedFailure
660658
def test_issue18374_binop_col_offset(self):
661659
tree = ast.parse('4+5+6+7')
662660
parent_binop = tree.body[0].value
@@ -994,8 +992,6 @@ def test_get_docstring_none(self):
994992
node = ast.parse('async def foo():\n x = "not docstring"')
995993
self.assertIsNone(ast.get_docstring(node.body[0]))
996994

997-
# TODO: RUSTPYTHON
998-
@unittest.expectedFailure
999995
def test_multi_line_docstring_col_offset_and_lineno_issue16806(self):
1000996
node = ast.parse(
1001997
'"""line one\nline two"""\n\n'
@@ -1015,16 +1011,12 @@ def test_multi_line_docstring_col_offset_and_lineno_issue16806(self):
10151011
self.assertEqual(node.body[2].col_offset, 0)
10161012
self.assertEqual(node.body[2].lineno, 13)
10171013

1018-
# TODO: RUSTPYTHON
1019-
@unittest.expectedFailure
10201014
def test_elif_stmt_start_position(self):
10211015
node = ast.parse('if a:\n pass\nelif b:\n pass\n')
10221016
elif_stmt = node.body[0].orelse[0]
10231017
self.assertEqual(elif_stmt.lineno, 3)
10241018
self.assertEqual(elif_stmt.col_offset, 0)
10251019

1026-
# TODO: RUSTPYTHON
1027-
@unittest.expectedFailure
10281020
def test_elif_stmt_start_position_with_else(self):
10291021
node = ast.parse('if a:\n pass\nelif b:\n pass\nelse:\n pass\n')
10301022
elif_stmt = node.body[0].orelse[0]
@@ -1932,8 +1924,6 @@ def test_lambda(self):
19321924
self._check_content(s, lam.args.args[0], 'x')
19331925
self._check_content(s, lam.args.vararg, 'y')
19341926

1935-
# TODO: RUSTPYTHON
1936-
@unittest.expectedFailure
19371927
def test_func_def(self):
19381928
s = dedent('''
19391929
def func(x: int,
@@ -1963,8 +1953,6 @@ def test_call_noargs(self):
19631953
self._check_content(s, call.func, 'x[0]')
19641954
self._check_end_pos(call, 1, 6)
19651955

1966-
# TODO: RUSTPYTHON
1967-
@unittest.expectedFailure
19681956
def test_class_def(self):
19691957
s = dedent('''
19701958
class C(A, B):
@@ -1980,8 +1968,6 @@ def test_class_kw(self):
19801968
cdef = ast.parse(s).body[0]
19811969
self._check_content(s, cdef.keywords[0].value, 'abc.ABCMeta')
19821970

1983-
# TODO: RUSTPYTHON
1984-
@unittest.expectedFailure
19851971
def test_multi_line_str(self):
19861972
s = dedent('''
19871973
x = """Some multi-line text.
@@ -2075,8 +2061,6 @@ def test_fstring_multi_line(self):
20752061
self._check_content(s, binop.left, 'arg_one')
20762062
self._check_content(s, binop.right, 'arg_two')
20772063

2078-
# TODO: RUSTPYTHON
2079-
@unittest.expectedFailure
20802064
def test_import_from_multi_line(self):
20812065
s = dedent('''
20822066
from x.y.z import (
@@ -2087,8 +2071,6 @@ def test_import_from_multi_line(self):
20872071
self._check_end_pos(imp, 3, 1)
20882072
self._check_end_pos(imp.names[2], 2, 16)
20892073

2090-
# TODO: RUSTPYTHON
2091-
@unittest.expectedFailure
20922074
def test_slices(self):
20932075
s1 = 'f()[1, 2] [0]'
20942076
s2 = 'x[ a.b: c.d]'
@@ -2106,8 +2088,6 @@ def test_slices(self):
21062088
self._check_content(sm, im.slice.elts[1].lower, 'g ()')
21072089
self._check_end_pos(im, 3, 3)
21082090

2109-
# TODO: RUSTPYTHON
2110-
@unittest.expectedFailure
21112091
def test_binop(self):
21122092
s = dedent('''
21132093
(1 * 2 + (3 ) +
@@ -2156,8 +2136,6 @@ def test_attribute_spaces(self):
21562136
self._check_content(s, call, s)
21572137
self._check_content(s, call.args[0], 'x. y .z')
21582138

2159-
# TODO: RUSTPYTHON
2160-
@unittest.expectedFailure
21612139
def test_redundant_parenthesis(self):
21622140
s = '( ( ( a + b ) ) )'
21632141
v = ast.parse(s).body[0].value
@@ -2196,8 +2174,6 @@ def test_displays(self):
21962174
self._check_content(s2, c2.keys[1], 'f ()')
21972175
self._check_content(s2, c2.values[1], 'g ()')
21982176

2199-
# TODO: RUSTPYTHON
2200-
@unittest.expectedFailure
22012177
def test_comprehensions(self):
22022178
s = dedent('''
22032179
x = [{x for x, y in stuff
@@ -2210,8 +2186,6 @@ def test_comprehensions(self):
22102186
self._check_content(s, cmp.elt.generators[0].ifs[0], 'cond.x')
22112187
self._check_content(s, cmp.elt.generators[0].target, 'x, y')
22122188

2213-
# TODO: RUSTPYTHON
2214-
@unittest.expectedFailure
22152189
def test_yield_await(self):
22162190
s = dedent('''
22172191
async def f():
@@ -2252,8 +2226,6 @@ def fun(self) -> None:
22522226
self.assertEqual(ast.get_source_segment(s_orig, cdef.body[0], padded=True),
22532227
s_method)
22542228

2255-
# TODO: RUSTPYTHON
2256-
@unittest.expectedFailure
22572229
def test_source_segment_endings(self):
22582230
s = 'v = 1\r\nw = 1\nx = 1\n\ry = 1\rz = 1\r\n'
22592231
v, w, x, y, z = ast.parse(s).body

compiler/core/src/location.rs

+1-1
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

compiler/parser/python.lalrpop

+1-1
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: (),

compiler/parser/src/parser.rs

+1-1
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 {

compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_class.snap

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_named_expression_generator_comprehension.snap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)