Skip to content

Commit 978751c

Browse files
committed
Return EOF or False from take_char if the predicate fails
1 parent 1c71ea9 commit 978751c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

fluent/syntax/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import unicode_literals
22
import re
33
from . import ast
4-
from .stream import EOL, FluentParserStream
4+
from .stream import EOF, EOL, FluentParserStream
55
from .errors import ParseError
66

77

@@ -322,7 +322,7 @@ def get_term_identifier(self, ps):
322322
def get_variant_key(self, ps):
323323
ch = ps.current_char
324324

325-
if ch is None:
325+
if ch is EOF:
326326
raise ParseError('E0013')
327327

328328
cc = ord(ch)
@@ -500,7 +500,7 @@ def get_escape_sequence(self, ps, specials=('{', '\\')):
500500

501501
for _ in range(4):
502502
ch = ps.take_hex_digit()
503-
if ch is None:
503+
if not ch:
504504
raise ParseError('E0026', sequence + ps.current_char)
505505
sequence += ch
506506

@@ -694,7 +694,7 @@ def get_string(self, ps):
694694
def get_literal(self, ps):
695695
ch = ps.current_char
696696

697-
if ch is None:
697+
if ch is EOF:
698698
raise ParseError('E0014')
699699

700700
if ch == '$':

fluent/syntax/stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ def expect_line_end(self):
128128

129129
def take_char(self, f):
130130
ch = self.current_char
131-
if ch is not EOF and f(ch):
131+
if ch is EOF:
132+
return EOF
133+
if f(ch):
132134
self.next()
133135
return ch
134-
return None
136+
return False
135137

136138
def is_char_id_start(self, ch):
137139
if ch is EOF:

0 commit comments

Comments
 (0)