\subsection{Textual syntax} \label{Textual}

The syntax of grammatical productions resembles BNF and POSIX notation:

\begin{itemize}

\item
\TT{::=} defines a grammatical production by means of a regular expression.

Regular expressions are made of the following elements
(here \TT{...} is a placeholder):

% \item
% \TT{.} represents any character between U 0020 and U 007F inclusive;

\item 
\TT{`...`} represents any character in a character set;

\item 
\verb+`^ ...`+ represents any character (U+0020 to U+007E) not in a character
set;

\item 
\TT{"..."} represents a string to be matched verbatim;

\item
\GP{...} represents a regular expression defined by a grammatical production;

\item
\TT{... ...} represents a conjunctive regular expression;

\item
\TT{... | ...} represents a disjunctive regular expression;

\item
\TT{[ ... ]?} represents an optional regular expression;

\item
\TT{[ ... ]+} represents a regular expression to be repeated one or more times;

\item
\TT{[ ... ]*} represents a regular expression to be repeated zero or more times;

\item
\TT{[ ... ]} represents a grouped regular expression.

\end{itemize}

\noindent
{\MathQL} Expressions can contain quoted constant strings with the syntax of
\figref {StrTS}.%
\footnote{Note that the first slash of the \GP{path} is not optional as
in {\MathQL}.3.}

\begin{figure}[ht]
\begin{footnotesize} \begin{verbatim}
<dec>     ::= '0 - 9'
<num>     ::= <dec> [ <dec> ]*
<hex>     ::= <dec> | 'A - F' | 'a - f'
<escaped> ::= "u" <hex> <hex> <hex> <hex> | '"' | "\" | "^"  
<string>  ::= '"' [ "\" <escaped> "^" | '^ "\^' ]* '"'
<path>    ::= "/" | [ "/" <string> ]+ 
\end{verbatim} \end{footnotesize}
\vskip-1pc
\caption{Textual syntax of numbers, strings and paths} \label{StrTS}
\end{figure}

\noindent
The meaning of the escaped sequences is shown in \figref{EscTS}
(where $ .... $ is a 4-digit placeholder).

\begin{figure}[ht]
\begin{footnotesize}
\begin{center} \begin{tabular}{|l|l|c|}
\hline {\bf Escape sequence} & {\bf Unicode character} & {\bf Text} \\
\hline \verb+\u....^+        & U+....                  &            \\
\hline \verb+\"^+            & U+0022                  & \verb+"+   \\
\hline \verb+\\^+            & U+005C                  & \verb+\+   \\
\hline \verb+\^^+            & U+005E                  & \verb+^+   \\
\hline
\end{tabular} \end{center}
\end{footnotesize}
\vskip-1pc
\caption{Textual syntax of escaped characters} \label{EscTS}
\end{figure}

{\MathQL} character escaping syntax aims at complying with W3C character model
for the World Wide Web \cite{W3Ca} which recommends a support for standard
Unicode characters (U+0000 to U+FFFF) and escape sequences with
start/end delimiters.
In particular {\MathQL} escape delimiters (backslash and caret) are chosen
among the {\em unwise} characters for URI references (see \cite{URI}) because
URI references are the natural content of constant strings and these
characters should not be so frequent in them.

Query expressions can contain variables for {\av}'s (production \GP{avar})
and variables for {\av} sets, {\ie} for query results (production \GP{svar})
according to the syntax of \figref{VarTS}.

\begin{figure}[ht]
\begin{footnotesize} \begin{verbatim}
<alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
<id>    ::= <alpha> [ <alpha> | <dec> ]*
<avar>  ::= "@" <id>
<svar>  ::= "$" <id>
\end{verbatim}\end{footnotesize} %$
\vskip-1pc
\caption{Textual syntax of variables} \label{VarTS}
\end{figure}

\noindent
The syntax of query expressions (production \GP{query}) is described in
\figref{QueryTS}.

\begin{figure}[ht]
\begin{footnotesize} \begin{verbatim}
<qualifier> ::= [ "inverse" ]? [ "sub" | "super" ]? <path>
<main>      ::= [ "main" <path> ]? 
<cons>      ::= <path> [ "in" | "match" ] <query>
<istrue>    ::= [ "istrue" <cons> [ "," <cons> ]* ]?
<isfalses>  ::= [ "isfalse" <cons> [ "," <cons> ]* ]* 
<exp>       ::= <path> [ "as" <path> ]?
<sec>       ::= [ "attr" <exp> [ "," <exp> ]* ]?
<opt_args>  ::= <main> <istrue> <isfalses> <sec>
<source>    ::= [ "pattern" ]? <query>
<paths>     ::= [ <path> [ "," <path> ]* ]?
<query>     ::= "(" <query> ")" | <string> | "[" <xavs> "]"
            |   "property" <qualifier> <opt_args> "of" <source>
            |   "let" <svar> "=" <query> "in" <query>
            |   <query> ";;" <query> | <svar> | <avar> 
            |   "ex" <query> | <avar> "." <path>
            |   "add" [ "distr" ]? [ <xgroups> | <avar> ] "in" <query>
            |   "for" <avar> "in" <query> [ "sup" | "inf" ] <query>
            |   "while" <query> [ "sup" | "inf" ] <query>
            |   <path> "{" <paths> "}" "{" <queries> "}"
            |   "gen" <path> [ "{" <queries> "}" | "in" <query> ] 
<queries>   ::= [ <query> [ "," <query> ]* ]?
<xattr>     ::= <path> "=" <query>
<xgroup>    ::= "{" <xattr> [ ";" <xattr> ]* "}"
<xgroups>   ::= <xgroup> [ "," <xgroup> ]*
<xav>       ::= <string> [ "attr" <xgroups> ]?
<xavs>      ::= [ <xav> [ ";" <xav> ]* ]?
\end{verbatim} \end{footnotesize}
\vskip-1pc
\caption{Textual syntax of queries} \label{QueryTS}
\end{figure}

\noindent
The syntax of result expressions (production \GP{avs}) is described in
\figref{ResultTS}.

\begin{figure}[ht]
\begin{footnotesize} \begin{verbatim}
<attr>  ::= <path> "=" <string> | "{" <string> [ "," <string> ]* "}" 
<group> ::= "{" <attr> [ ";" <attr> ]* "}"
<av>    ::= <string> [ "attr" <group> [ "," <group> ]* ]?
<avs>   ::= [ <av> [ ";" <av> ]* ]?
\end{verbatim} \end{footnotesize}
\vskip-1pc
\caption{Textual syntax of results} \label{ResultTS}
\end{figure}

\xcomment {

\begin{figure}[ht]
\begin{footnotesize} \begin{verbatim}
            |   "select" <avar> "from" <query> "where" <query>
\end{verbatim} \end{footnotesize}
\vskip-1pc
\caption{Textual syntax of basic query extensions} \label{BasicTS}
\end{figure}

}
