From 727b37cc3dfa4b7d8ca4108e7426986cebf6d292 Mon Sep 17 00:00:00 2001 From: Katerina Barone-Adesi Date: Tue, 14 Apr 2015 16:27:35 +0100 Subject: [PATCH] Better errors on unknown possible-keywords As raised in https://github.com/Igalia/pflua/issues/153 This change introduces a clearer and much more verbose error message on similar invalid pflang input. --- src/pf/parse.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pf/parse.lua b/src/pf/parse.lua index c560e9a..2dd9654 100644 --- a/src/pf/parse.lua +++ b/src/pf/parse.lua @@ -275,7 +275,7 @@ local function tokens(str) return true end local function error_str(message, ...) - local location_error_message = "Error: In expression \"%s\"" + local location_error_message = "Pflua parse error: In expression \"%s\"" local start = #location_error_message - 4 local cursor_pos = start + last_pos @@ -838,7 +838,16 @@ local function parse_primitive_or_arithmetic(lexer) -- short for `not host vs and host ace` and which should not be -- confused with `not (host vs or ace)`." For now we punt on this -- part of the grammar. - lexer.error('keyword elision not implemented %s', tok) + local msg = +[[%s is not a recognized keyword. Likely causes: +a) %s is a typo, invalid keyword, or similar error. +b) An attempt to use keyword elision. +Repeating the previous keyword is not implemented. +Instead of elision, explicitly use keywords in each clause: +ie, "host a and host b", not "host a and b".]] + + local err = string.format(msg, tok, tok) + lexer.error(err) end local logical_ops = set('&&', 'and', '||', 'or')