new parser that uses flex and bison
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include "types.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 #define YY_DECL int _gst_parse_yylex (YYSTYPE *lvalp)
17 #define YY_NO_UNPUT
18 %}
19
20 _integer [[:digit:]]+
21 _double [[:digit:]]+"."*[[:digit:]]*
22 _number {_integer}|{_double}
23 _boolean "true"|"false"|"TRUE"|"FALSE"
24 _identifier [[:alpha:]][[:alnum:]\-_%]*
25 _lconnection ({_identifier}\.)?{_identifier}!
26 _rconnection !({_identifier}\.)?{_identifier}
27 _bconnection ({_identifier}\.)?{_identifier}!({_identifier}\.)?{_identifier}
28 _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
29
30 %x value
31 %option noyywrap
32 %%
33
34 <value>{
35     {_integer} {
36         PRINT ("An integer: %s (%d)\n", yytext,
37                atoi (yytext));
38         lvalp->v = g_new0 (GValue, 1);
39         g_value_init (lvalp->v, G_TYPE_INT);
40         g_value_set_int (lvalp->v, atoi (yytext));
41         BEGIN (INITIAL);
42         return VALUE;
43     }
44     
45     {_double}   {
46         PRINT ("A double: %s (%g)\n", yytext, atof (yytext));
47         lvalp->v = g_new0 (GValue, 1);
48         g_value_init (lvalp->v, G_TYPE_DOUBLE);
49         g_value_set_double (lvalp->v, atof (yytext));
50         BEGIN (INITIAL);
51         return VALUE;
52     }
53     
54     {_boolean} {
55         PRINT ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0);
56         lvalp->v = g_new0 (GValue, 1);
57         g_value_init (lvalp->v, G_TYPE_BOOLEAN);
58         g_value_set_boolean (lvalp->v, tolower (*yytext) == 't' ? TRUE : FALSE);
59         BEGIN (INITIAL);
60         return VALUE;
61     }
62     
63     {_string} {
64         if (*yytext == '"') {
65             yytext++;
66             *(yytext + strlen (yytext) - 1) = '\0';
67         }
68         PRINT ("A string: \"%s\"\n", yytext);
69         lvalp->v = g_new0 (GValue, 1);
70         g_value_init (lvalp->v, G_TYPE_STRING);
71         g_value_set_string (lvalp->v, yytext);
72         BEGIN (INITIAL);
73         return VALUE;
74     }
75     
76     [[:space:]]+ { /* PRINT ("space: [%s]\n", yytext); */ }
77     
78     . {
79         PRINT ("unknown: %s\n", yytext);
80         return *yytext;
81     }
82 }
83
84 {_lconnection} {
85     gchar *d1, *q;
86     lvalp->c = g_new0 (connection_t, 1);
87     PRINT ("An connection: %s\n", yytext);
88     q = strchr (yytext, '!');
89     d1 = strchr (yytext, '.');
90     if (d1) {
91         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
92         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
93     } else {
94         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
95     }
96     
97     return CONNECTION;
98 }
99
100 {_rconnection} {
101     gchar *d2;
102     lvalp->c = g_new0 (connection_t, 1);
103     PRINT ("An rconnection: %s\n", yytext);
104     d2 = strchr (yytext, '.');
105     if (d2) {
106         lvalp->c->sink_name = g_strndup (yytext + 1, d2 - yytext - 1);
107         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
108     } else {
109         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (yytext + 1));
110     }
111
112     return CONNECTION;
113 }
114
115 {_bconnection} {
116     gchar *d1, *d2, *q;
117     lvalp->c = g_new0 (connection_t, 1);
118     PRINT ("A bconnection: %s\n", yytext);
119     q = strchr (yytext, '!');
120     d1 = strchr (yytext, '.');
121     d2 = strchr (q, '.');
122     if (d1 && d1 < q) {
123         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
124         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
125     } else {
126         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
127     }
128     
129     if (d2) {
130         lvalp->c->sink_name = g_strndup (q + 1, d2 - q - 1);
131         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
132     } else {
133         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (q + 1));
134     }
135
136     return BCONNECTION;
137 }
138
139 {_identifier} {
140     PRINT ("An identifier: %s\n", yytext);
141     lvalp->s = g_strdup (yytext);
142     return IDENTIFIER;
143 }
144
145 "=" { BEGIN (value); CHAR ('='); }
146 "@" { CHAR ('@'); }
147 "." { CHAR ('.'); }
148 "," { CHAR (','); }
149 "{" { CHAR ('{'); }
150 "}" { CHAR ('}'); }
151 "[" { CHAR ('['); }
152 "]" { CHAR (']'); }
153 "(" { CHAR ('('); }
154 ")" { CHAR (')'); }
155 "!" { CHAR ('!'); }
156 "+" { CHAR ('+'); }
157
158 [[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
159
160 . {
161     printf ("unknown: %s\n", yytext);
162     return *yytext;
163 }
164
165 %%