1 \subsection{Textual syntax} \label{Textual}
3 In this section we present {\MathQL}.4 textual syntax using the same notation
4 that we adopted in \cite{GS03,Gui03}. In particular the grammatical
5 productions we use resemble {\BNF} with some {\POSIX} formalism:
10 \TT{::=} defines a grammatical production by means of a regular expression.
12 Regular expressions are made of the following elements
13 (\TT{...} is a placeholder):
16 \TT{`...`} represents any character in a character set;
19 \verb+`^ ...`+ represents any character (U+20 to U+7E) not in a character set;
22 \TT{"..."} represents a string to be matched verbatim;
25 \GP{...} represents a regular expression defined by a grammatical production;
28 \TT{... ...} represents a conjunctive regular expression;
31 \TT{... | ...} represents a disjunctive regular expression;
34 \TT{[ ... ]?} represents an optional regular expression;
37 \TT{[ ... ]+} represents a regular expression to be repeated one or more times;
40 \TT{[ ... ]*} represents a regular expression to be repeated zero or more times;
43 \TT{[ ... ]} represents a grouped regular expression.
48 \begin{footnotesize} \begin{verbatim}
50 <num> ::= <dec> [ <dec> ]*
51 <hex> ::= <dec> | 'A - F' | 'a - f'
52 <escaped> ::= "u" <hex> <hex> <hex> <hex> | '"' | "\" | "^"
53 <string> ::= '"' [ "\" <escaped> "^" | '^ "\^' ]* '"'
54 <path> ::= "/" | [ "/" <string> ]+
55 \end{verbatim} \end{footnotesize}
57 \caption{Textual syntax of numbers, strings and paths} \label{StrTS}
62 \begin{center} \begin{tabular}{|l|l|c|}
63 \hline {\bf Escape sequence} & {\bf Unicode character} & {\bf Text} \\
64 \hline \verb+\u....^+ & U+.... & \\
65 \hline \verb+\"^+ & U+0022 & \verb+"+ \\
66 \hline \verb+\\^+ & U+005C & \verb+\+ \\
67 \hline \verb+\^^+ & U+005E & \verb+^+ \\
69 \end{tabular} \end{center}
72 \caption{Textual syntax of escaped characters} \label{EscTS}
75 Queries and results can contain quoted constant strings with the syntax of
78 {Note that the first slash of the \GP{path} is not optional as in {\MathQL}.3.}
79 and the meaning of the escaped sequences is shown in \figref{EscTS} (where
80 $ .... $ is a 4-digit placeholder).
81 {\MathQL} character escaping syntax aims at complying with W3C character model
82 for the World Wide Web \cite{W3Ca} which recommends a support for standard
83 Unicode characters (U+0000 to U+FFFF) and escape sequences with start/end
85 In particular {\MathQL} escape delimiters (backslash and caret) are chosen
86 among the \emph{unwise} characters for {\URI} references (see \cite{URI})
87 because {\URI} references are the natural content of constant strings and
88 these characters should not be so frequent in them.
91 \begin{footnotesize} \begin{verbatim}
92 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
93 <id> ::= <alpha> [ <alpha> | <dec> ]*
96 \end{verbatim}\end{footnotesize} %$
98 \caption{Textual syntax of variables} \label{VarTS}
101 Queries can also contain \emph{set} variables (production \GP{svar}) and
102 \emph{element} variables (production \GP{evar}) according to the syntax of
104 \footnote{This syntax resembles the one of programming languages identifiers.}
105 A set variable holds an {\av} set, {\ie} a query result, while an element
106 variable holds an {\av}.
109 \begin{footnotesize} \begin{verbatim}
110 <ref> ::= [ "sub" | "super" ]?
111 <qualifier> ::= [ "inverse" ]? <ref> <path>
112 <main> ::= [ "main" <path> ]?
113 <cons> ::= <path> [ "in" | "match" ] <query>
114 <istrue> ::= [ "istrue" <cons> [ "," <cons> ]* ]?
115 <isfalses> ::= [ "isfalse" <cons> [ "," <cons> ]* ]*
116 <exp> ::= <path> [ "as" <path> ]?
117 <sec> ::= [ "attr" <exp> [ "," <exp> ]* ]?
118 <opt_args> ::= <main> <istrue> <isfalses> <sec>
119 <source> ::= [ "pattern" ]? <query>
120 <paths> ::= <path> [ "," <path> ]*
121 <query> ::= "(" <query> ")" | <string> | "[" <xavs> "]"
122 | "property" <qualifier> <opt_args> "of" <source>
123 | "let" <svar> "=" <query> "in" <query>
124 | <query> ";;" <query> | <svar> | <evar>
125 | "ex" <query> | <evar> "." <path>
126 | "add" [ "distr" ]? [ <xgroups> | <evar> ] "in" <query>
127 | "for" <evar> "in" <query> [ "sup" | "inf" ] <query>
128 | "while" <query> [ "sup" | "inf" ] <query>
129 | <path> "{" [ <paths> ]? "}" "{" <queries> "}"
130 | "gen" <path> [ "{" <queries> "}" | "in" <query> ]
131 <queries> ::= [ <query> [ "," <query> ]* ]?
132 <xattr> ::= <path> "=" <query>
133 <xgroup> ::= "{" <xattr> [ ";" <xattr> ]* "}"
134 <xgroups> ::= <xgroup> [ "," <xgroup> ]*
135 <xav> ::= <string> [ "attr" <xgroups> ]?
136 <xavs> ::= [ <xav> [ ";" <xav> ]* ]?
137 \end{verbatim} \end{footnotesize}
139 \caption{Textual syntax of queries} \label{QueryTS}
143 \begin{footnotesize} \begin{verbatim}
144 <attr> ::= <path> "=" <string> | "{" <string> [ "," <string> ]* "}"
145 <group> ::= "{" <attr> [ ";" <attr> ]* "}"
146 <av> ::= <string> [ "attr" <group> [ "," <group> ]* ]?
147 <avs> ::= [ <av> [ ";" <av> ]* ]?
148 \end{verbatim} \end{footnotesize}
150 \caption{Textual syntax of results} \label{ResultTS}
154 \begin{footnotesize} \begin{verbatim}
155 <query> ::= "empty" | "false" | "true"
156 | [ "not" | "count" | "proj" <path> "of" ] <query>
157 | <query> [ "and" | "or" | "xor" ] <query>
158 | <query> [ "sub" | "meet" | "eq" | "le" | "lt" ] <query>
159 | <query> [ "union" | "intersect" | "diff" ] <query>
161 | "keep" [ "allbut" ]? [ <paths> "in" ]? <query>
162 | "if" <query> "then" <query> "else" <query>
163 | "select" <evar> "from" <query> "where" <query>
164 \end{verbatim} \end{footnotesize}
166 \caption{Textual syntax of the basic extension} \label{BasicTS}
169 The core infrastructure of {\MathQL}.4 defines a syntax for queries
170 (\figref{QueryTS}, production \GP{query}) and a syntax for results
171 (\figref{ResultTS}, production \GP{avs}).
172 A syntax extension for the most common functions of the basic library is
173 also provided for the user's convenience and for backward compatibility with
174 {\MathQL}.3. The syntax extension concerning the functions covered in this
175 paper is shown in \figref{BasicTS}.
176 Note that this extension makes \GP{avs} an instance of \GP{xavs}.