compiler: don't fail on empty lines

This commit is contained in:
Henri DF 2016-02-22 10:45:20 -08:00
parent 7853260f38
commit 05362e2c68
2 changed files with 11 additions and 2 deletions

View File

@ -166,7 +166,7 @@ end
local G = { local G = {
V"Start", -- Entry rule V"Start", -- Entry rule
Start = V"Skip" * (V"MacroDef" / macro + V"Filter" / filter) * -1 + report_error(); Start = V"Skip" * (V"MacroDef" / macro + V"Filter" / filter)^-1 * -1 + report_error();
-- Grammar -- Grammar
Filter = V"OrExpression"; Filter = V"OrExpression";
@ -466,6 +466,14 @@ function compiler.compile_line(line, state)
error(error_msg) error(error_msg)
end end
if (type(ast) == "number") then
-- hack: we get a number (# of matched chars) V"Skip" back if this line
-- only contained whitespace. (According to docs 'v"Skip" / 0' in Start
-- rule should not capture anything but it doesn't seem to work that
-- way...)
return {}
end
local macros = get_macros(ast.value, {}) local macros = get_macros(ast.value, {})
for m, _ in pairs(macros) do for m, _ in pairs(macros) do
if state.macros[m] == nil then if state.macros[m] == nil then

View File

@ -24,7 +24,8 @@ function bad
} }
# Filters # Filters
good "a" good " "
good " a"
good "a and b" good "a and b"
good "(a)" good "(a)"
good "(a and b)" good "(a and b)"