Debian Codegraph @

gst/parse/parse.l

raw
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 _preset @preset{_assign}{_string}
68
69 /* get pad/element references and stuff with dots right */
70 _padref "."{_identifier}
71 _ref {_identifier}"."{_identifier}?
72 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
73
74 /* links */
75 _mimechar [[:alnum:]-]
76 _mimetype {_mimechar}+"/"{_mimechar}+
77 _capschar ("\\".)|([^\;!])
78 _capsstring {_capschar}+
79 _caps {_mimetype}(","[^!]|{_capsstring})*
80 _link ([!:][[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)*[!:])|([!:])
81
82 %x value
83 %option noyywrap
84 %option nounput
85 %option reentrant
86 %option bison-bridge
87 %option never-interactive
88 %option noinput
89 %%
90
91 {_assignment} {
92 /* "=" */
93 PRINT ("ASSIGNMENT: %s", yytext);
94 yylval->ss = gst_parse_strdup (yytext);
95 BEGIN (INITIAL);
96 return ASSIGNMENT;
97 }
98
99 {_preset} {
100 gchar *pos = yytext;
101 while (*pos && (*pos != '=')) pos++;
102 while (*pos && g_ascii_isspace (*pos)) pos++;
103 PRINT ("PRESET: %s", &pos[1]);
104 yylval->ss = gst_parse_strdup (&pos[1]);
105 BEGIN (INITIAL);
106 return PRESET;
107 }
108
109 {_padref} {
110 yytext++;
111 PRINT ("PADREF: %s", yytext);
112 yylval->ss = gst_parse_strdup (yytext);
113 BEGIN (INITIAL);
114 return PADREF;
115 }
116
117 {_ref} {
118 PRINT ("REF: %s", yytext);
119 yylval->ss = gst_parse_strdup (yytext);
120 BEGIN (INITIAL);
121 return REF;
122 }
123
124 {_binref} {
125 gchar *pos = yytext;
126 while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
127 *pos = '\0';
128 PRINT ("BINREF: %s", yytext);
129 yylval->ss = gst_parse_strdup (yytext);
130 BEGIN (INITIAL);
131 return BINREF;
132 }
133
134 {_identifier} {
135 PRINT ("IDENTIFIER: %s", yytext);
136 yylval->ss = gst_parse_strdup (yytext);
137 BEGIN (INITIAL);
138 return IDENTIFIER;
139 }
140
141 {_link} {
142 gchar *c = yytext;
143 gchar op;
144 gboolean link_all;
145
146 PRINT ("LINK: %s", yytext);
147 /* First char is a link operator */
148 link_all = (*c == ':');
149 c++;
150 if (*c) {
151 while (g_ascii_isspace (*c)) c++;
152 c = yylval->ss = gst_parse_strdup (c);
153 while (*c) c++;
154 /* Last non-space char is a link operator */
155 op = *--c;
156 if (op != '!' && op != ':')
157 g_assert_not_reached ();
158 if (op == ':')
159 link_all = TRUE;
160
161 /* Walk backward past whitespaces - what remains
162 * is a filter caps string, or empty */
163 while (g_ascii_isspace (*--c));
164 *++c = '\0';
165 } else {
166 yylval->ss = NULL;
167 }
168 BEGIN (INITIAL);
169 return link_all ? LINK_ALL : LINK;
170 }
171 {_url} {
172 PRINT ("URL: %s", yytext);
173 yylval->ss = g_strdup (yytext);
174 gst_parse_unescape (yylval->ss);
175 BEGIN (INITIAL);
176 return PARSE_URL;
177 }
178
179 {_operator} { PRINT ("OPERATOR: [%s]", yytext); return *yytext; }
180
181 [[:space:]]+ { PRINT ("SPACE: [%s]", yytext); }
182
183 . {
184 PRINT ("Invalid Lexer element: %s\n", yytext);
185 return *yytext;
186 }
187
188 %%