Skip to content

Commit 35feafe

Browse files
committed
Define parser based on EBNF: all your Attributes are belong to us...
1 parent cfa3b72 commit 35feafe

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

fluent/syntax.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ local ftlparser = epnf.define(function (_ENV)
1212
local junk_line = (1-line_end)^0 * line_end
1313
Pattern = P"bar" + P"qiz"
1414
Junk = junk_line * (junk_line - P"#" - P"-" - R("az","AZ"))^0
15-
Attribute = P"yyy"
15+
Attribute = line_end * blank^-1 * P"." * V"Identifier" * blank_inline^-1 * "=" * blank_inline^-1 * V"Pattern"
1616
local comment_char = 1 - line_end
1717
CommentLine = (P"###" + P"##" + P"#") * (" " * comment_char^0)-1 * line_end
18-
Term = P"xxx"
18+
Term = P"-" * V"Identifier" * blank_inline^-1 * "=" * blank_inline^-1 * V"Pattern" * V"Attribute"^0
1919
Identifier = R("az", "AZ") * (R("az", "AZ", "09") + P"_" + P"-")^0
2020
Message = V"Identifier" * blank_inline^-1 * P"=" * blank_inline^-1 * ((V"Pattern" * V"Attribute"^0) + V"Attribute"^1)
2121
Entry = (V"Message" * line_end) + (V"Term" * line_end) + V"CommentLine"
@@ -24,7 +24,7 @@ local ftlparser = epnf.define(function (_ENV)
2424
end)
2525
-- luacheck: pop
2626

27-
-- TODO: Spec L15-L84, L86-L129
27+
-- TODO: Spec L33-L84, L86-L129
2828

2929
local FluentSyntax = class({
3030
parser = ftlparser,

spec/fluent_syntax_spec.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ describe('fluent.syntax', function ()
3737
assert.equals("Entry", syntax:parse("baz = qiz")[1].id)
3838
end)
3939

40+
it('should handle term entries', function ()
41+
assert.equals("Entry", syntax:parse("-foo = bar")[1].id)
42+
assert.equals("Entry", syntax:parse("-baz = qiz")[1].id)
43+
end)
44+
45+
it('should handle a entry with an attribute', function ()
46+
assert.equals("Entry", syntax:parse("foo = bar\n .baz = quiz")[1].id)
47+
end)
48+
4049
it('should handle simple comments', function ()
4150
assert.same("CommentLine", syntax:parse("# foo")[1][1].id)
4251
assert.same("CommentLine", syntax:parse("## foo")[1][1].id)

0 commit comments

Comments
 (0)