]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_textual.tex
updating and structuring
[helm.git] / helm / mathql / doc / mathql_introduction_textual.tex
1 \subsection{Textual syntax} \label{Textual}
2
3 The syntax of grammatical productions resembles BNF and POSIX notation:
4
5 \begin{itemize}
6
7 \item
8 \TT{::=} defines a grammatical production by means of a regular expression.
9
10 Regular expressions are made of the following elements
11 (here \TT{...} is a placeholder):
12
13 % \item
14 % \TT{.} represents any character between U 0020 and U 007F inclusive;
15
16 \item 
17 \TT{`...`} represents any character in a character set;
18
19 \item 
20 \verb+`^ ...`+ represents any character (U+0020 to U+007E) not in a character
21 set;
22
23 \item 
24 \TT{"..."} represents a string to be matched verbatim;
25
26 \item
27 \GP{...} represents a regular expression defined by a grammatical production;
28
29 \item
30 \TT{... ...} represents a conjunctive regular expression;
31
32 \item
33 \TT{... | ...} represents a disjunctive regular expression;
34
35 \item
36 \TT{[ ... ]?} represents an optional regular expression;
37
38 \item
39 \TT{[ ... ]+} represents a regular expression to be repeated one or more times;
40
41 \item
42 \TT{[ ... ]*} represents a regular expression to be repeated zero or more times;
43
44 \item
45 \TT{[ ... ]} represents a grouped regular expression.
46
47 \end{itemize}
48
49 \noindent
50 {\MathQL} Expressions can contain quoted constant strings with the syntax of
51 \figref {StrTS}.%
52 \footnote{Note that the first slash of the \GP{path} is not optional as
53 in {\MathQL}.3.}
54
55 \begin{figure}[ht]
56 \begin{footnotesize} \begin{verbatim}
57 <dec>     ::= '0 - 9'
58 <num>     ::= <dec> [ <dec> ]*
59 <hex>     ::= <dec> | 'A - F' | 'a - f'
60 <escaped> ::= "u" <hex> <hex> <hex> <hex> | '"' | "\" | "^"  
61 <string>  ::= '"' [ "\" <escaped> "^" | '^ "\^' ]* '"'
62 <path>    ::= "/" | [ "/" <string> ]+ 
63 \end{verbatim} \end{footnotesize}
64 \vskip-1pc
65 \caption{Textual syntax of numbers, strings and paths} \label{StrTS}
66 \end{figure}
67
68 \noindent
69 The meaning of the escaped sequences is shown in \figref{EscTS}
70 (where $ .... $ is a 4-digit placeholder).
71
72 \begin{figure}[ht]
73 \begin{footnotesize}
74 \begin{center} \begin{tabular}{|l|l|c|}
75 \hline {\bf Escape sequence} & {\bf Unicode character} & {\bf Text} \\
76 \hline \verb+\u....^+        & U+....                  &            \\
77 \hline \verb+\"^+            & U+0022                  & \verb+"+   \\
78 \hline \verb+\\^+            & U+005C                  & \verb+\+   \\
79 \hline \verb+\^^+            & U+005E                  & \verb+^+   \\
80 \hline
81 \end{tabular} \end{center}
82 \end{footnotesize}
83 \vskip-1pc
84 \caption{Textual syntax of escaped characters} \label{EscTS}
85 \end{figure}
86
87 {\MathQL} character escaping syntax aims at complying with W3C character model
88 for the World Wide Web \cite{W3Ca} which recommends a support for standard
89 Unicode characters (U+0000 to U+FFFF) and escape sequences with
90 start/end delimiters.
91 In particular {\MathQL} escape delimiters (backslash and caret) are chosen
92 among the {\em unwise} characters for URI references (see \cite{URI}) because
93 URI references are the natural content of constant strings and these
94 characters should not be so frequent in them.
95
96 Query expressions can contain variables for {\av}'s (production \GP{avar})
97 and variables for {\av} sets, {\ie} for query results (production \GP{svar})
98 according to the syntax of \figref{VarTS}.
99
100 \begin{figure}[ht]
101 \begin{footnotesize} \begin{verbatim}
102 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
103 <id>    ::= <alpha> [ <alpha> | <dec> ]*
104 <avar>  ::= "@" <id>
105 <svar>  ::= "$" <id>
106 \end{verbatim}\end{footnotesize} %$
107 \vskip-1pc
108 \caption{Textual syntax of variables} \label{VarTS}
109 \end{figure}
110
111 \noindent
112 The syntax of query expressions (production \GP{query}) is described in
113 \figref{QueryTS}.
114
115 \begin{figure}[ht]
116 \begin{footnotesize} \begin{verbatim}
117 <qualifier> ::= [ "inverse" ]? [ "sub" | "super" ]? <path>
118 <main>      ::= [ "main" <path> ]? 
119 <cons>      ::= <path> [ "in" | "match" ] <query>
120 <istrue>    ::= [ "istrue" <cons> [ "," <cons> ]* ]?
121 <isfalses>  ::= [ "isfalse" <cons> [ "," <cons> ]* ]* 
122 <exp>       ::= <path> [ "as" <path> ]?
123 <sec>       ::= [ "attr" <exp> [ "," <exp> ]* ]?
124 <opt_args>  ::= <main> <istrue> <isfalses> <sec>
125 <source>    ::= [ "pattern" ]? <query>
126 <paths>     ::= [ <path> [ "," <path> ]* ]?
127 <query>     ::= "(" <query> ")" | <string> | "[" <xavs> "]"
128             |   "property" <qualifier> <opt_args> "of" <source>
129             |   "let" <svar> "=" <query> "in" <query>
130             |   <query> ";;" <query> | <svar> | <avar> 
131             |   "ex" <query> | <avar> "." <path>
132             |   "add" [ "distr" ]? [ <xgroups> | <avar> ] "in" <query>
133             |   "for" <avar> "in" <query> [ "sup" | "inf" ] <query>
134             |   "while" <query> [ "sup" | "inf" ] <query>
135             |   <path> "{" <paths> "}" "{" <queries> "}"
136             |   "gen" <path> [ "{" <queries> "}" | "in" <query> ] 
137 <queries>   ::= [ <query> [ "," <query> ]* ]?
138 <xattr>     ::= <path> "=" <query>
139 <xgroup>    ::= "{" <xattr> [ ";" <xattr> ]* "}"
140 <xgroups>   ::= <xgroup> [ "," <xgroup> ]*
141 <xav>       ::= <string> [ "attr" <xgroups> ]?
142 <xavs>      ::= [ <xav> [ ";" <xav> ]* ]?
143 \end{verbatim} \end{footnotesize}
144 \vskip-1pc
145 \caption{Textual syntax of queries} \label{QueryTS}
146 \end{figure}
147
148 \noindent
149 The syntax of result expressions (production \GP{avs}) is described in
150 \figref{ResultTS}.
151
152 \begin{figure}[ht]
153 \begin{footnotesize} \begin{verbatim}
154 <attr>  ::= <path> "=" <string> | "{" <string> [ "," <string> ]* "}" 
155 <group> ::= "{" <attr> [ ";" <attr> ]* "}"
156 <av>    ::= <string> [ "attr" <group> [ "," <group> ]* ]?
157 <avs>   ::= [ <av> [ ";" <av> ]* ]?
158 \end{verbatim} \end{footnotesize}
159 \vskip-1pc
160 \caption{Textual syntax of results} \label{ResultTS}
161 \end{figure}
162
163 \xcomment {
164
165 \begin{figure}[ht]
166 \begin{footnotesize} \begin{verbatim}
167             |   "select" <avar> "from" <query> "where" <query>
168 \end{verbatim} \end{footnotesize}
169 \vskip-1pc
170 \caption{Textual syntax of basic query extensions} \label{BasicTS}
171 \end{figure}
172
173 }