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