Skip to content

Commit e1eac00

Browse files
authored
Merge pull request #78 from stasm/zeroeight
Implement Syntax 0.8
2 parents 6f3b911 + be596db commit e1eac00

File tree

108 files changed

+9397
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+9397
-514
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
tests/syntax/fixtures_reference/crlf.ftl eol=crlf
2+
tests/syntax/fixtures_reference/cr.ftl eol=cr
23
tests/syntax/fixtures_structure/crlf.ftl eol=crlf

fluent/syntax/ast.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import json
44

55

6-
def to_json(value):
6+
def to_json(value, fn=None):
77
if isinstance(value, BaseNode):
8-
return value.to_json()
8+
return value.to_json(fn)
99
if isinstance(value, list):
10-
return list(map(to_json, value))
10+
return list(to_json(item, fn) for item in value)
1111
if isinstance(value, tuple):
12-
return list(map(to_json, value))
12+
return list(to_json(item, fn) for item in value)
1313
else:
1414
return value
1515

@@ -119,15 +119,15 @@ def equals(self, other, ignored_fields=['span']):
119119

120120
return True
121121

122-
def to_json(self):
122+
def to_json(self, fn=None):
123123
obj = {
124-
name: to_json(value)
124+
name: to_json(value, fn)
125125
for name, value in vars(self).items()
126126
}
127127
obj.update(
128128
{'type': self.__class__.__name__}
129129
)
130-
return obj
130+
return fn(obj) if fn else obj
131131

132132
def __str__(self):
133133
return json.dumps(self.to_json())
@@ -207,8 +207,9 @@ class Expression(SyntaxNode):
207207

208208

209209
class StringLiteral(Expression):
210-
def __init__(self, value, **kwargs):
210+
def __init__(self, raw, value, **kwargs):
211211
super(StringLiteral, self).__init__(**kwargs)
212+
self.raw = raw
212213
self.value = value
213214

214215

@@ -236,6 +237,12 @@ def __init__(self, id, **kwargs):
236237
self.id = id
237238

238239

240+
class FunctionReference(Expression):
241+
def __init__(self, id, **kwargs):
242+
super(FunctionReference, self).__init__(**kwargs)
243+
self.id = id
244+
245+
239246
class SelectExpression(Expression):
240247
def __init__(self, selector, variants, **kwargs):
241248
super(SelectExpression, self).__init__(**kwargs)
@@ -324,11 +331,6 @@ def __init__(self, content=None, **kwargs):
324331
super(ResourceComment, self).__init__(content, **kwargs)
325332

326333

327-
class Function(Identifier):
328-
def __init__(self, name, **kwargs):
329-
super(Function, self).__init__(name, **kwargs)
330-
331-
332334
class Junk(SyntaxNode):
333335
def __init__(self, content=None, annotations=None, **kwargs):
334336
super(Junk, self).__init__(**kwargs)

fluent/syntax/errors.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def get_error_message(code, args):
2121
msg = 'Expected message "{}" to have a value or attributes'
2222
return msg.format(args[0])
2323
if code == 'E0006':
24-
msg = 'Expected term "{}" to have a value'
24+
msg = 'Expected term "-{}" to have a value'
2525
return msg.format(args[0])
2626
if code == 'E0007':
2727
return 'Keyword cannot end with a whitespace'
2828
if code == 'E0008':
29-
return 'The callee has to be a simple, upper-case identifier'
29+
return 'The callee has to be an upper-case identifier or a term'
3030
if code == 'E0009':
3131
return 'The key has to be a simple identifier'
3232
if code == 'E0010':
@@ -44,7 +44,7 @@ def get_error_message(code, args):
4444
if code == 'E0016':
4545
return 'Message references cannot be used as selectors'
4646
if code == 'E0017':
47-
return 'Variants cannot be used as selectors'
47+
return 'Terms cannot be used as selectors'
4848
if code == 'E0018':
4949
return 'Attributes of messages cannot be used as selectors'
5050
if code == 'E0019':
@@ -55,12 +55,14 @@ def get_error_message(code, args):
5555
return 'Positional arguments must not follow named arguments'
5656
if code == 'E0022':
5757
return 'Named arguments must be unique'
58-
if code == 'E0023':
59-
return 'VariantLists are only allowed inside of other VariantLists.'
6058
if code == 'E0024':
6159
return 'Cannot access variants of a message.'
6260
if code == 'E0025':
63-
return 'Unknown escape sequence: {}'.format(args[0])
61+
return 'Unknown escape sequence: \\{}.'.format(args[0])
6462
if code == 'E0026':
6563
return 'Invalid Unicode escape sequence: {}'.format(args[0])
64+
if code == 'E0027':
65+
return 'Unbalanced closing brace in TextElement.'
66+
if code == 'E0028':
67+
return 'Expected an inline expression'
6668
return code

0 commit comments

Comments
 (0)