Skip to content

Commit cfa3b72

Browse files
committed
Define parser based on EBNF: a Message is...
1 parent e2cfffd commit cfa3b72

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fluent/syntax.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ local ftlparser = epnf.define(function (_ENV)
1010
local blank = (blank_inline + line_end)^1
1111
local digits = R"09"^1
1212
local junk_line = (1-line_end)^0 * line_end
13+
Pattern = P"bar" + P"qiz"
1314
Junk = junk_line * (junk_line - P"#" - P"-" - R("az","AZ"))^0
15+
Attribute = P"yyy"
1416
local comment_char = 1 - line_end
1517
CommentLine = (P"###" + P"##" + P"#") * (" " * comment_char^0)-1 * line_end
1618
Term = P"xxx"
1719
Identifier = R("az", "AZ") * (R("az", "AZ", "09") + P"_" + P"-")^0
18-
Message = V"Identifier" * blank_inline^-1 * P"=" * blank_inline^-1 * P"bar"
20+
Message = V"Identifier" * blank_inline^-1 * P"=" * blank_inline^-1 * ((V"Pattern" * V"Attribute"^0) + V"Attribute"^1)
1921
Entry = (V"Message" * line_end) + (V"Term" * line_end) + V"CommentLine"
2022
Resource = (V"Entry" + blank_block + V"Junk")^0 * EOF"unparsable input"
2123
START("Resource")
2224
end)
2325
-- luacheck: pop
2426

25-
-- TODO: Spec L14-L84, L86-L129
27+
-- TODO: Spec L15-L84, L86-L129
2628

2729
local FluentSyntax = class({
2830
parser = ftlparser,

spec/fluent_syntax_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('fluent.syntax', function ()
3434

3535
it('should handle a simple entry', function ()
3636
assert.equals("Entry", syntax:parse("foo = bar")[1].id)
37-
assert.equals("Entry", syntax:parse("baz = bar")[1].id)
37+
assert.equals("Entry", syntax:parse("baz = qiz")[1].id)
3838
end)
3939

4040
it('should handle simple comments', function ()

0 commit comments

Comments
 (0)