]> icculus.org git repositories - mikachu/openbox.git/blob - util/epist/epist.y
better error reporting. epist now reports the line number and token a parser error...
[mikachu/openbox.git] / util / epist / epist.y
1 %{
2 #ifdef    HAVE_CONFIG_H
3 #  include "../../config.h"
4 #endif // HAVE_CONFIG_H
5
6 #include <stdio.h>
7 #include <string.h>
8 #include "parser.hh"
9     
10 #define YYPARSE_PARAM parser_obj
11 #define YYSTYPE char*
12
13 extern int yylineno;
14 extern char *yytext;
15
16 extern "C" {
17     int yylex();
18     int yywrap() {
19         return 1;
20     }
21 }
22
23 void yyerror(const char *c)
24 {
25     printf("ERROR: %s, on line %d, near %s\n", c, yylineno, yytext);
26 }
27
28 %}
29
30 %token OBRACE EBRACE SEMICOLON DASH NUMBER QUOTES WORD BINDING OPTIONS TRUE FALSE
31 %expect 1
32
33 %%
34
35 commands:
36     | commands command
37     | commands options_block
38     ;
39
40 command:
41     action_command | chain_command
42     ;
43
44 action_command:
45     binding WORD parameter SEMICOLON
46     {
47         ((parser*)parser_obj)->setAction($2);
48         ((parser*)parser_obj)->endAction();
49     }
50     
51     ;
52
53 chain_command:
54     binding obrace commands ebrace
55     {
56         ((parser*)parser_obj)->endChain();
57     }
58     ;
59
60 options_block:
61     options_keyword OBRACE options EBRACE
62     ;
63
64 binding:
65     binding_w_modifier bind_key
66     ;
67
68 obrace:
69     OBRACE { ((parser*)parser_obj)->startChain(); }
70     ;
71
72 ebrace:
73     EBRACE { /* ((parser*)parser_obj)->endChain(); */ }
74     ;
75
76 binding_w_modifier:
77     | BINDING DASH binding_w_modifier { ((parser*)parser_obj)->addModifier($1); }
78     ;
79
80 bind_key:
81     OBRACE       { ((parser*)parser_obj)->setKey($1); }
82     | EBRACE     { ((parser*)parser_obj)->setKey($1); }
83     | DASH       { ((parser*)parser_obj)->setKey($1); }
84     | SEMICOLON  { ((parser*)parser_obj)->setKey($1); }
85     | NUMBER     { ((parser*)parser_obj)->setKey($1); }
86     | WORD       { ((parser*)parser_obj)->setKey($1); }
87     ;
88
89 parameter:
90     | NUMBER      { ((parser*)parser_obj)->setArgumentNum($1); }
91     | DASH NUMBER { ((parser*)parser_obj)->setArgumentNegNum($2); }
92     | QUOTES      { ((parser*)parser_obj)->setArgumentStr($1); }
93     | TRUE        { ((parser*)parser_obj)->setArgumentTrue($1); }
94     | FALSE       { ((parser*)parser_obj)->setArgumentFalse($1); }
95     ;
96
97 options_keyword:
98     OPTIONS
99     ;
100
101 options:
102     | options option
103     ;
104
105 option:
106     WORD parameter SEMICOLON
107     { ((parser*)parser_obj)->setOption($1); }
108     ;
109
110 %%
111