gst/parse/parse.l: Commit patch for parse_launch syntax from #331255. Removes support...
[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 _assign [[:space:]]*"="[[:space:]]*
45
46 _protocol [[:alpha:]][[:alnum:]+-\.]*
47 _url ({_protocol}"://"{_string}|["."{_identifier}]?"/"{_string})|({_protocol}"://")
48
49 /* we must do this here, because nearly everything matches a {_string} */ 
50 _assignment {_identifier}{_assign}{_string}
51
52 /* get pad/element references and stuff with dots right */
53 _padref "."{_identifier}
54 _ref {_identifier}"."{_identifier}?
55 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
56
57 /* links */
58 _mimechar [[:alnum:]-]
59 _mimetype {_mimechar}+"/"{_mimechar}+
60 _capschar ("\\".)|([^\;!])
61 _capsstring {_capschar}+
62 _caps {_mimetype}(","[^!]|{_capsstring})*
63 _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)*"!")|("!")
64
65 %x value
66 %option noyywrap
67 %option nounput
68 %%
69
70 {_assignment} {
71     /* "=" */
72     PRINT ("ASSIGNMENT: %s", yytext);
73     lvalp->s = gst_parse_strdup (yytext);
74     BEGIN (INITIAL);
75     return ASSIGNMENT;
76 }
77
78 {_padref} {
79     yytext++;
80     PRINT ("PADREF: %s", yytext);
81     lvalp->s = gst_parse_strdup (yytext);
82     BEGIN (INITIAL);
83     return PADREF;
84 }
85
86 {_ref} {
87     PRINT ("REF: %s", yytext);
88     lvalp->s = gst_parse_strdup (yytext);
89     BEGIN (INITIAL);
90     return REF;
91 }
92
93 {_binref} {
94     gchar *pos = yytext;
95     while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
96     *pos = '\0';
97     PRINT ("BINREF: %s", yytext);
98     lvalp->s = gst_parse_strdup (yytext);
99     BEGIN (INITIAL);
100     return BINREF;
101 }
102
103 {_identifier} {
104     PRINT ("IDENTIFIER: %s", yytext);
105     lvalp->s = gst_parse_strdup (yytext);
106     BEGIN (INITIAL);
107     return IDENTIFIER;
108 }
109
110 {_link} {
111     gchar *c = yytext;
112     PRINT ("LINK: %s", yytext);
113     c++;
114     if (*c) {
115       while (g_ascii_isspace (*c)) c++;
116       c = lvalp->s = gst_parse_strdup (c);
117       while (*c) c++;
118       if (*--c != '!')
119         g_assert_not_reached ();
120       while (g_ascii_isspace (*--c));
121       *++c = '\0';
122     } else {
123       lvalp->s = NULL;
124     }
125     BEGIN (INITIAL);
126     return LINK;
127 }
128 {_url} {
129   PRINT ("URL: %s", yytext);
130   if (gst_uri_is_valid (yytext)) {
131     lvalp->s = g_strdup (yytext);
132   } else {
133     lvalp->s = gst_uri_construct ("file", yytext);
134   }
135   gst_parse_unescape (lvalp->s);
136   BEGIN (INITIAL);
137   return PARSE_URL;
138 }
139
140 {_operator} { PRINT ("OPERATOR: [%s]", yytext); return *yytext; }
141
142 [[:space:]]+ { PRINT ("SPACE: [%s]", yytext); }
143
144 . {
145     printf ("???: %s\n", yytext);
146     return *yytext;
147 }
148
149 %%