Skip to content

Commit 7b67da5

Browse files
committed
Add a type alias for stream location
Prior to this change, the location in the parser stream was represented by the current index. We would like to update the parser stream to also return the source position (row/column) as part of the location information. This change adds a type alias to represent a location in the parser stream, and a property to return it. Currently, this is just the index, but we will update it in future commits. This allows us to break up the change to make it easier to review, as we can switch code paths which create span information to use locations before making any functional changes.
1 parent 91e8510 commit 7b67da5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fluent.syntax/fluent/syntax/stream.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
from typing import Callable, Union
1+
from typing import Callable, TypeAlias, Union
22

33
from typing_extensions import Literal
44

55
from .errors import ParseError
66

77

8+
# Represents a location in the parser stream (for convenience)
9+
# - Index
10+
Location: TypeAlias = int
11+
12+
813
class ParserStream:
914
def __init__(self, string: str):
1015
self.string = string
@@ -31,6 +36,10 @@ def char_at(self, offset: int) -> Union[str, None]:
3136

3237
return self.get(offset)
3338

39+
@property
40+
def current_location(self) -> Location:
41+
return self.index
42+
3443
@property
3544
def current_char(self) -> Union[str, None]:
3645
return self.char_at(self.index)

0 commit comments

Comments
 (0)