]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_textual.tex
- added sigpipe handling to avoid processes get killed by unhandled
[helm.git] / helm / mathql / doc / mathql_introduction_textual.tex
1 \subsection{Textual syntax} \label{Textual}
2
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:
6
7 \begin{itemize}
8
9 \item
10 \TT{::=} defines a grammatical production by means of a regular expression.
11
12 Regular expressions are made of the following elements
13 (\TT{...} is a placeholder):
14
15 \item 
16 \TT{`...`} represents any character in a character set;
17
18 \item 
19 \verb+`^ ...`+ represents any character (U+20 to U+7E) not in a character set;
20
21 \item 
22 \TT{"..."} represents a string to be matched verbatim;
23
24 \item
25 \GP{...} represents a regular expression defined by a grammatical production;
26
27 \item
28 \TT{... ...} represents a conjunctive regular expression;
29
30 \item
31 \TT{... | ...} represents a disjunctive regular expression;
32
33 \item
34 \TT{[ ... ]?} represents an optional regular expression;
35
36 \item
37 \TT{[ ... ]+} represents a regular expression to be repeated one or more times;
38
39 \item
40 \TT{[ ... ]*} represents a regular expression to be repeated zero or more times;
41
42 \item
43 \TT{[ ... ]} represents a grouped regular expression.
44
45 \end{itemize}
46
47 \begin{figure}
48 \begin{footnotesize} \begin{verbatim}
49 <dec>     ::= '0 - 9'
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}
56 \vskip-1pc
57 \caption{Textual syntax of numbers, strings and paths} \label{StrTS}
58 \end{figure}
59
60 \begin{figure}
61 \begin{footnotesize}
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+^+   \\
68 \hline
69 \end{tabular} \end{center}
70 \end{footnotesize}
71 \vskip-1pc
72 \caption{Textual syntax of escaped characters} \label{EscTS}
73 \end{figure}
74
75 Queries and results can contain quoted constant strings with the syntax of
76 \figref {StrTS}%
77 \footnote
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
84 delimiters.
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.
89
90 \begin{figure}
91 \begin{footnotesize} \begin{verbatim}
92 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
93 <id>    ::= <alpha> [ <alpha> | <dec> ]*
94 <svar>  ::= "$" <id>
95 <evar>  ::= "@" <id>
96 \end{verbatim}\end{footnotesize} %$
97 \vskip-1pc
98 \caption{Textual syntax of variables} \label{VarTS}
99 \end{figure}
100
101 Queries can also contain \emph{set} variables (production \GP{svar}) and
102 \emph{element} variables (production \GP{evar}) according to the syntax of
103 \figref{VarTS}.%
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}.
107
108 \begin{figure}
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}
138 \vskip-1pc
139 \caption{Textual syntax of queries} \label{QueryTS}
140 \end{figure}
141
142 \begin{figure}
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}
149 \vskip-1pc
150 \caption{Textual syntax of results} \label{ResultTS}
151 \end{figure}
152
153 \begin{figure}
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> 
160         |   "{" <queries> "}"  
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}
165 \vskip-1pc
166 \caption{Textual syntax of the basic extension} \label{BasicTS}
167 \end{figure}
168
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}.
177
178