better error reporting. epist now reports the line number and token a parser error occurs at, as well as invalid actions.
This commit is contained in:
parent
37ccfef895
commit
18f704edd0
4 changed files with 49 additions and 17 deletions
|
@ -8,9 +8,11 @@
|
||||||
#include "yacc_parser.hh"
|
#include "yacc_parser.hh"
|
||||||
|
|
||||||
extern YYSTYPE yylval;
|
extern YYSTYPE yylval;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%option yylineno
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
\{ return OBRACE;
|
\{ return OBRACE;
|
||||||
|
@ -27,6 +29,8 @@ Mod3 |
|
||||||
mod3 |
|
mod3 |
|
||||||
Mod4 |
|
Mod4 |
|
||||||
mod4 |
|
mod4 |
|
||||||
|
Mod5 |
|
||||||
|
mod5 |
|
||||||
Control |
|
Control |
|
||||||
control |
|
control |
|
||||||
shift |
|
shift |
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
|
|
||||||
#define YYPARSE_PARAM parser_obj
|
#define YYPARSE_PARAM parser_obj
|
||||||
#define YYSTYPE char*
|
#define YYSTYPE char*
|
||||||
|
|
||||||
|
extern int yylineno;
|
||||||
|
extern char *yytext;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int yylex();
|
int yylex();
|
||||||
int yywrap() {
|
int yywrap() {
|
||||||
|
@ -17,14 +20,15 @@ extern "C" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void yyerror(const char *c) {
|
void yyerror(const char *c)
|
||||||
printf("ERROR: %s\n", c);
|
{
|
||||||
|
printf("ERROR: %s, on line %d, near %s\n", c, yylineno, yytext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token OBRACE EBRACE SEMICOLON DASH NUMBER QUOTES WORD BINDING OPTIONS TRUE FALSE
|
%token OBRACE EBRACE SEMICOLON DASH NUMBER QUOTES WORD BINDING OPTIONS TRUE FALSE
|
||||||
|
%expect 1
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,14 @@ extern "C" {
|
||||||
|
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::cout;
|
||||||
|
|
||||||
parser::parser(keytree *kt, Config *conf)
|
parser::parser(keytree *kt, Config *conf)
|
||||||
: _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
|
: _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
|
||||||
_key(""), _arg("")
|
_key(""), _arg(""), _add(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,39 +122,56 @@ void parser::setAction(string act)
|
||||||
if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
|
if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
|
||||||
_action = actions[i].act;
|
_action = actions[i].act;
|
||||||
found = true;
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found) {
|
||||||
_action = Action::noaction;
|
cout << "ERROR: Invalid action (" << act << "). Binding ignored.\n";
|
||||||
|
_add = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser::addModifier(string mod)
|
void parser::addModifier(string mod)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
string str;
|
const char *str;
|
||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
}
|
}
|
||||||
modifiers[] = {
|
modifiers[] = {
|
||||||
{ "Mod1", Mod1Mask },
|
{ "mod1", Mod1Mask },
|
||||||
{ "Mod2", Mod2Mask },
|
{ "mod2", Mod2Mask },
|
||||||
{ "Mod3", Mod3Mask },
|
{ "mod3", Mod3Mask },
|
||||||
{ "Mod4", Mod4Mask },
|
{ "mod4", Mod4Mask },
|
||||||
{ "Control", ControlMask },
|
{ "mod5", Mod5Mask },
|
||||||
{ "Shift", ShiftMask },
|
{ "control", ControlMask },
|
||||||
|
{ "shift", ShiftMask },
|
||||||
{ "", 0 }
|
{ "", 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; modifiers[i].str != ""; ++i) {
|
for (int i = 0; modifiers[i].str != ""; ++i) {
|
||||||
if (modifiers[i].str == mod)
|
if ( strcasecmp(modifiers[i].str, mod.c_str()) == 0 ) {
|
||||||
_mask |= modifiers[i].mask;
|
_mask |= modifiers[i].mask;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
cout << "ERROR: Invalid modifier (" << mod << "). Binding ignored.\n";
|
||||||
|
_add = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser::endAction()
|
void parser::endAction()
|
||||||
{
|
{
|
||||||
_kt->addAction(_action, _mask, _key, _arg);
|
if (_add)
|
||||||
|
_kt->addAction(_action, _mask, _key, _arg);
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
|
_add = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser::startChain()
|
void parser::startChain()
|
||||||
|
@ -171,6 +190,10 @@ void parser::endChain()
|
||||||
void parser::setChainBinding()
|
void parser::setChainBinding()
|
||||||
{
|
{
|
||||||
if (_mask != 0 && _key != "") {
|
if (_mask != 0 && _key != "") {
|
||||||
|
if (!_add) {
|
||||||
|
cout << "Error: Bad modifier detected on chain's root key.\n";
|
||||||
|
_add = true;
|
||||||
|
}
|
||||||
_kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
|
_kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
Action::ActionType _action;
|
Action::ActionType _action;
|
||||||
std::string _key;
|
std::string _key;
|
||||||
std::string _arg;
|
std::string _arg;
|
||||||
|
bool _add;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__parser_hh
|
#endif //__parser_hh
|
||||||
|
|
Loading…
Reference in a new issue