]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/doc/spec.tex
added an example of a long fxgrep expression
[helm.git] / helm / DEVEL / mathml_editor / doc / spec.tex
1 \documentclass[10pt]{article}
2
3 \usepackage{a4wide}
4 \usepackage{palatino}
5 \usepackage{euler}
6 \usepackage{amssymb}
7 \usepackage{stmaryrd}
8
9 \title{A MathML Editor Based on \TeX{} Syntax\\Formal Specification}
10 \author{Paolo Marinelli\\Luca Padovani\\\small\{{\tt pmarinel},{\tt lpadovan}\}{\tt @cs.unibo.it}\\\small Department of Computer Science\\\small University of Bologna}
11 \date{}
12
13 \newcommand{\tmap}[1]{\llbracket#1\rrbracket}
14 \newcommand{\tadvance}{\vartriangle}
15 \newcommand{\tnext}{\rhd}
16 \newcommand{\G}{\texttt{g}}
17 \newcommand{\PNODE}{\texttt{p}}
18 \newcommand{\SNODE}{\texttt{s}}
19 \newcommand{\INODE}{\texttt{i}}
20 \newcommand{\NNODE}{\texttt{n}}
21 \newcommand{\ONODE}{\texttt{o}}
22 \newcommand{\CNODE}{\texttt{c}}
23 \newcommand{\TABLE}{\texttt{table}}
24 \newcommand{\SP}{\texttt{sp}}
25 \newcommand{\SB}{\texttt{sb}}
26 \newcommand{\CELL}{\texttt{cell}}
27 \newcommand{\ROW}{\texttt{row}}
28 \newcommand{\SLDROP}{\blacktriangleleft}
29 \newcommand{\NLDROP}{\vartriangleleft}
30
31 \begin{document}
32
33 \maketitle
34
35 \section{Tokens}
36
37 The following tokens are defined:
38
39 \begin{tabular}{lllp{0.5\textwidth}}
40   \textbf{\TeX{}} & \textbf{Notation} & \textbf{Node} & \textbf{Description} \\
41 \hline
42   \verb+{+ & $\mathrm{begin}$ & \texttt{g} & Beginning of a group \\
43   \verb+}+ & $\mathrm{end}$ & & End of a group \\
44   \verb+$+ & $\$$ & \texttt{math} & Math shift \\ %$ \\
45   & &  & End-of-line \\
46   \verb+#+$i$ & $p(i)$ & \texttt{p} & Parameter \\
47   \verb+^+ & $\uparrow$ & \texttt{sp} & Superscript \\
48   \verb+_+ & $\downarrow$ & \texttt{sb} & Subscript \\
49   & $\square$ & & Space-like character that can be ignored \\
50   & $s$ & \texttt{s} & Space-like character that may be significant \\
51   letter & $i(v)$ & \texttt{i} & Identifier $v$ \\
52   digit & $n(v)$ & \texttt{n} & Number $v$ \\
53   other & $o(v)$ & \texttt{o} & Other character or operator $v$ \\
54   \verb+~+ & $\sim$ & & Active character \\
55   \verb+%+ & $\%$ & & Comment \\
56   control & $c(v)\langle\alpha_1,\dots,\alpha_n\rangle$ & \texttt{c} & 
57     Control sequence $v$ that expects the $\alpha_1,\dots,\alpha_n$ sequence of tokens. \\
58   backspace & $\vartriangleleft$ & & \\
59   backspace & $\blacktriangleleft$ & & \\
60 \end{tabular}
61
62 %% Some tokens are mapped directly into nodes of the TML tree. The following functions shows
63 %% the mapping:
64
65 \begin{tabular}{r@{\quad$=$\quad}l}
66   $\tmap{\{}$ & \verb+g+ \\
67   $\tmap{p(i)}$ & \verb+p[@index=+$i$\verb+]+ \\
68   $\tmap{p_l(i)}$ & \verb+p[@index=+$i$\verb+][@left-open='1']+ \\
69   $\tmap{p_r(i)}$ & \verb+p[@index=+$i$\verb+][@right-open='1']+ \\
70   $\tmap{s}$ & \verb+s+ \\
71   $\tmap{\uparrow}$ & \verb+sp+ \\
72   $\tmap{\downarrow}$ & \verb+sb+ \\
73   $\tmap{i(v)}$ & \verb+i[@value=+$v$\verb+]+ \\
74   $\tmap{n(v)}$ & \verb+n[@value=+$v$\verb+]+ \\
75   $\tmap{o(v)}$ & \verb+o[@value=+$v$\verb+]+ \\
76   $\tmap{c(v)\langle\alpha_1,\dots,\alpha_n\rangle}$ & \verb+c[@name=+$v$\verb+][^+$\tmap{\alpha_1}\cdots\tmap{\alpha_n}$\verb+$]+\\
77 \end{tabular}
78 %$
79
80 %% \section{Description and Semantics of the Pattern Language}
81
82 %% \begin{eqnarray*}
83 %%   \mathit{NodeTest} & ::= & \mathtt{*} \\
84 %%   & | & \mathit{ElementType} \\
85 %%   & | & \mathtt{<}~\mathit{ElementTypePattern}~\mathtt{>} \\[1ex]
86 %%   \mathit{ElementTypePattern} & ::= & \mathtt{*} \\
87 %%   & | & \mathit{ElementType}~(\mathtt{|}~\mathit{ElementType})^* \\
88 %%   & | & \mathtt{!}\mathit{ElementType}~(\mathtt{|}~\mathit{ElementType})^*\\[1ex]
89 %%   \mathit{NodePattern} & ::= & \mathit{NodeTest}~\mathit{AttributeQualifier}^*\\[1ex]
90 %%   \mathit{AttributeQualifier} & ::= & \mathtt{[@}\mathit{AttributeTest}\mathtt{]}\\
91 %%   & | & \mathtt{[!@}\mathit{AttributeTest}\mathtt{]}\\[1ex]
92 %%   \mathit{AttributeTest} & ::= & \mathit{AttributeName} \\
93 %%   & | & \mathit{AttributeName}\mathtt{='}\mathit{Text}\mathtt{'}
94 %% \end{eqnarray*}
95
96 \section{Insert Rules}
97
98 \paragraph{Begin Group:} $\{$
99
100 \begin{description}
101   \item{\verb+table/cursor+}\\
102    create a \texttt{row} node, create a \texttt{cell} node, create a \texttt{g} node,
103     append the cursor to the \texttt{g} node, append the \texttt{g} node to the \texttt{cell} node,
104     append the \texttt{cell} node to the \texttt{row} node, append the \texttt{row} node to the
105     \texttt{c} node 
106   \item{\verb+cursor+} \\ create a \texttt{g} node, replace the cursor with the new \texttt{g} node,
107     append the cursor to the new \texttt{g} node
108 \end{description}
109
110 % CASE: c/g[!@id]/cursor
111
112 % CASE: c/cursor
113
114 % ELSE:
115
116 % do_begin:
117 % CASE: c[@table='1']/cursor
118 % ELSE:
119 %   create a g node with id, replace the cursor with the fresh g and append
120 %   the cursor as only child of it
121
122 \paragraph{End Group:} $\}$
123
124 \begin{description}
125   \item{\verb+g[@id]/cursor+}\\
126   remove the cursor, put $\tadvance$ after the \texttt{g} node
127   \item{\verb+row/cell/g/cursor+}\\
128   remove the cursor, put $\tadvance$ after the \texttt{row} node
129   \item{\verb+math/g[!@id]/cursor+}\\
130   ?
131   \item{\verb+cursor+}\\
132   error ?
133 \end{description}
134
135 \paragraph{Math Shift:} $\$$
136
137 \begin{description}
138   \item{\verb+tex/cursor+}\\
139   create a \texttt{math} node, create a \texttt{g} node, append the \texttt{g} node
140     as child of the \texttt{math} node, append the cursor as child of the \texttt{g} node
141   \item{\verb+math[@display='1']/g[!@id][*#]/cursor+}\\
142   append the cursor as last child of the \texttt{math} node
143   \item{\verb+math/g[!@id][*#]/cursor+}\\
144   remove the cursor
145   \item{\verb+math[!display='1']/g[!@id]/cursor+}\\
146   set \verb+display='1'+ in the \texttt{math} node
147   \item{\verb+math/g[!@id]+}\\
148   append the cursor after the \texttt{math} node
149   \item{\verb+math/cursor+}\\
150   remove the cursor
151   \item{\verb+cursor+} \\
152   error ?
153 \end{description}
154
155 % do_shift:
156 % CASE: tex/cursor
157 %   create a math node. create a g node. append g as child of math.
158 %   append the cursor as child of g
159 % CASE: math[@display='1']/g[!@id][*#]/cursor
160 %   append the cursor as last child of math
161 % CASE: math/g[!@id][*#]/cursor
162 %   remove the cursor. Editing is done
163 % CASE: math[!display='1']/g[!@id]/cursor
164 %   set the display attribute to '1'
165 % CASE: math/g[!@id]
166 %   append the cursor after math (?)
167 % CASE: math/cursor
168 %   remove the cursor. Editing is done
169 % ELSE:
170 %   error
171
172 \paragraph{Align:} $\&$
173
174 \begin{description}
175   \item{\verb+g[@id]/cursor+}\\
176   create a \texttt{row} node, create a \texttt{cell} node, create a \texttt{g} node,
177     append the cursor to the new \texttt{g} node, append the \texttt{cell} node to the
178     the \texttt{row} node ?
179   \item{\verb+row/cell/g/cursor+}\\
180   create the \texttt{g} node, create the \texttt{cell} node, append the cursor
181     as child of the new \texttt{g} node, append the new \texttt{g} node to the new
182     \texttt{cell} node after the old \texttt{cell} node
183   \item{\verb+cursor+}\\
184   error
185 \end{description}
186
187 % do_align:
188 % CASE: g[@id]/cursor
189 %   create a row node. create a cell node. create a g node. append the
190 %   cursor to g, append the g to cell, append the cell to row, ???
191 % CASE: row/cell/g/cursor
192 %   create a g node. create a cell node. appent the cursor to g,
193 %   append the g to cell, insert the new cell after the existing cell
194 % ELSE:
195 %   error
196
197 \paragraph{End-of-line:}
198
199 % do_eol:
200 %   ignored
201
202 \paragraph{Parameter:} $p(i)$
203 % do_parameter:
204 %   ignored
205
206 \paragraph{Superscript:} $\uparrow$
207
208 \begin{description}
209   \item{\verb+<g|p>[^#]/cursor+}\\
210   create a \SP{} node, create a \G{} node, replace the cursor with the \SP{} node,
211     append the \G{} node as first child of the \SP{} node, append the cursor as last
212     child of the \SP{} node
213   \item{\verb+<g|p>[*#]/cursor+}\\
214   create a \SP{} node, replace \texttt{*} with the \SP{} node, append \texttt{*} to
215     the \SP{} node, append cursor to the \SP{} node
216   \item{\verb+sp[^*#$][!@over='1']/cursor+}\\ %$
217   set \verb+over='1'+ in the \SP{} node
218   \item{\verb+sp[^*#$][@over='1']/cursor+}\\ %$
219   error
220   \item{\verb+cursor+}\\
221   error ?
222 \end{description}
223 % do_superscript:
224 % CASE: g[^#]/cursor
225 %   create sp node. create g node, replace cursor with sp, append g to sp, append cursor to sp
226 % CASE: g[*#]/cursor
227 %   create sp node, replace * with sp, append * to sp, append cursor to sp
228 % CASE: sp[^*#$][!@over='1']/cursor
229 %   set over='1' in sp node
230 % CASE: sp[^*#$][@over='1']/cursor
231 %   error
232 % ELSE:
233 %   error ?
234
235 \paragraph{Subscript:} $\downarrow$
236
237 \begin{description}
238   \item{\verb+<g|p>[^#]/cursor+}\\
239   create a \SB{} node, create a \G{} node, replace the cursor with the \SB{} node,
240     append the \G{} node as first child of the \SB{} node, append the cursor as last
241     child of the \SB{} node
242   \item{\verb+<g|p>[*#]/cursor+}\\
243   create a \SB{} node, replace \texttt{*} with the \SB{} node, append \texttt{*} to
244     the \SB{} node, append cursor to the \SB{} node
245   \item{\verb+sb[^*#$][!@under='1']/cursor+}\\ %$
246   set \verb+under='1'+ in the \SB{} node
247   \item{\verb+sb[^*#$][@under='1']/cursor+}\\ %$
248   error
249   \item{\verb+cursor+}\\
250   error ?
251 \end{description}
252 % do_subscript:
253 % CASE: g[^#]/cursor
254 %   create sb node. create g node, replace cursor with sb, append g to sb, append cursor to sb
255 % CASE: g[*#]/cursor
256 %   create sb node, replace * with sb, append * to sb, append cursor to sb
257 % CASE: sb[^*#$][!@under='1']/cursor
258 %   set over='1' in sb node
259 % CASE: sb[^*#$][@under='1']/cursor
260 %   error
261 % ELSE:
262 %   error ?
263
264 \paragraph{Ignorable space:} $\square$
265
266 % do_ignorable_space:
267 %   do nothing?
268
269 \paragraph{Space:} $s$
270
271 \begin{description}
272   \item{\verb+cursor+}\\
273   create \SNODE{} node, replace cursor with the \SNODE{} node, append
274   $\tadvance$ after \SNODE{} node
275 \end{description}
276
277 % do_space
278 %   create s node, replace cursor with s, append \advance after s
279
280 \paragraph{Identifier:} $i(v)$
281
282 \begin{description}
283   \item{\verb+cursor+}\\
284   create an \INODE{}, set \verb+value=+$v$ in the \INODE{}, replace
285   cursor with \INODE{}, append $\tadvance$ after the \INODE{} node
286 \end{description}
287
288 % do_identifier
289 %   create i node, replace cursor with i, append \advance after i
290
291 \paragraph{Number:} $n(v)$
292
293 \begin{description}
294   \item{\verb+cursor+}\\
295   create an \NNODE{}, set \verb+value=+$v$ in the \NNODE{}, replace
296   cursor with \NNODE{}, append $\tadvance$ after the \NNODE{} node
297 \end{description}
298
299 % do_number
300 %   create n node, replace cursor with n, append \advance after n
301
302 \paragraph{Apostrophe:} $o({}')$
303
304 \begin{description}
305   \item{\verb+<g/p>[(sp[*#$]/g[o[@name='prime']$])#]/cursor+}\\
306   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
307     append the \ONODE{} to the innermost \G{} node
308   \item{\verb+<g|p>[(sb[^sp[^*#$]/g[o[@name='prime']]$])#]/cursor+}\\
309   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
310     append the \ONODE{} to the innermost \G{} node
311   \item{\verb+<g|p>[*#]/cursor+}\\
312   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
313     create a \SP{} node, create a \G{} node, replace \texttt{*} with \SP{} node,
314     append the new \G{} node to the \SP{} node, append the \ONODE{}
315     node to the new \G{} node
316   \item{\verb+<g|p>[^#]/cursor+}\\
317   error?
318   \item{\verb+cursor+}\\
319   cursor is not in a group, error?
320 \end{description}
321
322 % do_apostrophe
323 % CASE: g[(sp[^*#$]/g[o[@name='prime']$])#]/cursor
324 %   append a new o[@name='prime'] node to the inner g node
325 % CASE: g[(sb[^sp[^*#$]/g[o[@name='prime']]$])#]/cursor
326 %   append a new o[@name='prime'] node to the inner g node
327 % CASE: g[*#]/cursor
328 %   create sp node, create g node, replace * with sp, append * to sp, append g to sp,
329 %   append a new o[@name='prime'[ node to the new g node
330 % CASE: g[^#]/cursor
331 %   error?
332 % ELSE:
333 %   cursor is not in a group, error?
334
335 \paragraph{Other:} $o(v)$
336
337 create an \ONODE{}, set \verb+value=+$v$ in the \ONODE{}, replace
338 cursor with \ONODE{}, append $\tadvance$ after the \ONODE{} node
339
340 % do_other
341 %   create o node, replace cursor with o, append \advance after o
342
343 \paragraph{Active:} $\sim$
344
345 % do_active:
346 %   ignored ???
347
348 \paragraph{Comment:} $\%$
349
350 % do_comment:
351 %   ignored ???
352
353 \paragraph{Begin Environment:} $c(\mathtt{begin})\langle\alpha_1,\dots,\alpha_n\rangle$
354
355 \paragraph{End Environment:} $c(\mathtt{end})\langle\rangle$
356
357 \paragraph{Left Delimiter:} $c(\mathtt{left})\langle\alpha\rangle$
358
359 \paragraph{Right Delimiter:} $c(\mathtt{right})\langle\alpha\rangle$
360
361 \paragraph{Carriage-Return:} $c(\mathtt{cr})\langle\rangle$
362
363 \begin{description}
364   \item{\verb+row/cell/g/cursor+}\\
365   create a \ROW{} node, create a \CELL{} node, create a \G{}
366     node, append the cursor to the new \G{} node, append the new \G{}
367     node to the new \CELL{} node, append the new \CELL{} node to the
368     new \ROW{} node, insert the new \ROW{} node after the old \ROW{} node
369   \item{\verb+cursor+}\\
370   ignored?
371 \end{description}
372
373 % do_cr:
374 % CASE: row/cell/g/cursor
375 %   create row node, create cell node, create g node,
376 %   append cursor to g, append g to cell, append cell to row,
377 %   insert new row after old row
378 % ELSE:
379 %   ignored ???
380
381 \paragraph{Macro:} $c(v)\langle\alpha_1,\dots,\alpha_n\rangle$
382
383 \begin{description}
384   \item{\verb+<p|g>/cursor+}\\
385   create a \CNODE{} node with the children corresponding to the pattern
386   $\tmap{\alpha_1}$,\dots,$\tmap{\alpha_n}$, replace the cursor with
387   the new \CNODE{} node. put $\tnext$ as the first child of the new
388   \CNODE{} node
389
390   \item{\verb+*/cursor+}\\
391   create a \CNODE{} node with the children corresponding to the pattern
392   $\tmap{\alpha_1}$,\dots,$\tmap{\alpha_n}$, replace the cursor with
393   the new \CNODE{} node, put $\tnext$ as the first child of the new
394   \CNODE{} node. If $n\ne0$ emit a warning (the macro has arguments but
395   but the context wouldn't normally allow them to be entered)
396 \end{description}
397
398 % do_macro:
399 % CASE: g/cursor
400 %   create a c node with children corresponding to the pattern of the macro
401 %   append \nextparam as first child of the macro
402
403 \section{Left Drop Rules}
404
405 \paragraph{Normal Left Drop:} $\NLDROP$
406
407 \begin{description}
408
409   %********* rules that try to express situations completely specified (there is an effective deletion) ******
410
411   % in the rules below, a token is either an i node, an n node, an o node, an s node or an empty c node.
412   % an empty c node is either an undefined macro or an empty macro. These c node are handled as they actually were 
413   % tokens (i, n, o, s).
414
415   % there is an optional sequence of groups with id, all of which having one and only one child. The last
416   % child of this sequence (or the root, if the sequence is empty) is a group with id, has as first element a
417   % token and has as second and last element an eventually empty sequence of groups with id, all of which having
418   %one and only one child. The last element of this sequence has the cursor as its child.
419   \item{\verb+(g[@id][^*$]/++\verb+)?g[@id][^(i|n|o|s|c[ ])#$]/(g[@id][^*$]/++\verb+)?cursor+}\\
420   replace the whole fragment with the cursor.
421
422   %*******************************************************************************************************
423   %************** rules handling the case in which the cursor has a preceding node ***********************
424   %*******************************************************************************************************
425
426   %************************* the cursor's parent is a group or a parameter *******************************
427
428   %we consider an empty macro as a token. An empty macro is either undefined or simply empty.
429
430   %rule handling the case where the cursor has a preceding token and this is the first node of a group with id
431   \item{\verb+g[@id][^(i||n||o||s||c[^$])#]/cursor+}\\
432   remove the cursor and replace the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node with the $\NLDROP$.
433   \item{\verb+<g|p>[(i||n||o||s||c[^$])#]/cursor+}\\
434   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
435   %it corresponds to the drop_prev_group(false).
436   \item{\verb+<g|p>[g#]/cursor+}\\
437   remove the cursor and append the $\NLDROP$ to the \G{} node.
438   %corresponds to the drop_prev_script(false).
439   \item{\verb+<g|p>[(<sp|sb>)#]/cursor+}\\
440   remove the cursor and append the $\NLDROP$ to the \SP{} or \SB{} node.
441   %rules handling the right open macros preceding the cursor.
442   \item{\verb+<g|p>[(c[^p[@right-open='1']$])#]/cursor+}\\
443   remove the cursor and append the $\NLDROP$ to the \PNODE{} node.
444   %we don't have a macro of this kind, but we don't know the future...
445   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/cursor+}\\
446   remove the cursor and replace the \CNODE node with the $\NLDROP$.
447   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1']$])#]/cursor+}\\
448   replace the \CNODE{} node with the content of the \PNODE node and replace the cursor with the $\NLDROP$.
449   %rules handling macro with parameter(s) and preceding the cursor.
450   \item{\verb+<g|p>[c#]/cursor+}\\
451   remove the cursor and append the $\NLDROP$ to the \CNODE{} node.
452   %rule handling table with rows preceding the cursor.
453   \item{\verb+<g|p>[(table[row[cell[^g$]$]$])#]/cursor+}\\
454   remove the cursor and append the $\NLDROP$ to the \G{} node, which is child of the \CELL{} node.
455   %rule handling tables without rows preceding the cursor.
456   \item{\verb+<g|p>[table#]/cursor+}\\
457   remove the cursor and append the $\NLDROP$ to the \TABLE{} node
458
459   %********************************* the cursor's parent is a script ******************************
460
461   %rule handling the case where the script's base is an empty group with id.
462   \item{\verb+<sp|sb>[^(g[@id][^$])#$]/cursor+}\\
463   replace the \SP{} or \SB{} node with the $\NLDROP$.
464   %rule handling the case where the script's base is an empty group without id
465   \item{\verb+<sp|sb>[^(g[^$])#$]/cursor+}\\
466   replace the \SP{} or \SB{} node with the cursor.
467   %rule handling the case where the script's base is something else
468   \item{\verb+<sp|sb>[^*#$]/cursor+}\\
469   replace the \SP{} or \SB{} node with it's first child and insert the $\NLDROP$ after it.
470
471   %********************************* the cursor's parent is a macro ********************************
472
473   %rule handling the case where the preceding node is a parameter
474   \item{\verb+c[p#]/cursor+}\\
475   remove the cursor and append the $\NLDROP$ to the PNODE{} node.
476   %rule handling the case where the preceding node is a delimiter
477   \item{\verb+c[(<i|n|o|s|c>)#]/cursor+}\\
478   remove the cursor and insert the $\NLDROP$ before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
479
480   %*************************************************************************************************
481   %*********** rules handling the case in which the cursor has no preceding nodes ******************
482   %*************************************************************************************************
483
484   %rule handling the case where the cursor has something else after it
485   \item{\verb+<g|p>[#*]/cursor+}\\
486   nothing to drop.
487
488   %rules handling the case where the cursor's parent is a p node and the cursor has no nodes after it.
489
490   %rule handling the case where the p node is a left and right open macro's child and the first p node has no elements.
491   \item{\verb+c[^(p[@left-open='1'][^$])#$]/p[@right-open='1'][^#$]/cursor+}\\
492   replace the \CNODE{} with the $\NLDROP$.
493   %rule handling the case where the p node is a left and right open macro's child and the first p node has elements.
494   \item{\verb+c[^(p[@left-open='1']#$]/p[@right-open='1'][^#$]/cursor+}\\
495   replace the \CNODE{} with the content of the PNODE{} with attribute texttt{left-open='1'} and insert $\NLDROP$ after this.
496   %rule handling the case where the p node is right open macro's child.
497   \item{\verb+c[^#$]/p[@right-open='1'][^#$]/cursor+}\\
498   replace the \CNODE{} with the $\NLDROP$.
499   %rule handling the case where the p node is a macro's child and this macro has parameter.
500   \item{\verb+c/p[^#$]/cursor+}\\
501   remove the cursor and insert the $\NLDROP$ before the \PNODE{} node.
502   
503   %rule handling the case where the cursor has no nodes after it and its parent is a group with id
504   \item{\verb+g[@id][^#$]/cursor+}\\
505   replace the \G{} node with the $\NLDROP$.
506
507 \end{description}
508
509 \paragraph{Special Left Drop:} $\SLDROP$
510
511 \begin{description}
512
513   %*******************************************************************************************************
514   %************** rules handling the case in which the cursor has a preceding node ***********************
515   %*******************************************************************************************************
516
517   %************************* the cursor's parent is a group or a parameter *******************************
518
519   %this rule is more specific than the one below which handle the case of the cursor preceded by a c node
520   \item{\verb+<g|p>[(i||n||o||s||c[^$])#]/cursor+}\\
521   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
522   %it corresponds to the drop_prev_group(true).
523   \item{\verb+<g|p>[g#]/cursor+}\\
524   remove the cursor and append the it to the \G{} node.
525   %corresponds to the drop_prev_script(true).
526   \item{\verb+<g|p>[(<sp|sb>)#]/cursor+}\\
527   remove the cursor and append the $\SLDROP$ to the \SP{} or \SB{} node.
528   %rules handling the right open macros preceding the cursor.
529   \item{\verb+<g|p>[(c[^p[@right-open='1']$])#]/cursor+}\\
530   remove the cursor and append the $\SLDROP$ to the \PNODE{} node.
531   %we don't have a macro of this kind, but we don't know the future...
532   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/cursor+}\\
533   remove the cursor and replace the \CNODE node with the cursor.
534   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1']$])#]/cursor+}\\
535   replace the \CNODE{} node with the content of the \PNODE node.
536   %rule handling macro with parameter(s) and preceding the cursor.
537   \item{\verb+<g|p>[c#]/cursor+}\\
538   remove the cursor and append the $\SLDROP$ to the \CNODE{} node.
539   %rule handling table with rows preceding the cursor.
540   \item{\verb+<g|p>[(table[row[cell[^g$]$]$])#]/cursor+}\\
541   remove the cursor and append the it to the \G{} node, which is child of the \CELL{} node.
542   %rule handling tables without rows preceding the cursor.
543   \item{\verb+<g|p>[table#]/cursor+}\\
544   remove the cursor and append the $\SLDROP$ to the \TABLE{} node
545
546   %********************************* the cursor's parent is a script ******************************
547
548   %rule handling the case where the script's base is an empty group with id.
549   \item{\verb+<sp|sb>[^(g[@id][^$])#$]/cursor+}\\
550   replace the \SP{} or \SB{} node with the \G{} node and insert the cursor after it.
551   %rule handling the case where the script's base is an empty group without id
552   \item{\verb+<sp|sb>[^(g[^$])#$]/cursor+}\\
553   replace the \SP{} or \SB{} node with the cursor.
554   %rule handling the case where the scrip's base is something else
555   \item{\verb+<sp|sb>[^*#$]/cursor+}\\
556   replace the \SP{} or \SB{} node with it's first child and insert the cursor after it.
557
558   %********************************* the cursor's parent is a macro ********************************
559
560   %rule handling the case where the preceding node is a parameter
561   \item{\verb+c[p#]/cursor+}\\
562   remove the cursor and append the $\SLDROP$ to the PNODE{} node.
563   %rule handling the case where the preceding node is a delimiter
564   \item{\verb+c[(<i|n|o|s|c>)#]/cursor+}\\
565   remove the cursor and insert the it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
566
567   %*************************************************************************************************
568   %*********** rules handling the case in which the cursor has no preceding nodes ******************
569   %*************************************************************************************************
570
571   %rule handling the case where the cursor has something else after it
572   \item{\verb+<g|p>[#*]/cursor+}\\
573   nothing to drop.
574
575   %rules handling the case where the cursor's parent is a p node and the cursor has no nodes after it.
576
577   %rule handling the case where the p node is a left and right open macro's child and the first p node has no elements.
578   \item{\verb+c[^(p[@left-open='1'][^$])#$]/p[@right-open='1'][^#$]/cursor+}\\
579   replace the \CNODE{} with the cursor.
580   %rule handling the case where the p node is a left and right open macro's child and the first p node has elements.
581   \item{\verb+c[^(p[@left-open='1']#$]/p[@right-open='1'][^#$]/cursor+}\\
582   replace the \CNODE{} with the content of the PNODE{} with attribute texttt{left-open='1'} and insert cursor after this.
583   %rule handling the case where the p node is right open macro's child.
584   \item{\verb+c[^#$]/p[@right-open='1'][^#$]/cursor+}\\
585   replace the \CNODE{} with the cursor.
586   %rule handling the case where the p node is a macro's child and this macro has parameter.
587   \item{\verb+c/p[^#$]/cursor+}\\
588   remove the cursor and insert the $\SLDROP$ before the \PNODE{} node.
589   
590   %rule handling the case where the cursor has no nodes after it and its parent is a group with id
591   \item{\verb+g[@id][^#$]/cursor+}\\
592   replace the \G{} node with the cursor.
593
594 \end{description}
595
596 \section{Right Drop Rules}
597
598 \section{$\varepsilon$-rules}
599
600 \paragraph{Nromal Left Drop}
601
602 \begin{description}
603
604
605   %********************************************* \NLDROP has a preceding node *********************************************
606
607   %rule handling the case where the preceding node is a token or an empty macro.
608   \item{\verb+*[(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
609   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or the \CNODE{} node.
610   %rule handling the case where the preceding node is a group
611   \item{\verb+*[g#]/+$\NLDROP$}\\
612   remove the $\NLDROP$ append it to the \G{} node.
613   %rule handling the case where the preceding node is a script
614   \item{\verb+*[<sp|sb>#]/+$\NLDROP$}\\
615   remove the $\NLDROP$ append it to the \SP{} or \SB{} node.
616   %rule handling the case where the preceding node is an open-right macro
617   \item{\verb+*[(c[^p[@right-open='1']$])#]/+$\NLDROP$}\\
618   remove the $\NLDROP$ and append it to the \PNODE{} node.
619   %rule handling the case where the preceding node is a left-open macro (and not right-open), and the p node of this macro has no children
620   \item{\verb+*[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/+$\NLDROP$}\\
621   remove the \CNODE node.
622   %rule handling the case where the preceding node is a left-open macro (and not right-open), and the p node of this macro has children
623   \item{\verb+*[(c[^p[!(@right-open='1')][@left-open='1']$])#]/+$\NLDROP$}\\
624   replace the \CNODE{} node with the content of the \PNODE{} node.
625   %rule handling the case where the preceding node is a macro with parameter(s)
626   \item{\verb+*[c#]/+$\NLDROP$}\\
627   remove the $\NLDROP$ and append it to the \CNODE{} node.
628
629   %rule handling the deletion of primes in superscript
630
631   %there are more than one prime in the phantom group
632   \item{\verb+sp[!(@id)][*#$]/g[!(@id)][o#]/+$\NLDROP$}\\
633   remove the \ONODE node, remove the $\NLDROP$ and insert the cursor after the \SP{} node.
634   %there is one and only one prime in the phantom group
635   \item{\verb+sp[!(@id)][*#$]/g[!(@id)][^o#]/+$\NLDROP$}\\
636   replace the \SP{} node with it's first child and insert the cursor after it
637
638   %*** rules handling the case where the \NLDROP's parent is a macro (with parameter) ***
639
640   %the node preceding the \NLDROP is a delimiter
641   \item{\verb+c[(<i|n|o|s|c>)#]/+$\NLDROP$}\\
642   remove the $\NLDROP$ and insert it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
643   %the node preceding the \NLDROP is parameter
644   \item{\verb+c[p#]/+$\NLDROP$}\\
645   remove the $\NLDROP$ and append it to the \PNODE{} node.
646
647   %********************************************* the \NLDROP has no preceding nodes ****************************************************
648
649   %if the \NLDROP has no preceding nodes, but has following nodes...
650   \item{\verb+<g|p>[#*]/+$\NLDROP$}\\
651   replace the $\NLDROP$ with the cursor.
652   %rule handling the case where the $\NLDROP$ is the only child of a group with id.
653   \item{\verb+g[@id][^#$]/+$\NLDROP$}\\
654   replace the \G{} node with the $\NLDROP$.
655   %\NLDROP is the first child of a macro with no inserted parameter
656   \item{\verb+c[!(p[*])][^#]/+$\NLDROP$}\\
657   replace the \CNODE{} with the $\NLDROP$.
658   %\NLDROP is the first child of a macro with some inserted parameter
659   \item{\verb+c[p[*]][^#]/+$\NLDROP$}\\
660   put the cursor in the first \PNODE{} node.
661   
662
663   %**** rule handling the case where the \NLDROP has a preceding token or a preceding empty macro, which is either undefined or empty ****
664
665   %%the \NLDROP's parent is neither a macro nor a phantom group which in turn is a sp's child and the token is a prime
666   %\item{\verb+*[(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
667   %replace the \INODE{}, \NNODE{}, \SNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node with the cursor and remove the $\NLDROP$.
668   %%the \NLDROP's parent is a macro with argument
669   %\item{\verb+c[((!(p[@left-open='1']))&(!(p[@right-open+'1'])))][(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
670   %remove the $\NLDROP$ and insert it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
671   %%rule handling the case where the \NLDROP's parent is a phantom group, which in turn is a sp's child
672   %\item{\verb+sp[!(@id)][^*#$]/g[!(@id)][o#$]/+$\NLDROP$}\\
673   %remove the \ONODE{} node
674
675   %********************************* rules handling the case where the \NLDROP has a preceding group **************************************
676   \item{\verb+*[g#]/+$\NLDROP$}\\
677   remove the $\NLDROP$ and append it to the \G{} node.
678
679 \end{description}
680
681 \paragraph{Special Left Drop}
682
683 \begin{description}
684
685   \item{special left}\\
686
687 \end{description}
688
689 \paragraph{Advance}
690
691 \begin{description}
692   \item{\verb+g/+$\tadvance$}\\
693   replace $\tadvance$ with the cursor
694
695   \item{\verb+p[#$]/+$\tadvance$}\\ %$
696   put $\tadvance$ after the \PNODE{} node
697
698   \item{\verb+c[#p]/+$\tadvance$} \\
699   remove $\tadvance$, put the cursor as first child of the \PNODE{} node
700
701   \item{\verb+c[#*]/+$\tadvance$} \\ %$
702   replace $\tadvance$ with the cursor 
703
704   \item{\verb+c[#$]/+$\tadvance$} \\ %$
705   move $\tadvance$ after the \CNODE{} node
706 \end{description}
707
708 \paragraph{Next Parameter}
709
710 \paragraph{Next Token}
711
712 %% \begin{description}
713 %%   \item{\verb+c[#p]/+$\tnext$} \\
714 %% \end{description}
715
716 % g[@id]/(c[#$][@right-open]/g[!@id][#$]/)+cursor  }   let p = cursor.parent() in remove; advance(p)
717
718 % c/g[!@id]/cursor
719 % c/cursor 
720 % */cursor  {   let g = new group in replace
721
722 % g[@id][^#$]/cursor  <=   cursor.parent().replace(cursor)
723 % g[@id][^#$]/cursor  <-   cursor
724 % (!g[@id][^#$])[A#B]/(g[@id][^#$]/)+cursor  <-  (!g[@id][^#$])[A#B]/cursor  
725
726 \end{document}