Skip to content

Commit 1d15bdc

Browse files
committed
Avoid calling ord(None) if at EOF
Port of projectfluent/fluent.js#265
1 parent ca55dbd commit 1d15bdc

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

fluent/syntax/ftlstream.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ def is_identifier_start(self):
9797
return is_id
9898

9999
def is_number_start(self):
100-
if self.current_is('-'):
101-
self.peek()
100+
ch = self.peek() if self.current_is('-') else self.current()
101+
if ch is None:
102+
return False
102103

103-
cc = ord(self.current_peek())
104+
cc = ord(ch)
104105
is_digit = cc >= 48 and cc <= 57
105106
self.reset_peek()
106107
return is_digit
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### BE CAREFUL WHEN EDITING THIS FILE
2+
###
3+
### The last character in this file is the dash ("-") on line 8.
4+
### We want to test a literal which starts like a negative number.
5+
### Most editors automatically add a trailing newline at EOF.
6+
### If you edit this file make sure to turn this behavior off.
7+
8+
key1 = {-
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"type": "Resource",
3+
"body": [
4+
{
5+
"type": "ResourceComment",
6+
"content": "BE CAREFUL WHEN EDITING THIS FILE\n\nThe last character in this file is the dash (\"-\") on line 8.\nWe want to test a literal which starts like a negative number.\nMost editors automatically add a trailing newline at EOF.\nIf you edit this file make sure to turn this behavior off.",
7+
"span": {
8+
"type": "Span",
9+
"start": 0,
10+
"end": 298
11+
}
12+
},
13+
{
14+
"type": "Junk",
15+
"annotations": [
16+
{
17+
"type": "Annotation",
18+
"code": "E0004",
19+
"args": [
20+
"a-zA-Z"
21+
],
22+
"message": "Expected a character from range: \"a-zA-Z\"",
23+
"span": {
24+
"type": "Span",
25+
"start": 309,
26+
"end": 309
27+
}
28+
}
29+
],
30+
"content": "key1 = {-",
31+
"span": {
32+
"type": "Span",
33+
"start": 300,
34+
"end": 309
35+
}
36+
}
37+
],
38+
"span": {
39+
"type": "Span",
40+
"start": 0,
41+
"end": 309
42+
}
43+
}

0 commit comments

Comments
 (0)