gst/parse/parse.l: Attempt to solve bug #172815.
[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 #define YY_DECL int _gst_parse_yylex (YYSTYPE *lvalp)
36 %}
37
38 _operator [(){}.!,;=]
39 _identifier [[:alpha:]][[:alnum:]\-_%:]*
40
41 _char ("\\".)|([^[:space:]])
42 _string {_char}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
43
44 _comma [[:space:]]*","[[:space:]]*
45 _assign [[:space:]]*"="[[:space:]]*
46
47 _protocol [[:alpha:]][[:alnum:]+-\.]*
48 _url ({_protocol}"://"{_string}|["."{_identifier}]?"/"{_string})|({_protocol}"://")
49
50 /* we must do this here, because nearly everything matches a {_string} */ 
51 _assignment {_identifier}{_assign}{_string}
52
53 /* get pad/element references and stuff with dots right */
54 _padref "."{_identifier}
55 _ref {_identifier}"."{_identifier}?
56 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
57
58 /* links */
59 _mimechar ([[:alnum:]-])
60 _mimetype ({_mimechar}+"/"{_mimechar}+)|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
61 _capschar ("\\".)|([^\;!])
62 _capsstring {_capschar}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
63 _caps {_mimetype}(","[^!]|{_capsstring})*
64 _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)*"!")|("!")
65
66 %x value
67 %option noyywrap
68 %option nounput
69 %%
70
71 {_assignment} {
72     /* "=" */
73     PRINT ("ASSIGNMENT: %s", yytext);
74     lvalp->s = gst_parse_strdup (yytext);
75     BEGIN (INITIAL);
76     return ASSIGNMENT;
77 }
78
79 {_padref} {
80     yytext++;
81     PRINT ("PADREF: %s", yytext);
82     lvalp->s = gst_parse_strdup (yytext);
83     BEGIN (INITIAL);
84     return PADREF;
85 }
86
87 {_ref} {
88     PRINT ("REF: %s", yytext);
89     lvalp->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     lvalp->s = gst_parse_strdup (yytext);
100     BEGIN (INITIAL);
101     return BINREF;
102 }
103
104 {_identifier} {
105     PRINT ("IDENTIFIER: %s", yytext);
106     lvalp->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 = lvalp->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       lvalp->s = NULL;
125     }
126     BEGIN (INITIAL);
127     return LINK;
128 }
129 {_url} {
130   PRINT ("URL: %s", yytext);
131   if (gst_uri_is_valid (yytext)) {
132     lvalp->s = g_strdup (yytext);
133   } else {
134     lvalp->s = gst_uri_construct ("file", yytext);
135   }
136   gst_parse_unescape (lvalp->s);
137   BEGIN (INITIAL);
138   return PARSE_URL;
139 }
140
141 {_operator} { PRINT ("OPERATOR: [%s]", yytext); return *yytext; }
142
143 [[:space:]]+ { PRINT ("SPACE: [%s]", yytext); }
144
145 . {
146     printf ("???: %s\n", yytext);
147     return *yytext;
148 }
149
150 %%