Skip to content

Commit f4cdac8

Browse files
authored
Inline Patterns may start with any character (#48)
`}`, `.`, `*` and `[` are only special when they appear at the beginning of indented Pattern lines. When a Pattern starts on the same line as `id =` or `[variant key]`, its first character doesn't carry any special meaning and it may be one of those four ones as well. See also https://bugzilla.mozilla.org/show_bug.cgi?id=1436685. Port of projectfluent/fluent.js#150.
1 parent babad84 commit f4cdac8

File tree

7 files changed

+1086
-13
lines changed

7 files changed

+1086
-13
lines changed

fluent/syntax/ftlstream.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ def is_number_start(self):
106106
self.reset_peek()
107107
return is_digit
108108

109-
def is_char_pattern_start(self, ch):
109+
def is_char_pattern_continuation(self, ch):
110110
return ch not in SPECIAL_LINE_START_CHARS
111111

112112
def is_peek_pattern_start(self):
113113
self.peek_inline_ws()
114+
ch = self.current_peek()
114115

115-
if self.current_peek_is('\n'):
116-
return self.is_peek_next_line_pattern_start()
116+
# Inline Patterns may start with any char.
117+
if ch is not None and ch != '\n':
118+
return True
117119

118-
is_pattern = self.is_char_pattern_start(self.current_peek())
119-
self.reset_peek()
120-
return is_pattern
120+
return self.is_peek_next_line_pattern_start()
121121

122122
def is_peek_next_line_zero_four_style_comment(self):
123123
if not self.current_peek_is('\n'):
@@ -227,7 +227,7 @@ def is_peek_next_line_pattern_start(self):
227227
self.reset_peek()
228228
return False
229229

230-
if not self.is_char_pattern_start(self.current_peek()):
230+
if not self.is_char_pattern_continuation(self.current_peek()):
231231
self.reset_peek()
232232
return False
233233

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
key01 = .Value
2+
key02 = …Value
3+
key03 = {"."}Value
4+
key04 =
5+
{"."}Value
6+
7+
key05 = Value
8+
{"."}Continued
9+
10+
key06 = .Value
11+
{"."}Continued
12+
13+
# ERROR (attr .Continued must have a value)
14+
key07 = Value
15+
.Continued
16+
17+
# ERROR (attr .Value must have a value)
18+
key08 =
19+
.Value
20+
21+
# ERROR (attr .Value must have a value)
22+
key09 =
23+
.Value
24+
Continued
25+
26+
key10 =
27+
.Value = which looks like an attribute
28+
Continued
29+
30+
key11 =
31+
{"."}Value = which looks like an attribute
32+
Continued
33+
34+
key12 =
35+
.accesskey =
36+
A
37+
38+
key13 =
39+
.attribute = .Value
40+
41+
key14 =
42+
.attribute =
43+
{"."}Value
44+
45+
key15 =
46+
{ 1 ->
47+
[one] .Value
48+
*[other]
49+
{"."}Value
50+
}
51+
52+
# ERROR (variant must have a value)
53+
key16 =
54+
{ 1 ->
55+
*[one]
56+
.Value
57+
}
58+
59+
# ERROR (unclosed placeable)
60+
key17 =
61+
{ 1 ->
62+
*[one] Value
63+
.Continued
64+
}

0 commit comments

Comments
 (0)