Makes the lexical errors a little bit more verbose

This commit is contained in:
Felipe Zimmerle 2017-01-10 19:38:39 -03:00 committed by Felipe Zimmerle
parent 5880524db6
commit a6f07f621d
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
4 changed files with 23 additions and 8 deletions

View File

@ -255,7 +255,19 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+
NEW_LINE [\n\r]+ NEW_LINE [\n\r]+
%x TRANSACTION_TO_VARIABLE EXPECTING_VARIABLE TRANSACTION_FROM_VARIABLE_TO_OPERATOR EXPECTING_OPERATOR COMMENT EXPECTING_PARAMETER EXPECTING_ACTIONS TRANSACTION_FROM_OPERATOR_TO_ACTIONS TRANSACTION_FROM_DIRECTIVE_TO_ACTIONS NO_OP_INFORMED FINISH_ACTIONS %x TRANSACTION_TO_VARIABLE
%x EXPECTING_VARIABLE
%x TRANSACTION_FROM_VARIABLE_TO_OPERATOR
%x EXPECTING_OPERATOR
%x COMMENT
%x EXPECTING_PARAMETER
%x EXPECTING_ACTIONS
%x TRANSACTION_FROM_OPERATOR_TO_ACTIONS
%x TRANSACTION_FROM_DIRECTIVE_TO_ACTIONS
%x NO_OP_INFORMED
%x FINISH_ACTIONS
%x LEXING_ERROR
%x LEXING_ERROR_ACTION
%{ %{
// Code run each time a pattern is matched. // Code run each time a pattern is matched.
@ -386,9 +398,10 @@ NEW_LINE [\n\r]+
\"[ \t]*\n { BEGIN(INITIAL); yyless(1); } \"[ \t]*\n { BEGIN(INITIAL); yyless(1); }
\"[ \t]*\r\n { BEGIN(INITIAL); driver.loc.back()->lines(1); driver.loc.back()->step(); } \"[ \t]*\r\n { BEGIN(INITIAL); driver.loc.back()->lines(1); driver.loc.back()->step(); }
. { driver.error (*driver.loc.back(), "invalid character", yytext); throw p::syntax_error(*driver.loc.back(), ""); } . { BEGIN(LEXING_ERROR_ACTION); yyless(0); }
} }
<FINISH_ACTIONS>{ <FINISH_ACTIONS>{
<<EOF>> { BEGIN(INITIAL); yyless(0); p::make_NEW_LINE(*driver.loc.back()); } <<EOF>> { BEGIN(INITIAL); yyless(0); p::make_NEW_LINE(*driver.loc.back()); }
. { BEGIN(INITIAL); } . { BEGIN(INITIAL); }
@ -603,8 +616,10 @@ NEW_LINE [\n\r]+
. { driver.error (*driver.loc.back(), "invalid character", yytext); throw p::syntax_error(*driver.loc.back(), ""); } . { BEGIN(LEXING_ERROR); yyless(0); }
<LEXING_ERROR>.+ { driver.error (*driver.loc.back(), "Invalid input: ", yytext); throw p::syntax_error(*driver.loc.back(), ""); }
<LEXING_ERROR_ACTION>.+ { driver.error (*driver.loc.back(), "Invalid action: ", yytext); throw p::syntax_error(*driver.loc.back(), ""); }
<<EOF>> { <<EOF>> {

View File

@ -80,7 +80,7 @@
] ]
}, },
"expected":{ "expected":{
"parser_error": "File: action-id.json. Line: 2. Column: 30. invalid character i" "parser_error": "File: action-id.json. Line: 2. Column: 56. Invalid action: id:-1,phase:2,pass,t:trim\""
}, },
"rules":[ "rules":[
"SecRuleEngine On", "SecRuleEngine On",
@ -212,7 +212,7 @@
] ]
}, },
"expected":{ "expected":{
"parser_error": "action-id.json. Line: 2. Column: 30. invalid character i" "parser_error": "action-id.json. Line: 2. Column: 56. Invalid action: id:'1,phase:2,pass,t:trim\""
}, },
"rules":[ "rules":[
"SecRuleEngine On", "SecRuleEngine On",
@ -256,7 +256,7 @@
] ]
}, },
"expected":{ "expected":{
"parser_error": "action-id.json. Line: 2. Column: 34. invalid character '" "parser_error": "action-id.json. Line: 2. Column: 56. Invalid action: ',phase:2,pass,t:trim\""
}, },
"rules":[ "rules":[
"SecRuleEngine On", "SecRuleEngine On",

View File

@ -38,7 +38,7 @@
"version_min":300000, "version_min":300000,
"title":"Testing skip action 2/3", "title":"Testing skip action 2/3",
"expected":{ "expected":{
"parser_error": "Rules error. File: action-skip.json. Line: 2. Column: 62. invalid character s" "parser_error": "Rules error. File: action-skip.json. Line: 2. Column: 71. Invalid action: skip:abc"
}, },
"client":{ "client":{
"ip":"200.249.12.31", "ip":"200.249.12.31",

View File

@ -4,7 +4,7 @@
"version_min":300000, "version_min":300000,
"title":"Include - bad rule", "title":"Include - bad rule",
"expected":{ "expected":{
"parser_error": "Rules error. File: test-cases/data/config_example3.txt. Line: 2. Column: 41. invalid character o" "parser_error": "Rules error. File: test-cases/data/config_example3.txt. Line: 2. Column: 66. Invalid action: ops \"id:1000,pass,t:trim\""
}, },
"rules":[ "rules":[
"SecRuleEngine On", "SecRuleEngine On",