]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_textual.tex
updating the introduction
[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 start/end
90 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 \footnote{This syntax resembles the one of programming languages identifiers.}
100
101 \begin{figure}[ht]
102 \begin{footnotesize} \begin{verbatim}
103 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
104 <id>    ::= <alpha> [ <alpha> | <dec> ]*
105 <avar>  ::= "@" <id>
106 <svar>  ::= "$" <id>
107 \end{verbatim}\end{footnotesize} %$
108 \vskip-1pc
109 \caption{Textual syntax of variables} \label{VarTS}
110 \end{figure}
111
112 \noindent
113 The syntax of query expressions (production \GP{query}) is described in
114 \figref{QueryTS}.
115
116 \begin{figure}[ht]
117 \begin{footnotesize} \begin{verbatim}
118 <qualifier> ::= [ "inverse" ]? [ "sub" | "super" ]? <path>
119 <main>      ::= [ "main" <path> ]? 
120 <cons>      ::= <path> [ "in" | "match" ] <query>
121 <istrue>    ::= [ "istrue" <cons> [ "," <cons> ]* ]?
122 <isfalses>  ::= [ "isfalse" <cons> [ "," <cons> ]* ]* 
123 <exp>       ::= <path> [ "as" <path> ]?
124 <sec>       ::= [ "attr" <exp> [ "," <exp> ]* ]?
125 <opt_args>  ::= <main> <istrue> <isfalses> <sec>
126 <source>    ::= [ "pattern" ]? <query>
127 <paths>     ::= [ <path> [ "," <path> ]* ]?
128 <query>     ::= "(" <query> ")" | <string> | "[" <xavs> "]"
129             |   "property" <qualifier> <opt_args> "of" <source>
130             |   "let" <svar> "=" <query> "in" <query>
131             |   <query> ";;" <query> | <svar> | <avar> 
132             |   "ex" <query> | <avar> "." <path>
133             |   "add" [ "distr" ]? [ <xgroups> | <avar> ] "in" <query>
134             |   "for" <avar> "in" <query> [ "sup" | "inf" ] <query>
135             |   "while" <query> [ "sup" | "inf" ] <query>
136             |   <path> "{" <paths> "}" "{" <queries> "}"
137             |   "gen" <path> [ "{" <queries> "}" | "in" <query> ] 
138 <queries>   ::= [ <query> [ "," <query> ]* ]?
139 <xattr>     ::= <path> "=" <query>
140 <xgroup>    ::= "{" <xattr> [ ";" <xattr> ]* "}"
141 <xgroups>   ::= <xgroup> [ "," <xgroup> ]*
142 <xav>       ::= <string> [ "attr" <xgroups> ]?
143 <xavs>      ::= [ <xav> [ ";" <xav> ]* ]?
144 \end{verbatim} \end{footnotesize}
145 \vskip-1pc
146 \caption{Textual syntax of queries} \label{QueryTS}
147 \end{figure}
148
149 \noindent
150 The syntax of result expressions (production \GP{avs}) is described in
151 \figref{ResultTS}.
152
153 \begin{figure}[ht]
154 \begin{footnotesize} \begin{verbatim}
155 <attr>  ::= <path> "=" <string> | "{" <string> [ "," <string> ]* "}" 
156 <group> ::= "{" <attr> [ ";" <attr> ]* "}"
157 <av>    ::= <string> [ "attr" <group> [ "," <group> ]* ]?
158 <avs>   ::= [ <av> [ ";" <av> ]* ]?
159 \end{verbatim} \end{footnotesize}
160 \vskip-1pc
161 \caption{Textual syntax of results} \label{ResultTS}
162 \end{figure}
163
164 The textual syntax of the language extension provided by the basic library
165 is in \figref{BasicTS}.
166
167 \begin{figure}[ht]
168 \begin{footnotesize} \begin{verbatim}
169 <query> ::= "empty" | "false" | "true"
170         |   "not" <query>
171         |   <query> [ "and" | "or" | "xor"| "sub" | "meet" | "eq" | "le"| "lt" ] <query>
172         |   <query> [ "union" | "intersect" ] <query> | { <queries> }  
173         |   "if" <query> "then" <query> "else" <query>
174         |   "select" <avar> "from" <query> "where" <query>
175 \end{verbatim} \end{footnotesize}
176 \vskip-1pc
177 \caption{Textual syntax of basic extension} \label{BasicTS}
178 \end{figure}
179