implement URI schemes
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <ctype.h>
4 #include <string.h>
5
6 #include "../gst_private.h"
7
8 #include "types.h"
9 #include "../gstinfo.h"
10 #include "../gsturi.h"
11 #include "grammar.tab.h"
12
13 #ifdef G_HAVE_ISO_VARARGS
14 #define PRINT(...) GST_CAT_DEBUG (GST_CAT_PIPELINE, "flex: "__VA_ARGS__)
15 #elif defined(G_HAVE_GNUC_VARARGS)
16 #define PRINT(args...) GST_CAT_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 _protocol [[:alpha:]][[:alnum:]+-\.]*
34 _url {_protocol}"://"{_string}|["."{_identifier}]?"/"{_string}
35
36 /* we must do this here, because nearly everything matches a {_string} */ 
37 _assignment {_identifier}{_assign}{_string}
38
39 /* get pad/element references and stuff with dots right */
40 _padref "."{_identifier}
41 _ref {_identifier}"."{_identifier}?
42 _binref {_identifier}[[:space:]]*"."[[:space:]]*"("
43
44 /* links */
45 _capschar ("\\".)|([^[:space:]\;!\.\,\(\)\]\[])
46 _capsstring {_capschar}+|("\""([^\"]|"\\\"")*"\"")|("'"([^']|"\\\"")*"'")
47 _mimetype ({_capschar}+"/"{_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\n", yytext);
59     lvalp->s = gst_parse_strdup (yytext);
60     BEGIN (INITIAL);
61     return ASSIGNMENT;
62 }
63
64 {_padref} {
65     yytext++;
66     PRINT ("PADREF: %s\n", yytext);
67     lvalp->s = gst_parse_strdup (yytext);
68     BEGIN (INITIAL);
69     return PADREF;
70 }
71
72 {_ref} {
73     PRINT ("REF: %s\n", 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\n", yytext);
84     lvalp->s = gst_parse_strdup (yytext);
85     BEGIN (INITIAL);
86     return BINREF;
87 }
88
89 {_identifier} {
90     PRINT ("IDENTIFIER: %s\n", 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\n", 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\n", 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]\n", yytext); return *yytext; }
126
127 [[:space:]]+ { PRINT ("SPACE: [%s]\n", yytext); }
128
129 . {
130     printf ("???: %s\n", yytext);
131     return *yytext;
132 }
133
134 %%