33from .errors import ParseError
44
55
6- INLINE_WS = (' ' , '\t ' )
6+ INLINE_WS = ' '
7+ ANY_WS = (INLINE_WS , '\n ' )
78SPECIAL_LINE_START_CHARS = ('}' , '.' , '[' , '*' )
89
910
1011class FTLParserStream (ParserStream ):
1112 last_comment_zero_four_syntax = False
1213
13- def skip_inline_ws (self ):
14+ def skip_blank_inline (self ):
1415 while self .ch :
15- if self .ch not in INLINE_WS :
16+ if self .ch != INLINE_WS :
1617 break
1718 self .next ()
1819
19- def peek_inline_ws (self ):
20+ def peek_blank_inline (self ):
2021 ch = self .current_peek ()
2122 while ch :
22- if ch not in INLINE_WS :
23+ if ch != INLINE_WS :
2324 break
2425 ch = self .peek ()
2526
26- def skip_blank_lines (self ):
27+ def skip_blank_block (self ):
2728 line_count = 0
2829 while True :
29- self .peek_inline_ws ()
30+ self .peek_blank_inline ()
3031
3132 if self .current_peek_is ('\n ' ):
3233 self .skip_to_peek ()
@@ -36,21 +37,25 @@ def skip_blank_lines(self):
3637 self .reset_peek ()
3738 return line_count
3839
39- def peek_blank_lines (self ):
40+ def peek_blank_block (self ):
4041 while True :
4142 line_start = self .get_peek_index ()
4243
43- self .peek_inline_ws ()
44+ self .peek_blank_inline ()
4445
4546 if self .current_peek_is ('\n ' ):
4647 self .peek ()
4748 else :
4849 self .reset_peek (line_start )
4950 break
5051
51- def skip_indent (self ):
52- self .skip_blank_lines ()
53- self .skip_inline_ws ()
52+ def skip_blank (self ):
53+ while self .ch in ANY_WS :
54+ self .next ()
55+
56+ def peek_blank (self ):
57+ while self .current_peek () in ANY_WS :
58+ self .peek ()
5459
5560 def expect_char (self , ch ):
5661 if self .ch == ch :
@@ -63,12 +68,6 @@ def expect_char(self, ch):
6368
6469 raise ParseError ('E0003' , ch )
6570
66- def expect_indent (self ):
67- self .expect_char ('\n ' )
68- self .skip_blank_lines ()
69- self .expect_char (' ' )
70- self .skip_inline_ws ()
71-
7271 def expect_line_end (self ):
7372 if self .ch is None :
7473 # EOF is a valid line end in Fluent.
@@ -112,17 +111,24 @@ def is_char_pattern_continuation(self, ch):
112111
113112 return ch not in SPECIAL_LINE_START_CHARS
114113
115- def is_peek_value_start (self ):
116- self .peek_inline_ws ()
114+ def is_value_start (self , skip ):
115+ if skip is False :
116+ raise NotImplementedError ()
117+
118+ self .peek_blank_inline ()
117119 ch = self .current_peek ()
118120
119121 # Inline Patterns may start with any char.
120122 if ch is not None and ch != '\n ' :
123+ self .skip_to_peek ()
121124 return True
122125
123- return self .is_peek_next_line_value ()
126+ return self .is_next_line_value (skip )
127+
128+ def is_next_line_zero_four_comment (self , skip ):
129+ if skip is True :
130+ raise NotImplementedError ()
124131
125- def is_peek_next_line_zero_four_style_comment (self ):
126132 if not self .current_peek_is ('\n ' ):
127133 return False
128134
@@ -141,7 +147,10 @@ def is_peek_next_line_zero_four_style_comment(self):
141147 # 0 - comment
142148 # 1 - group comment
143149 # 2 - resource comment
144- def is_peek_next_line_comment (self , level = - 1 ):
150+ def is_next_line_comment (self , skip , level = - 1 ):
151+ if skip is True :
152+ raise NotImplementedError ()
153+
145154 if not self .current_peek_is ('\n ' ):
146155 return False
147156
@@ -165,21 +174,14 @@ def is_peek_next_line_comment(self, level=-1):
165174 self .reset_peek ()
166175 return False
167176
168- def is_peek_next_line_variant_start (self ):
177+ def is_next_line_variant_start (self , skip ):
178+ if skip is True :
179+ raise NotImplementedError ()
180+
169181 if not self .current_peek_is ('\n ' ):
170182 return False
171183
172- self .peek ()
173-
174- self .peek_blank_lines ()
175-
176- ptr = self .get_peek_index ()
177-
178- self .peek_inline_ws ()
179-
180- if (self .get_peek_index () - ptr == 0 ):
181- self .reset_peek ()
182- return False
184+ self .peek_blank ()
183185
184186 if self .current_peek_is ('*' ):
185187 self .peek ()
@@ -191,50 +193,43 @@ def is_peek_next_line_variant_start(self):
191193 self .reset_peek ()
192194 return False
193195
194- def is_peek_next_line_attribute_start (self ):
195- if not self .current_peek_is ('\n ' ):
196- return False
197-
198- self .peek ()
199-
200- self .peek_blank_lines ()
201-
202- ptr = self .get_peek_index ()
203-
204- self .peek_inline_ws ()
196+ def is_next_line_attribute_start (self , skip ):
197+ if skip is False :
198+ raise NotImplementedError ()
205199
206- if (self .get_peek_index () - ptr == 0 ):
207- self .reset_peek ()
208- return False
200+ self .peek_blank ()
209201
210202 if self .current_peek_is ('.' ):
211- self .reset_peek ()
203+ self .skip_to_peek ()
212204 return True
213205
214206 self .reset_peek ()
215207 return False
216208
217- def is_peek_next_line_value (self ):
209+ def is_next_line_value (self , skip ):
218210 if not self .current_peek_is ('\n ' ):
219211 return False
220212
221- self .peek ()
222-
223- self .peek_blank_lines ()
213+ self .peek_blank_block ()
224214
225215 ptr = self .get_peek_index ()
226216
227- self .peek_inline_ws ()
217+ self .peek_blank_inline ()
228218
229- if (self .get_peek_index () - ptr == 0 ):
230- self .reset_peek ()
231- return False
219+ if not self .current_peek_is ("{" ):
220+ if (self .get_peek_index () - ptr == 0 ):
221+ self .reset_peek ()
222+ return False
232223
233- if not self .is_char_pattern_continuation (self .current_peek ()):
224+ if not self .is_char_pattern_continuation (self .current_peek ()):
225+ self .reset_peek ()
226+ return False
227+
228+ if skip :
229+ self .skip_to_peek ()
230+ else :
234231 self .reset_peek ()
235- return False
236232
237- self .reset_peek ()
238233 return True
239234
240235 def skip_to_next_entry_start (self ):
0 commit comments