allow colons in indentifier names (for jack: " ... !alsa_pcm:out_1 jacksink")
[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 {_lconnection} {
82     gchar *d1, *q;
83     lvalp->c = g_new0 (connection_t, 1);
84     PRINT ("An connection: %s\n", yytext);
85     q = strchr (yytext, '!');
86     d1 = strchr (yytext, '.');
87     if (d1) {
88         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
89         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
90     } else {
91         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
92     }
93     
94     return CONNECTION;
95 }
96
97 {_rconnection} {
98     gchar *d2;
99     lvalp->c = g_new0 (connection_t, 1);
100     PRINT ("An rconnection: %s\n", yytext);
101     d2 = strchr (yytext, '.');
102     if (d2) {
103         lvalp->c->sink_name = g_strndup (yytext + 1, d2 - yytext - 1);
104         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
105     } else {
106         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (yytext + 1));
107     }
108
109     return CONNECTION;
110 }
111
112 {_bconnection} {
113     gchar *d1, *d2, *q;
114     lvalp->c = g_new0 (connection_t, 1);
115     PRINT ("A bconnection: %s\n", yytext);
116     q = strchr (yytext, '!');
117     d1 = strchr (yytext, '.');
118     d2 = strchr (q, '.');
119     if (d1 && d1 < q) {
120         lvalp->c->src_name = g_strndup (yytext, d1 - yytext);
121         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q - d1 - 1));
122     } else {
123         lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q - yytext));
124     }
125     
126     if (d2) {
127         lvalp->c->sink_name = g_strndup (q + 1, d2 - q - 1);
128         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1));
129     } else {
130         lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (q + 1));
131     }
132
133     return BCONNECTION;
134 }
135
136 {_identifier} {
137     PRINT ("An identifier: %s\n", yytext);
138     lvalp->s = g_strdup (yytext);
139     return IDENTIFIER;
140 }
141
142 "=" { BEGIN (value); CHAR ('='); }
143 "@" { CHAR ('@'); }
144 "." { CHAR ('.'); }
145 "," { CHAR (','); }
146 "{" { CHAR ('{'); }
147 "}" { CHAR ('}'); }
148 "[" { CHAR ('['); }
149 "]" { CHAR (']'); }
150 "(" { CHAR ('('); }
151 ")" { CHAR (')'); }
152 "!" { CHAR ('!'); }
153 "+" { CHAR ('+'); }
154
155 [[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
156
157 . {
158     printf ("unknown: %s\n", yytext);
159     return *yytext;
160 }
161
162 %%