diff --git a/src/bindings/lua/hammer.lua b/src/bindings/lua/hammer.lua index fe0c47fae66933df813221ee867521315e2b9277..8f8ede550f22c21f12742b9f54b7d3a40b658f31 100644 --- a/src/bindings/lua/hammer.lua +++ b/src/bindings/lua/hammer.lua @@ -153,7 +153,7 @@ local function ch(c) if type(c) == "number" then return h.h_ch(c) else - return h.h_ch(c:byte) + return h.h_ch(c:byte()) end end local function ch_range(lower, upper) @@ -161,7 +161,7 @@ local function ch_range(lower, upper) return h.h_ch_range(lower, upper) -- FIXME this is really not thorough type checking else - return h.h_ch_range(lower:byte, upper:byte) + return h.h_ch_range(lower:byte(), upper:byte()) end end local function int_range(parser, lower, upper) @@ -213,7 +213,7 @@ local function action(parser, action, user_data) local cb = ffi.cast("HAction", action) return h.h_action(parser, cb, user_data) end -local function in(charset) +local function in_(charset) return h.h_in(charset, #charset) end local function not_in(charset) @@ -277,10 +277,10 @@ local function attr_bool(parser, predicate, user_data) local cb = ffi.cast("HPredicate", predicate) return h.h_attr_bool(parser, cb, user_data) end -local function and(parser) +local function and_(parser) return h.h_and(parser) end -local function not(parser) +local function not_(parser) return h.h_not(parser) end local function indirect(parser) diff --git a/src/bindings/lua/test.lua b/src/bindings/lua/test.lua index a5ee79773ecb590bc351ce15b817d8810db6ce5d..279d54a574e65220f9ed3a5c5217888326a2a832 100644 --- a/src/bindings/lua/test.lua +++ b/src/bindings/lua/test.lua @@ -42,7 +42,7 @@ describe("Combinator tests", function() it("rejects a char outside the range", function() local ret = parser:parse("d") assert.is_falsy(ret) - ) + end) end) describe("Signed 64-bit int tests", function() @@ -60,7 +60,7 @@ describe("Combinator tests", function() describe("Signed 32-bit int tests", function() local parser = hammer.int32() it("parses a valid 32-bit int", function() - local ret = parser:parse(string.char(\xff, 0xfe, 0x00, 0x00)) + local ret = parser:parse(string.char(0xff, 0xfe, 0x00, 0x00)) assert.are.same(ret.ast.sint, -0x20000) end) it("does not parse an invalid 32-bit int", function() @@ -76,7 +76,7 @@ describe("Combinator tests", function() assert.are.same(ret.ast.sint, -0x200) end) it("does not parse an invalid 16-bit int", function() - local ret = parser:parse((string.char(0xfe)) + local ret = parser:parse(string.char(0xfe)) assert.is_falsy(ret) end) end) @@ -231,7 +231,7 @@ describe("Combinator tests", function() end) describe("Middle-parser tests", function() - local parser = hammer.middle(hammer.ch(" "), hammer.ch("a"), hammer.ch(" ") + local parser = hammer.middle(hammer.ch(" "), hammer.ch("a"), hammer.ch(" ")) it("parses the middle character", function() local ret = parser:parse(" a ") assert.are.same(ret.ast.uint, "a") @@ -285,7 +285,7 @@ describe("Combinator tests", function() end) describe("Character set membership tests", function() - local parser = hammer.in({"a", "b", "c"}) + local parser = hammer.in_({"a", "b", "c"}) it("parses a character that is in the included set", function() local ret = parser:parse("b") assert.are.same(ret.ast.uint, "b") @@ -392,7 +392,7 @@ describe("Combinator tests", function() local parser = hammer.difference(hammer.token("ab"), hammer.ch("a")) it("succeeds when 'ab' matches and its result is longer than the result for 'a'", function() local ret = parser:parse("ab") - assert.are.same(ret.ast., ) + assert.are.same(ret.ast.bytes, "ab") end) it("fails if 'ab' doesn't match", function() local ret = parser:parse("a") @@ -487,7 +487,7 @@ describe("Combinator tests", function() it("parses a string missing one of the optional characters", function() local ret = parser:parse("ad") assert.are.same(ret.ast.seq, {"a", {}, "d"}) - end + end) it("does not parse a string containing a character not among the optional ones", function() local ret = parser:parse("aed") assert.is_falsy(ret) @@ -590,9 +590,9 @@ describe("Combinator tests", function() end) describe("Matching lookahead tests", function() - local parser = hammer.sequence(hammer.and(hammer.ch("0")), hammer.ch("0")) - local parser2 = hammer.sequence(hammer.and(hammer.ch("0")), hammer.ch("1")) - local parser3 = hammer.sequence(hammer.ch("1"), hammer.and(hammer.ch("2"))) + local parser = hammer.sequence(hammer.and_(hammer.ch("0")), hammer.ch("0")) + local parser2 = hammer.sequence(hammer.and_(hammer.ch("0")), hammer.ch("1")) + local parser3 = hammer.sequence(hammer.ch("1"), hammer.and_(hammer.ch("2"))) it("parses successfully when the lookahead matches the next character to parse", function() local ret = parser:parse("0") assert.are.same(ret.ast.seq, {"0"}) @@ -609,7 +609,7 @@ describe("Combinator tests", function() describe("Non-matching lookahead tests", function() local parser = hammer.sequence(hammer.ch("a"), hammer.choice(hammer.ch("+"), hammer.token("++")), hammer.ch("b")) - local parser2 = hammer.sequence(hammer.ch("a"), hammer.choice(hammer.sequence(hammer.ch("+"), hammer.not(hammer.ch("+"))), hammer.token("++")), hammer.ch("b")) + local parser2 = hammer.sequence(hammer.ch("a"), hammer.choice(hammer.sequence(hammer.ch("+"), hammer.not_(hammer.ch("+"))), hammer.token("++")), hammer.ch("b")) it("parses a single plus correctly in the 'choice' example", function() local ret = parser:parse("a+b") assert.are.same(ret.ast.seq, {"a", "+", "b"})