]> Dogcows Code - chaz/openbox/blob - obcl/lex.l
add shit that i made in the last week!
[chaz/openbox] / obcl / lex.l
1 %{
2 #include "obcl.h"
3 #include "parse.h"
4 %}
5
6 %option yylineno
7
8 DGT [0-9]
9 ID [a-zA-Z_][a-zA-Z_\.\-0-9]*
10
11
12 /* string bummy */
13 %x str
14 %%
15
16 char str_buf[1024];
17 char *str_buf_ptr;
18 int str_char;
19
20 /* begin a string */
21 [\"\'] {
22 str_buf_ptr = str_buf;
23 str_char = yytext[0];
24 BEGIN(str);
25 }
26
27 /* end a string */
28 <str>[\"\'] {
29 if (yytext[0] == str_char) {
30 BEGIN(INITIAL);
31 *str_buf_ptr = '\0';
32 yylval.string = g_strdup(str_buf);
33 return TOK_STRING;
34 } else {
35 *str_buf_ptr++ = yytext[0];
36 }
37 }
38
39 /* can't have newlines in strings */
40 <str>\n {
41 printf("Error: Unterminated string constant.\n");
42 BEGIN(INITIAL);
43 }
44
45 /* handle \" and \' */
46 <str>"\\"[\"\'] {
47 if (yytext[1] == str_char)
48 *str_buf_ptr++ = yytext[1];
49 else {
50 *str_buf_ptr++ = yytext[0];
51 *str_buf_ptr++ = yytext[1];
52 }
53 }
54
55 /* eat valid string contents */
56 <str>[^\\\n\'\"]+ {
57 char *yptr = yytext;
58 while (*yptr) {
59 *str_buf_ptr++ = *yptr++;
60 }
61 }
62
63 /* numberz */
64 {DGT}+ {
65 yylval.num = atof(yytext);
66 return TOK_NUM;
67 }
68
69 /* real numbers */
70 {DGT}+"."{DGT}* {
71 yylval.num = atof(yytext);
72 return TOK_NUM;
73 }
74
75 /* identifiers -- names without spaces and other crap in them */
76 {ID} {
77 yylval.string = g_strdup(yytext);
78 return TOK_ID;
79 }
80
81 /* skip comments */
82 "#".*\n ;
83 /* skip other whitespace */
84 [ \n\t]+ ;
85 . { return yytext[0]; }
86 %%
This page took 0.034537 seconds and 4 git commands to generate.