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