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