diff --git a/spec/pragma/invalid_spec.lua b/spec/pragma/invalid_spec.lua index 105770481..e6dadeff2 100644 --- a/spec/pragma/invalid_spec.lua +++ b/spec/pragma/invalid_spec.lua @@ -1,17 +1,21 @@ local util = require("spec.util") describe("invalid pragma", function() - it("rejects invalid pragma", util.check_syntax_error([[ - --#invalid_pragma on + it("ignores other --# lines", util.check([[ + --#invalid on + ]])) + + it("rejects invalid pragma", util.check_type_error([[ + --#pragma invalid_foo on ]], { - { y = 1, msg = "invalid token '--#invalid_pragma'" } + { y = 1, msg = "invalid pragma: invalid_foo" } })) it("pragmas currently do not accept punctuation", util.check_syntax_error([[ --#pragma something(other) ]], { - { y = 1, msg = "invalid token '('" }, - { y = 1, msg = "invalid token ')'" }, + { y = 1, x = 26, msg = "invalid token '('" }, + { y = 1, x = 32, msg = "invalid token ')'" }, })) it("pragma arguments need to be in a single line", util.check_syntax_error([[ diff --git a/tl.lua b/tl.lua index 60d0fda18..b9b628483 100644 --- a/tl.lua +++ b/tl.lua @@ -879,7 +879,7 @@ do ["number hexfloat"] = "number", ["number power"] = "number", ["number powersign"] = "$ERR invalid_number$", - ["pragma"] = "pragma", + ["pragma"] = nil, ["pragma any"] = nil, ["pragma word"] = "pragma_identifier", } @@ -1285,11 +1285,15 @@ do elseif state == "pragma" then if not lex_word[c] then end_token_prev("pragma") - if tokens[nt].tk ~= "--#pragma" then - add_syntax_error() + if tokens[nt].tk == "--#pragma" then + state = "pragma any" + else + state = "comment short" + table.remove(tokens) + nt = nt - 1 + drop_token() end fwd = false - state = "pragma any" end elseif state == "pragma any" then if c == "\n" then diff --git a/tl.tl b/tl.tl index 5462194a1..7ee6d1f82 100644 --- a/tl.tl +++ b/tl.tl @@ -879,7 +879,7 @@ do ["number hexfloat"] = "number", ["number power"] = "number", ["number powersign"] = "$ERR invalid_number$", - ["pragma"] = "pragma", + ["pragma"] = nil, -- drop comment ["pragma any"] = nil, -- never in a token ["pragma word"] = "pragma_identifier", -- never in a token } @@ -1285,11 +1285,15 @@ do elseif state == "pragma" then if not lex_word[c] then end_token_prev("pragma") - if tokens[nt].tk ~= "--#pragma" then - add_syntax_error() + if tokens[nt].tk == "--#pragma" then + state = "pragma any" + else + state = "comment short" + table.remove(tokens) + nt = nt - 1 + drop_token() end fwd = false - state = "pragma any" end elseif state == "pragma any" then if c == "\n" then