quote spaces in tokens passed to gst_parse_launchv. this restores the old (shell...
[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 _char ([^[:space:]])|("\\".)
29 _string {_char}+|("\""([^\"]|"\\\"")*"\"")
30
31 %x value
32 %option noyywrap
33 %%
34
35 <value>{
36     {_integer} {
37         PRINT ("An integer: %s (%d)\n", yytext,
38                atoi (yytext));
39         lvalp->v = g_new0 (GValue, 1);
40         g_value_init (lvalp->v, G_TYPE_INT);
41         g_value_set_int (lvalp->v, atoi (yytext));
42         BEGIN (INITIAL);
43         return VALUE;
44     }
45     
46     {_double}   {
47         PRINT ("A double: %s (%g)\n", yytext, atof (yytext));
48         lvalp->v = g_new0 (GValue, 1);
49         g_value_init (lvalp->v, G_TYPE_DOUBLE);
50         g_value_set_double (lvalp->v, atof (yytext));
51         BEGIN (INITIAL);
52         return VALUE;
53     }
54     
55     {_boolean} {
56         PRINT ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0);
57         lvalp->v = g_new0 (GValue, 1);
58         g_value_init (lvalp->v, G_TYPE_BOOLEAN);
59         g_value_set_boolean (lvalp->v, tolower (*yytext) == 't' ? TRUE : FALSE);
60         BEGIN (INITIAL);
61         return VALUE;
62     }
63     
64     {_string} {
65         if (*yytext == '"') {
66             yytext++;
67             *(yytext + strlen (yytext) - 1) = '\0';
68         }
69         _gst_parse_unescape (yytext);
70         PRINT ("A string: \"%s\"\n", yytext);
71         lvalp->v = g_new0 (GValue, 1);
72         g_value_init (lvalp->v, G_TYPE_STRING);
73         g_value_set_string (lvalp->v, yytext);
74         BEGIN (INITIAL);
75         return VALUE;
76     }
77     
78     [[:space:]]+ { /* PRINT ("space: [%s]\n", yytext); */ }
79     
80     . {
81         PRINT ("unknown: %s\n", yytext);
82         return *yytext;
83     }
84 }
85
86 {_lconnection} {
87     gchar *d1, *q;
88     lvalp->c = g_new0 (connection_t, 1);
89     PRINT ("An connection: %s\n", yytext);
90     q = strchr (yytext, '!');
91     d1 = strchr (yytext, '.');
92     if (d1) {
93         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
94         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
95     } else {
96         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
97     }
98     
99     return CONNECTION;
100 }
101
102 {_rconnection} {
103     gchar *d2;
104     lvalp->c = g_new0 (connection_t, 1);
105     PRINT ("An rconnection: %s\n", yytext);
106     d2 = strchr (yytext, '.');
107     if (d2) {
108         lvalp->c->sink_name = g_strndup (yytext + 1, d2 - yytext - 1);
109         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
110     } else {
111         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (yytext + 1));
112     }
113
114     return CONNECTION;
115 }
116
117 {_bconnection} {
118     gchar *d1, *d2, *q;
119     lvalp->c = g_new0 (connection_t, 1);
120     PRINT ("A bconnection: %s\n", yytext);
121     q = strchr (yytext, '!');
122     d1 = strchr (yytext, '.');
123     d2 = strchr (q, '.');
124     if (d1 && d1 < q) {
125         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
126         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
127     } else {
128         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
129     }
130     
131     if (d2) {
132         lvalp->c->sink_name = g_strndup (q + 1, d2 - q - 1);
133         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
134     } else {
135         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (q + 1));
136     }
137
138     return BCONNECTION;
139 }
140
141 {_identifier} {
142     PRINT ("An identifier: %s\n", yytext);
143     lvalp->s = g_strdup (yytext);
144     return IDENTIFIER;
145 }
146
147 "=" { BEGIN (value); CHAR ('='); }
148 "@" { CHAR ('@'); }
149 "." { CHAR ('.'); }
150 "," { CHAR (','); }
151 "{" { CHAR ('{'); }
152 "}" { CHAR ('}'); }
153 "[" { CHAR ('['); }
154 "]" { CHAR (']'); }
155 "(" { CHAR ('('); }
156 ")" { CHAR (')'); }
157 "!" { CHAR ('!'); }
158 "+" { CHAR ('+'); }
159
160 [[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
161
162 . {
163     printf ("unknown: %s\n", yytext);
164     return *yytext;
165 }
166
167 %%