the parser works properly, but it doesn't do anything yet
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include <glib.h>
6 #include <grammar.tab.h>
7
8 #ifdef DEBUG
9 # define PRINT(a...) printf(##a)
10 #else
11 #define PRINT(a...)
12 #endif
13
14 #define CHAR(x) PRINT ("char: %c\n", *yytext); return *yytext;
15 %}
16
17 _integer [[:digit:]]+
18 _float [[:digit:]]+"."*[[:digit:]]*
19 _number {_integer}|{_float}
20 _boolean "true"|"false"|"TRUE"|"FALSE"
21 _identifier [[:alpha:]][[:alnum:]\-_]*
22 _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
23
24 %x value
25 %option noyywrap
26 %%
27
28 <value>{
29     {_integer} {
30         PRINT ("An integer: %s (%d)\n", yytext,
31                 atoi (yytext));
32         BEGIN (INITIAL);
33         return INTEGER;
34     }
35     
36     {_float}    {
37         PRINT ("A float: %s (%g)\n", yytext, atof (yytext));
38         BEGIN (INITIAL);
39         return FLOAT;
40     }
41     
42     {_boolean} {
43         PRINT ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0);
44         BEGIN (INITIAL);
45         return BOOLEAN;
46     }
47     
48     {_string} {
49         if (*yytext == '"') {
50             yytext++;
51             *(yytext + strlen (yytext) - 1) = '\0';
52         }
53         PRINT ("A string: %s\n", yytext);
54         BEGIN (INITIAL);
55         return STRING;
56     }
57     
58     [[:space:]]+ { /* PRINT ("space: [%s]\n", yytext); */ }
59     
60     . {
61         PRINT ("unknown: %s\n", yytext);
62     }
63 }
64
65 {_identifier} {
66     PRINT ("An identifier: %s\n", yytext);
67     return IDENTIFIER;
68 }
69
70 "=" { BEGIN (value); CHAR ('='); }
71 "@" { CHAR ('@'); }
72 "." { CHAR ('.'); }
73 "," { CHAR (','); }
74 "{" { CHAR ('{'); }
75 "}" { CHAR ('}'); }
76 "[" { CHAR ('['); }
77 "]" { CHAR (']'); }
78 "(" { CHAR ('('); }
79 ")" { CHAR (')'); }
80 "!" { CHAR ('!'); }
81 "+" { CHAR ('+'); }
82
83 [[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
84
85 . {
86     printf ("unknown: %s\n", yytext);
87     return *yytext;
88 }
89
90 %%