Skip to content

Commit

Permalink
fix: add space between a numeral and following period
Browse files Browse the repository at this point in the history
  • Loading branch information
vsariola committed Aug 20, 2023
1 parent 862cd68 commit 6aeb934
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Escaping `\r` and `\f` in quoted string literals
- `-- {` was not considered comment, even though it was not considered
permutation block either
- Add space between a numeral and following period when printing. For
example, `1 ..2` (string concatenation) should not be printed as
`1..2`, as LUA then parses the beginning of it as floating point
numeral `1.`

## [1.2.0] - 2023-04-02

Expand Down
4 changes: 2 additions & 2 deletions pakettic/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def format(node: ast.Node, pretty: bool = False, no_load: bool = False) -> str:
return Formatter(pretty=pretty, no_load=no_load).format(node)


_hexy = re.compile('[0-9a-fxA-FXpP]').search
_hexy = re.compile(r'[0-9a-fxA-FXpP\.]').search
_alphaunder = re.compile('[_a-zA-Z]').search
_alphanumunder = re.compile('[_a-zA-Z0-9]').search
_single_quote_translation = str.maketrans({"\n": r"\n",
Expand Down Expand Up @@ -57,7 +57,7 @@ def __addspaces(self, tokens: typing.Iterable[str]):
# the previous token was word, and the next continues with a character that might be confused with it
yield ' '
elif type(prevtoken) is ast.Numeral and bool(_hexy(token[0])):
yield ' ' # the previous token was numeral and the next starts with something that be confused with a hex
yield ' ' # the previous token was numeral and the next starts with something that be confused with a hex or a decimal point
yield token
elif type(token) is ast.Numeral:
strnumeral = str(token)
Expand Down
1 change: 1 addition & 0 deletions tests/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_printing_parsed_code(self):
"x='\\r'",
"x='\\t'",
"x='\\f'",
"x=1 ..2",
]
for a in cases:
with self.subTest(code=a):
Expand Down

0 comments on commit 6aeb934

Please sign in to comment.