aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2020-10-01 11:47:46 +0200
committerOmar Polo <op@omarpolo.com>2020-10-01 11:52:58 +0200
commit7d3286caede96d7b813eff7dc3691d683d0f9bf9 (patch)
tree617ed265767606edba64468a5b08b10a8093a827
parente0041ee5139dcd4173fe8f47ff691c0d41951341 (diff)
downloadstar-platinum-7d3286caede96d7b813eff7dc3691d683d0f9bf9.tar.gz
star-platinum-7d3286caede96d7b813eff7dc3691d683d0f9bf9.tar.bz2
reworked the tokenizer -- breaking change
The parser was pratically rewritten. Strings now are required to be quoted with single quotes, while keys (still) requires double quotes. In addition, the * is no longer a valid match argument: to match on everything you need to use the special keyword `all'. match all # before was `match *' on "C-a" do "<Home>" # unchanged match class 'Firefox' # before was `match class Firefox' # ...
-rw-r--r--lex.l117
-rw-r--r--parse.y4
2 files changed, 61 insertions, 60 deletions
diff --git a/lex.l b/lex.l
index 943a39c..92aadc8 100644
--- a/lex.l
+++ b/lex.l
@@ -1,4 +1,4 @@
-/* -*- mode:fundamental; indent-tabs-mode: t; -*- */
+/* -*- mode:c; indent-tabs-mode: t; -*- */
%{
/*
@@ -34,76 +34,77 @@ KeySym key = 0;
%x COMMENT
%x KEY
+%x STRING
%%
-"#" { BEGIN(COMMENT); }
-<COMMENT>\n { yylineno++; BEGIN(INITIAL); }
-<COMMENT>. ;
-
-[ \t\r\v\f]+ ;
-
-"match" return TMATCH;
-"class" return TCLASS;
-"on" return TON;
-"do" return TDO;
-"toggle" return TTOGGLE;
-"activate" return TACTIVATE;
-"deactivate" return TDEACTIVATE;
-"ignore" return TIGNORE;
-
-"\n" yylineno++; return '\n';
-"*" return '*';
-
-[-a-zA-Z0-9]+ {
- char *ident;
- if ((ident = strdup(yytext)) == NULL)
- err(1, "strdup");
- yylval.str = ident;
- return TSTRING;
- }
-
-"\"" { BEGIN(KEY); }
-<KEY>"\"" {
- BEGIN(INITIAL);
-
- yylval.key = (struct key){ state, key };
- state = 0;
- key = 0;
- return TKEY;
- }
-
-<KEY>C- { state |= ControlMask; }
-<KEY>S- { state |= ShiftMask; }
-<KEY>M- { state |= Mod1Mask; }
-<KEY>s- { state |= Mod4Mask; }
+<INITIAL># BEGIN(COMMENT);
+<COMMENT>.*\n yylineno++; BEGIN(INITIAL); return '\n';
+
+<INITIAL>\" BEGIN(KEY);
+<KEY>\" {
+ BEGIN(INITIAL);
+ yylval.key = (struct key){ state, key };
+ state = 0;
+ key = 0;
+ return TKEY;
+ }
+
+<KEY>C- state |= ControlMask;
+<KEY>S- state |= ShiftMask;
+<KEY>M- state |= Mod1Mask;
+<KEY>s- state |= Mod4Mask;
<KEY><[^>]+> {
- char *c;
+ char *c;
- if ((c = strdup(yytext)) == NULL)
- err(1, "strdup");
+ if ((c = strdup(yytext)) == NULL)
+ err(1, "strdup");
- c++; /* skip the < */
- c[strlen(c)-1] = '\0'; /* trim the > */
+ c++; /* skip the < */
+ c[strlen(c)-1] = '\0'; /* trim the > */
- if ((key = XStringToKeysym(c)) == NoSymbol)
- yyerror("invalid keysym %s", c);
+ if ((key = XStringToKeysym(c)) == NoSymbol)
+ yyerror("invalid keysym %s", c);
- free(--c);
- }
+ free(--c);
+ }
-<KEY>SPC { key = XK_space; }
-<KEY>RET { key = XK_Return; }
+<KEY>SPC key = XK_space;
+<KEY>RET key = XK_Return;
-<KEY>"(" { key = XK_parenleft; }
-<KEY>")" { key = XK_parenright; }
+<KEY>"(" key = XK_parenleft;
+<KEY>")" key = XK_parenright;
<KEY>. {
- if ((key = XStringToKeysym(yytext)) == NoSymbol)
- yyerror("invalid key %s", yytext);
- }
-
+ if ((key = XStringToKeysym(yytext)) == NoSymbol)
+ yyerror("invalid key %s", yytext);
+ }
+
+<INITIAL>\' BEGIN(STRING);
+<STRING>[^']*\' {
+ if ((yylval.str = strdup(yytext)) == NULL)
+ err(1, "strdup");
+ yylval.str[strlen(yylval.str)-1] = '\0'; /* remove the closing quote */
+ BEGIN(INITIAL);
+ return TSTRING;
+ }
+
+match return TMATCH;
+class return TCLASS;
+on return TON;
+do return TDO;
+toggle return TTOGGLE;
+activate return TACTIVATE;
+deactivate return TDEACTIVATE;
+ignore return TIGNORE;
+exec return TEXEC;
+all return TALL;
+
+\n yylineno++; return '\n';
+[ \r\t\f]+
+
+. return TERR;
%%
diff --git a/parse.y b/parse.y
index 32657d4..68bb6d1 100644
--- a/parse.y
+++ b/parse.y
@@ -41,7 +41,7 @@
struct group *group;
}
-%token TMATCH TCLASS
+%token TMATCH TCLASS TALL
%token TON TDO
%token TTOGGLE TACTIVATE TDEACTIVATE TIGNORE TEXEC
%token TERR
@@ -69,7 +69,7 @@ matches : /* empty */ { $$ = NULL; }
| matches match '\n' { $2->next = $1; $$ = $2; }
;
-match : TMATCH '*' { $$ = new_match(MANY, NULL); }
+match : TMATCH TALL { $$ = new_match(MANY, NULL); }
| TMATCH TCLASS TSTRING { $$ = new_match(MCLASS, $3); }
;