gst/parse/grammar.y: fix assert to not trigger when there's no error argument
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <string.h>
4
5 #include "../gst_private.h"
6
7 #include "types.h"
8 #include "../gstinfo.h"
9 #include "../gsturi.h"
10 #include "grammar.tab.h"
11
12 #ifdef G_HAVE_ISO_VARARGS
13 #define PRINT(...) GST_CAT_DEBUG (GST_CAT_PIPELINE, "flex: " __VA_ARGS__)
14 #elif defined(G_HAVE_GNUC_VARARGS)
15 #define PRINT(args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, "flex: " args)
16 #else
17 #define PRINT(args...)
18 #endif
19
20 #define YY_DECL int _gst_parse_yylex (YYSTYPE *lvalp)
21 %}
22
23 _operator [(){}.:!,;=]
24 _identifier [[:alpha:]][[:alnum:]\-_%]*
25
26 _char ("\\".)|([^[:space:]])
27 _string {_char}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
28
29 _comma [[:space:]]*","[[:space:]]*
30 _assign [[:space:]]*"="[[:space:]]*
31
32 _protocol [[:alpha:]][[:alnum:]+-\.]*
33 _url {_protocol}"://"{_string}|["."{_identifier}]?"/"{_string}
34
35 /* we must do this here, because nearly everything matches a {_string} */ 
36 _assignment {_identifier}{_assign}{_string}
37
38 /* get pad/element references and stuff with dots right */
39 _padref "."{_identifier}
40 _ref {_identifier}"."{_identifier}?
41 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
42
43 /* links */
44 _mimechar ([[:alnum:]-])
45 _mimetype ({_mimechar}+"/"{_mimechar}+)|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
46 _capschar ("\\".)|([^\;!])
47 _capsstring {_capschar}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
48 _caps {_mimetype}(","[^!]|{_capsstring})*
49 _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)*"!")|("!")
50
51 %x value
52 %option noyywrap
53 %option nounput
54 %%
55
56 {_assignment} {
57     /* "=" */
58     PRINT ("ASSIGNMENT: %s", yytext);
59     lvalp->s = gst_parse_strdup (yytext);
60     BEGIN (INITIAL);
61     return ASSIGNMENT;
62 }
63
64 {_padref} {
65     yytext++;
66     PRINT ("PADREF: %s", yytext);
67     lvalp->s = gst_parse_strdup (yytext);
68     BEGIN (INITIAL);
69     return PADREF;
70 }
71
72 {_ref} {
73     PRINT ("REF: %s", yytext);
74     lvalp->s = gst_parse_strdup (yytext);
75     BEGIN (INITIAL);
76     return REF;
77 }
78
79 {_binref} {
80     gchar *pos = yytext;
81     while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
82     *pos = '\0';
83     PRINT ("BINREF: %s", yytext);
84     lvalp->s = gst_parse_strdup (yytext);
85     BEGIN (INITIAL);
86     return BINREF;
87 }
88
89 {_identifier} {
90     PRINT ("IDENTIFIER: %s", yytext);
91     lvalp->s = gst_parse_strdup (yytext);
92     BEGIN (INITIAL);
93     return IDENTIFIER;
94 }
95
96 {_link} {
97     gchar *c = yytext;
98     PRINT ("LINK: %s", yytext);
99     c++;
100     if (*c) {
101       while (g_ascii_isspace (*c)) c++;
102       c = lvalp->s = gst_parse_strdup (c);
103       while (*c) c++;
104       g_assert (*--c == '!');
105       while (g_ascii_isspace (*--c));
106       *++c = '\0';
107     } else {
108       lvalp->s = NULL;
109     }
110     BEGIN (INITIAL);
111     return LINK;
112 }
113 {_url} {
114   PRINT ("URL: %s", yytext);
115   if (gst_uri_is_valid (yytext)) {
116     lvalp->s = g_strdup (yytext);
117   } else {
118     lvalp->s = gst_uri_construct ("file", yytext);
119   }
120   gst_parse_unescape (lvalp->s);
121   BEGIN (INITIAL);
122   return PARSE_URL;
123 }
124
125 {_operator} { PRINT ("OPERATOR: [%s]", yytext); return *yytext; }
126
127 [[:space:]]+ { PRINT ("SPACE: [%s]", yytext); }
128
129 . {
130     printf ("???: %s\n", yytext);
131     return *yytext;
132 }
133
134 %%