Skip to content

Commit 7cb7fac

Browse files
committed
Respect the with_spans setting for Annotations
Prior to this change, Annotations would always have span information, irrespective of the value of the with_spans argument to the parser. This change changes the behaviour to only include span information if with_spans if set to True.
1 parent 7888ba1 commit 7cb7fac

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fluent.syntax/fluent/syntax/parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def get_entry_or_junk(self, ps: FluentParserStream) -> ast.EntryType:
133133
annot = ast.Annotation(
134134
err.code, list(err.args) if err.args else None, err.message
135135
)
136-
annot.add_span(error_index, error_index)
136+
if self.with_spans:
137+
annot.add_span(error_index, error_index)
137138
junk.add_annotation(annot)
138139
return junk
139140

fluent.syntax/tests/syntax/test_entry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_return_junk(self):
6565
"arguments": ["="],
6666
"code": "E0003",
6767
"message": 'Expected token: "="',
68-
"span": {"end": 23, "start": 23, "type": "Span"},
68+
"span": None,
6969
"type": "Annotation",
7070
}
7171
],
@@ -111,7 +111,7 @@ def test_do_not_ignore_invalid_comments(self):
111111
"arguments": [" "],
112112
"code": "E0003",
113113
"message": 'Expected token: " "',
114-
"span": {"end": 21, "start": 21, "type": "Span"},
114+
"span": None,
115115
"type": "Annotation",
116116
}
117117
],

0 commit comments

Comments
 (0)