gst/parse/: Make the parser reentrant and recursively callable. This requires flex...
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <string.h>
4
5 #include <glib/gprintf.h>
6
7 #include "../gst_private.h"
8
9 #include "types.h"
10 #include "../gstinfo.h"
11 #include "../gsturi.h"
12 #include "grammar.tab.h"
13
14 /* Override the default ECHO so as to avoid fortify warnings. Ignore the
15    embedded-NUL case for now. We know yytext is NUL-terminated. */
16 #define ECHO g_fprintf(yyout, "%s", yytext)
17
18 #ifdef G_HAVE_ISO_VARARGS
19 #define PRINT(...) GST_CAT_DEBUG (GST_CAT_PIPELINE, "flex: " __VA_ARGS__)
20 #elif defined(G_HAVE_GNUC_VARARGS)
21 #define PRINT(args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, "flex: " args)
22 #else
23 static inline void
24 PRINT (const char *format, ...)
25 {
26   va_list varargs;
27
28   va_start (varargs, format);
29   GST_CAT_LEVEL_LOG_valist (GST_CAT_PIPELINE, GST_LEVEL_DEBUG, NULL,
30     format, varargs);
31   va_end (varargs);
32 }
33 #endif
34
35 %}
36
37 _operator [(){}.!,;=]
38 _identifier [[:alpha:]][[:alnum:]\-_%:]*
39
40 _char ("\\".)|([^[:space:]])
41 _string {_char}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\'")*"'")
42
43 _assign [[:space:]]*"="[[:space:]]*
44
45 _protocol [[:alpha:]][[:alnum:]+-\.]*
46 _url ({_protocol}"://"{_string}|["."{_identifier}]?"/"{_string})|({_protocol}"://")
47
48 /* we must do this here, because nearly everything matches a {_string} */ 
49 _assignment {_identifier}{_assign}{_string}
50
51 /* get pad/element references and stuff with dots right */
52 _padref "."{_identifier}
53 _ref {_identifier}"."{_identifier}?
54 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
55
56 /* links */
57 _mimechar [[:alnum:]-]
58 _mimetype {_mimechar}+"/"{_mimechar}+
59 _capschar ("\\".)|([^\;!])
60 _capsstring {_capschar}+
61 _caps {_mimetype}(","[^!]|{_capsstring})*
62 _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)*"!")|("!")
63
64 %x value
65 %option noyywrap
66 %option nounput
67 %option reentrant
68 %option bison-bridge
69 %%
70
71 {_assignment} {
72     /* "=" */
73     PRINT ("ASSIGNMENT: %s", yytext);
74     yylval->s = gst_parse_strdup (yytext);
75     BEGIN (INITIAL);
76     return ASSIGNMENT;
77 }
78
79 {_padref} {
80     yytext++;
81     PRINT ("PADREF: %s", yytext);
82     yylval->s = gst_parse_strdup (yytext);
83     BEGIN (INITIAL);
84     return PADREF;
85 }
86
87 {_ref} {
88     PRINT ("REF: %s", yytext);
89     yylval->s = gst_parse_strdup (yytext);
90     BEGIN (INITIAL);
91     return REF;
92 }
93
94 {_binref} {
95     gchar *pos = yytext;
96     while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
97     *pos = '\0';
98     PRINT ("BINREF: %s", yytext);
99     yylval->s = gst_parse_strdup (yytext);
100     BEGIN (INITIAL);
101     return BINREF;
102 }
103
104 {_identifier} {
105     PRINT ("IDENTIFIER: %s", yytext);
106     yylval->s = gst_parse_strdup (yytext);
107     BEGIN (INITIAL);
108     return IDENTIFIER;
109 }
110
111 {_link} {
112     gchar *c = yytext;
113     PRINT ("LINK: %s", yytext);
114     c++;
115     if (*c) {
116       while (g_ascii_isspace (*c)) c++;
117       c = yylval->s = gst_parse_strdup (c);
118       while (*c) c++;
119       if (*--c != '!')
120         g_assert_not_reached ();
121       while (g_ascii_isspace (*--c));
122       *++c = '\0';
123     } else {
124       yylval->s = NULL;
125     }
126     BEGIN (INITIAL);
127     return LINK;
128 }
129 {_url} {
130   PRINT ("URL: %s", yytext);
131   yylval->s = g_strdup (yytext);
132   gst_parse_unescape (yylval->s);
133   BEGIN (INITIAL);
134   return PARSE_URL;
135 }
136
137 {_operator} { PRINT ("OPERATOR: [%s]", yytext); return *yytext; }
138
139 [[:space:]]+ { PRINT ("SPACE: [%s]", yytext); }
140
141 . {
142     PRINT ("Invalid Lexer element: %s\n", yytext);
143     return *yytext;
144 }
145
146 %%