1 // All token codes are small integers with #defines that begin with "TK_"
2 %token_prefix D_
3
4 // The type of the data attached to each token is GValue. This is also the
5 // default type for non-terminals.
6 //
7 %token_type {GValue *}
8 %default_type {GValue *}
9 %token_destructor {if ($$) {
10 #ifdef GDA_DEBUG_NO
11 gchar *str = gda_sql_value_stringify ($$);
12 g_print ("___ token destructor /%s/\n", str)
13 g_free (str);
14 #endif
15 g_value_unset ($$); g_free ($$);}}
16
17 // The generated parser function takes a 4th argument as follows:
18 %extra_argument {GdaSqlParserIface *pdata}
19
20 // This code runs whenever there is a syntax error
21 //
22 %syntax_error {
23 gda_sql_parser_set_syntax_error (pdata->parser);
24 }
25 %stack_overflow {
26 gda_sql_parser_set_overflow_error (pdata->parser);
27 }
28
29 // The name of the generated procedure that implements the parser
30 // is as follows:
31 %name priv_gda_sql_delimiter
32
33 // The following text is included near the beginning of the C source
34 // code file that implements the parser.
35 //
36 %include {
37 #include <string.h>
38 #include <glib.h>
39 #include <glib-object.h>
40 #include <glib/gi18n-lib.h>
41 #include <libgda/sql-parser/gda-sql-parser-private.h>
42 #include <libgda/sql-parser/gda-statement-struct-util.h>
43 #include <libgda/sql-parser/gda-statement-struct-unknown.h>
44 #include <libgda/sql-parser/gda-statement-struct-parts.h>
45 #include <assert.h>
46 }
47
48 // The following directive causes tokens to
49 // fallback to RAWSTRING if they will not parse as their original value.
50 // However in this particular case, it serves to declare the LOOP,... tokens used by the
51 // GdaSqlParser object
52 %fallback RAWSTRING LOOP ENDLOOP DECLARE CREATE BLOB.
53
54 // force the declaration of the ILLEGAL and SQLCOMMENT tokens
55 %nonassoc ILLEGAL.
56 %nonassoc SQLCOMMENT.
57
58 // Input is a single SQL command
59 // A single statement
60 %type stmt {GdaSqlStatement *}
61 %destructor stmt {g_print ("Statement destroyed by parser: %p\n", $$); gda_sql_statement_free ($$);}
exprlist(L)62 stmt ::= exprlist(L) SEMI. {pdata->parsed_statement = gda_sql_statement_new (GDA_SQL_STATEMENT_UNKNOWN);
63 /* FIXME: set SQL */
64 gda_sql_statement_unknown_take_expressions (pdata->parsed_statement, g_slist_reverse (L));
65 }
exprlist(L)66 stmt ::= exprlist(L) END_OF_FILE. {pdata->parsed_statement = gda_sql_statement_new (GDA_SQL_STATEMENT_UNKNOWN);
67 /* FIXME: set SQL */
68 gda_sql_statement_unknown_take_expressions (pdata->parsed_statement, g_slist_reverse (L));
69 }
70
71 // List of expressions
72 %type exprlist {GSList *}
73 %destructor exprlist {if ($$) {g_slist_foreach ($$, (GFunc) gda_sql_expr_free, NULL); g_slist_free ($$);}}
exprlist(L)74 exprlist(L) ::= exprlist(E) expr(X). {L = g_slist_prepend (E, X);}
exprlist(L)75 exprlist(L) ::= expr(E). {L = g_slist_append (NULL, E);}
76
77 // A single expression
78 %type expr {GdaSqlExpr *}
79 %destructor expr {gda_sql_expr_free ($$);}
expr(E)80 expr(E) ::= pvalue(V). {E = V;}
expr(E)81 expr(E) ::= RAWSTRING(R). {E = gda_sql_expr_new (NULL); E->value = R;}
expr(E)82 expr(E) ::= SPACE(S). {E =gda_sql_expr_new (NULL); E->value = S;}
expr(E)83 expr(E) ::= value(V). {E =gda_sql_expr_new (NULL); E->value = V;}
84
85 // Values: for all constants (G_TYPE_STRING GValue)
value(V)86 value(V) ::= STRING(S). {V = S;}
value(V)87 value(V) ::= TEXTUAL(T). {V = T;}
value(V)88 value(V) ::= INTEGER(I). {V = I;}
value(V)89 value(V) ::= FLOAT(F). {V = F;}
90
91 // pvalue: values which are parameters (GdaSqlExpr)
92 %type pvalue {GdaSqlExpr *}
93 %destructor pvalue {gda_sql_expr_free ($$);}
pvalue(E)94 pvalue(E) ::= UNSPECVAL LSBRACKET paramspec(P) RSBRACKET. {E = gda_sql_expr_new (NULL); E->param_spec = P;}
pvalue(E)95 pvalue(E) ::= value(V) LSBRACKET paramspec(P) RSBRACKET. {E = gda_sql_expr_new (NULL); E->value = V; E->param_spec = P;}
pvalue(E)96 pvalue(E) ::= SIMPLEPARAM(S). {E = gda_sql_expr_new (NULL); E->param_spec = gda_sql_param_spec_new (S);}
97
98 // paramspec: parameter's specifications
99 %type paramspec {GdaSqlParamSpec *}
100 %destructor paramspec {gda_sql_param_spec_free ($$);}
paramspec(P)101 paramspec(P) ::= . {P = NULL;}
paramspec(P)102 paramspec(P) ::= paramspec(E) PNAME(N). {if (!E) P = gda_sql_param_spec_new (NULL); else P = E;
103 gda_sql_param_spec_take_name (P, N);}
paramspec(P)104 paramspec(P) ::= paramspec(E) PDESCR(N). {if (!E) P = gda_sql_param_spec_new (NULL); else P = E;
105 gda_sql_param_spec_take_descr (P, N);}
paramspec(P)106 paramspec(P) ::= paramspec(E) PTYPE(N). {if (!E) P = gda_sql_param_spec_new (NULL); else P = E;
107 gda_sql_param_spec_take_type (P, N);}
paramspec(P)108 paramspec(P) ::= paramspec(E) PNULLOK(N). {if (!E) P = gda_sql_param_spec_new (NULL); else P = E;
109 gda_sql_param_spec_take_nullok (P, N);}
110