This is filtered caps in 20 lines. Implemented full featured parsing of pipelines...
[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 _link ("!"[[:space:]]*{_mimetype}(","([^!]|{_capsstring})+)?[[:space:]]*"!")|("!")
46
47 %x value
48 %option noyywrap
49 %option nounput
50 %%
51
52 {_assignment} {
53     /* "=" */
54     PRINT ("ASSIGNMENT: %s\n", yytext);
55     lvalp->s = gst_parse_strdup (yytext);
56     BEGIN (INITIAL);
57     return ASSIGNMENT;
58 }
59
60 {_padref} {
61     yytext++;
62     PRINT ("PADREF: %s\n", yytext);
63     lvalp->s = gst_parse_strdup (yytext);
64     BEGIN (INITIAL);
65     return PADREF;
66 }
67
68 {_ref} {
69     PRINT ("REF: %s\n", yytext);
70     lvalp->s = gst_parse_strdup (yytext);
71     BEGIN (INITIAL);
72     return REF;
73 }
74
75 {_binref} {
76     gchar *pos = yytext;
77     while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
78     *pos = '\0';
79     PRINT ("BINREF: %s\n", yytext);
80     lvalp->s = gst_parse_strdup (yytext);
81     BEGIN (INITIAL);
82     return BINREF;
83 }
84
85 {_identifier} {
86     PRINT ("IDENTIFIER: %s\n", yytext);
87     lvalp->s = gst_parse_strdup (yytext);
88     BEGIN (INITIAL);
89     return IDENTIFIER;
90 }
91
92 {_link} {
93     gchar *c = yytext;
94     PRINT ("LINK: %s\n", yytext);
95     c++;
96     if (*c) {
97       while (g_ascii_isspace (*c)) c++;
98       c = lvalp->s = gst_parse_strdup (c);
99       while (*c) c++;
100       g_assert (*--c == '!');
101       while (g_ascii_isspace (*--c));
102       *++c = '\0';
103     } else {
104       lvalp->s = NULL;
105     }
106     BEGIN (INITIAL);
107     return LINK;
108 }
109
110 {_operator} { PRINT ("OPERATOR: [%s]\n", yytext); return *yytext; }
111
112 [[:space:]]+ { PRINT ("SPACE: [%s]\n", yytext); }
113
114 . {
115     printf ("???: %s\n", yytext);
116     return *yytext;
117 }
118
119 %%