]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/doc/spec.tex
Added some other rules in the "Left Drop" section.
[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   % An important observation is: a sequence of groups with id, in which every group has one and only one child and where 
415   % the last group contains the cursor, is equivalent to the cursor (Is it clear?). For example:
416   % <g id="id1"><g id="id2">...<g id="idn"><cursor/></g>...</g></g> is equivalent to:
417   % <cursor/>
418
419   % there is an optional sequence of groups with id, all of which having one and only one child. The last
420   % child of this sequence (or the root, if the sequence is empty) is a group with id, has as first element a
421   % token and has as second and last element an eventually empty sequence of groups with id, all of which having
422   %one and only one child. The last element of this sequence has the cursor as its child.
423   \item{\verb+(g[@id][^#$]/++\verb+)?g[@id][^(i|n|o|s|c[ ])#$]/(g[@id][^#$]/++\verb+)?cursor+}\\
424   replace the whole fragment with the cursor.
425
426   % the cursor is a macro's child. There is an eventually empty sequence of delimiters, which precedes the
427   % cursor. Before this sequence, there is a p node. This p node has as its last child a token
428   \item{\verb+c[p[(i|n|o|s|c[ ])$]((i|n|o|s|c[ ])*)#]/cursor+}\\
429   remove the cursor and replace the token with the cursor.
430
431   % there is a token, which precedes the cursor. The cursor is child of either a group or a parameter.
432   % the case where the cursor is child of a group with id, there are no nodes after the cusror and there 
433   % are no nodes preceding the token, is handled by the first rule.
434   % This rule is duplicated below, but that one could have a wrong syntax. This one has been tested.
435   \item{\verb+<g|p>[(i|n|o|c[ ])#]/cursor+}\\
436   remove the cursor and replace the token with the cursor.
437
438   % cursor's parent is a script (the cursor is not the base). The script's base is an empty group with id.
439   % The script is preceded by a token.The script's parent is group or a parameter.
440   % The case where the script's parent is a group with id and the token is the first child, while 
441   % the script is the last one, is handled some rules later.
442   \item{\verb+<g|p>[(i|n|o|s|c[ ])#]/<sp|sb>[^(g[@id][ ])#$]/cursor+}\\
443   remove the script and replace the token with the cursor.
444
445   % As above, but: we don't care who precedes the script (we do not have to remove it); the script's base 
446   % is still an empty group, but it has no id.
447   % Ad above, we have to precise that the situation where the script is the only child of a group with id
448   % is handled some rules later.
449   \item{\verb+<g|p>/<sp|sb>[^(g[!@id][ ])#$]/curosr+}\\
450   replace the script with the cursor.
451
452   % The cursor is the last child of a script. The script's base is token.
453   \item{\verb+<g|p>/<sp|sb>[^(i|n|o|s|c[ ])#$]/cursor+}\\
454   repalce the script with the cursor.
455   
456
457   %*******************************************************************************************************
458   %************** rules handling the case in which the cursor has a preceding node ***********************
459   %*******************************************************************************************************
460
461   %************************* the cursor's parent is a group or a parameter *******************************
462
463   %we consider an empty macro as a token. An empty macro is either undefined or simply empty.
464
465   %rule handling the case where the cursor has a preceding token and this is the first node of a group with id
466   \item{\verb+g[@id][^(i||n||o||s||c[^$])#]/cursor+}\\
467   remove the cursor and replace the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node with the $\NLDROP$.
468   \item{\verb+<g|p>[(i||n||o||s||c[^$])#]/cursor+}\\
469   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
470   %it corresponds to the drop_prev_group(false).
471   \item{\verb+<g|p>[g#]/cursor+}\\
472   remove the cursor and append the $\NLDROP$ to the \G{} node.
473   %corresponds to the drop_prev_script(false).
474   \item{\verb+<g|p>[(<sp|sb>)#]/cursor+}\\
475   remove the cursor and append the $\NLDROP$ to the \SP{} or \SB{} node.
476   %rules handling the right open macros preceding the cursor.
477   \item{\verb+<g|p>[(c[^p[@right-open='1']$])#]/cursor+}\\
478   remove the cursor and append the $\NLDROP$ to the \PNODE{} node.
479   %we don't have a macro of this kind, but we don't know the future...
480   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/cursor+}\\
481   remove the cursor and replace the \CNODE node with the $\NLDROP$.
482   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1']$])#]/cursor+}\\
483   replace the \CNODE{} node with the content of the \PNODE node and replace the cursor with the $\NLDROP$.
484   %rules handling macro with parameter(s) and preceding the cursor.
485   \item{\verb+<g|p>[c#]/cursor+}\\
486   remove the cursor and append the $\NLDROP$ to the \CNODE{} node.
487   %rule handling table with rows preceding the cursor.
488   \item{\verb+<g|p>[(table[row[cell[^g$]$]$])#]/cursor+}\\
489   remove the cursor and append the $\NLDROP$ to the \G{} node, which is child of the \CELL{} node.
490   %rule handling tables without rows preceding the cursor.
491   \item{\verb+<g|p>[table#]/cursor+}\\
492   remove the cursor and append the $\NLDROP$ to the \TABLE{} node
493
494   %********************************* the cursor's parent is a script ******************************
495
496   %rule handling the case where the script's base is an empty group with id.
497   \item{\verb+<sp|sb>[^(g[@id][^$])#$]/cursor+}\\
498   replace the \SP{} or \SB{} node with the $\NLDROP$.
499   %rule handling the case where the script's base is an empty group without id
500   \item{\verb+<sp|sb>[^(g[^$])#$]/cursor+}\\
501   replace the \SP{} or \SB{} node with the cursor.
502   %rule handling the case where the script's base is something else
503   \item{\verb+<sp|sb>[^*#$]/cursor+}\\
504   replace the \SP{} or \SB{} node with it's first child and insert the $\NLDROP$ after it.
505
506   %********************************* the cursor's parent is a macro ********************************
507
508   %rule handling the case where the preceding node is a parameter
509   \item{\verb+c[p#]/cursor+}\\
510   remove the cursor and append the $\NLDROP$ to the PNODE{} node.
511   %rule handling the case where the preceding node is a delimiter
512   \item{\verb+c[(<i|n|o|s|c>)#]/cursor+}\\
513   remove the cursor and insert the $\NLDROP$ before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
514
515   %*************************************************************************************************
516   %*********** rules handling the case in which the cursor has no preceding nodes ******************
517   %*************************************************************************************************
518
519   %rule handling the case where the cursor has something else after it
520   \item{\verb+<g|p>[#*]/cursor+}\\
521   nothing to drop.
522
523   %rules handling the case where the cursor's parent is a p node and the cursor has no nodes after it.
524
525   %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.
526   \item{\verb+c[^(p[@left-open='1'][^$])#$]/p[@right-open='1'][^#$]/cursor+}\\
527   replace the \CNODE{} with the $\NLDROP$.
528   %rule handling the case where the p node is a left and right open macro's child and the first p node has elements.
529   \item{\verb+c[^(p[@left-open='1']#$]/p[@right-open='1'][^#$]/cursor+}\\
530   replace the \CNODE{} with the content of the PNODE{} with attribute texttt{left-open='1'} and insert $\NLDROP$ after this.
531   %rule handling the case where the p node is right open macro's child.
532   \item{\verb+c[^#$]/p[@right-open='1'][^#$]/cursor+}\\
533   replace the \CNODE{} with the $\NLDROP$.
534   %rule handling the case where the p node is a macro's child and this macro has parameter.
535   \item{\verb+c/p[^#$]/cursor+}\\
536   remove the cursor and insert the $\NLDROP$ before the \PNODE{} node.
537   
538   %rule handling the case where the cursor has no nodes after it and its parent is a group with id
539   \item{\verb+g[@id][^#$]/cursor+}\\
540   replace the \G{} node with the $\NLDROP$.
541
542 \end{description}
543
544 \paragraph{Special Left Drop:} $\SLDROP$
545
546 \begin{description}
547
548   %*******************************************************************************************************
549   %************** rules handling the case in which the cursor has a preceding node ***********************
550   %*******************************************************************************************************
551
552   %************************* the cursor's parent is a group or a parameter *******************************
553
554   %this rule is more specific than the one below which handle the case of the cursor preceded by a c node
555   \item{\verb+<g|p>[(i||n||o||s||c[^$])#]/cursor+}\\
556   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
557   %it corresponds to the drop_prev_group(true).
558   \item{\verb+<g|p>[g#]/cursor+}\\
559   remove the cursor and append the it to the \G{} node.
560   %corresponds to the drop_prev_script(true).
561   \item{\verb+<g|p>[(<sp|sb>)#]/cursor+}\\
562   remove the cursor and append the $\SLDROP$ to the \SP{} or \SB{} node.
563   %rules handling the right open macros preceding the cursor.
564   \item{\verb+<g|p>[(c[^p[@right-open='1']$])#]/cursor+}\\
565   remove the cursor and append the $\SLDROP$ to the \PNODE{} node.
566   %we don't have a macro of this kind, but we don't know the future...
567   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/cursor+}\\
568   remove the cursor and replace the \CNODE node with the cursor.
569   \item{\verb+<g|p>[(c[^p[!(@right-open='1')][@left-open='1']$])#]/cursor+}\\
570   replace the \CNODE{} node with the content of the \PNODE node.
571   %rule handling macro with parameter(s) and preceding the cursor.
572   \item{\verb+<g|p>[c#]/cursor+}\\
573   remove the cursor and append the $\SLDROP$ to the \CNODE{} node.
574   %rule handling table with rows preceding the cursor.
575   \item{\verb+<g|p>[(table[row[cell[^g$]$]$])#]/cursor+}\\
576   remove the cursor and append the it to the \G{} node, which is child of the \CELL{} node.
577   %rule handling tables without rows preceding the cursor.
578   \item{\verb+<g|p>[table#]/cursor+}\\
579   remove the cursor and append the $\SLDROP$ to the \TABLE{} node
580
581   %********************************* the cursor's parent is a script ******************************
582
583   %rule handling the case where the script's base is an empty group with id.
584   \item{\verb+<sp|sb>[^(g[@id][^$])#$]/cursor+}\\
585   replace the \SP{} or \SB{} node with the \G{} node and insert the cursor after it.
586   %rule handling the case where the script's base is an empty group without id
587   \item{\verb+<sp|sb>[^(g[^$])#$]/cursor+}\\
588   replace the \SP{} or \SB{} node with the cursor.
589   %rule handling the case where the scrip's base is something else
590   \item{\verb+<sp|sb>[^*#$]/cursor+}\\
591   replace the \SP{} or \SB{} node with it's first child and insert the cursor after it.
592
593   %********************************* the cursor's parent is a macro ********************************
594
595   %rule handling the case where the preceding node is a parameter
596   \item{\verb+c[p#]/cursor+}\\
597   remove the cursor and append the $\SLDROP$ to the PNODE{} node.
598   %rule handling the case where the preceding node is a delimiter
599   \item{\verb+c[(<i|n|o|s|c>)#]/cursor+}\\
600   remove the cursor and insert the it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
601
602   %*************************************************************************************************
603   %*********** rules handling the case in which the cursor has no preceding nodes ******************
604   %*************************************************************************************************
605
606   %rule handling the case where the cursor has something else after it
607   \item{\verb+<g|p>[#*]/cursor+}\\
608   nothing to drop.
609
610   %rules handling the case where the cursor's parent is a p node and the cursor has no nodes after it.
611
612   %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.
613   \item{\verb+c[^(p[@left-open='1'][^$])#$]/p[@right-open='1'][^#$]/cursor+}\\
614   replace the \CNODE{} with the cursor.
615   %rule handling the case where the p node is a left and right open macro's child and the first p node has elements.
616   \item{\verb+c[^(p[@left-open='1']#$]/p[@right-open='1'][^#$]/cursor+}\\
617   replace the \CNODE{} with the content of the PNODE{} with attribute texttt{left-open='1'} and insert cursor after this.
618   %rule handling the case where the p node is right open macro's child.
619   \item{\verb+c[^#$]/p[@right-open='1'][^#$]/cursor+}\\
620   replace the \CNODE{} with the cursor.
621   %rule handling the case where the p node is a macro's child and this macro has parameter.
622   \item{\verb+c/p[^#$]/cursor+}\\
623   remove the cursor and insert the $\SLDROP$ before the \PNODE{} node.
624   
625   %rule handling the case where the cursor has no nodes after it and its parent is a group with id
626   \item{\verb+g[@id][^#$]/cursor+}\\
627   replace the \G{} node with the cursor.
628
629 \end{description}
630
631 \section{Right Drop Rules}
632
633 \section{$\varepsilon$-rules}
634
635 \paragraph{Nromal Left Drop}
636
637 \begin{description}
638
639
640   %********************************************* \NLDROP has a preceding node *********************************************
641
642   %rule handling the case where the preceding node is a token or an empty macro.
643   \item{\verb+*[(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
644   remove the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or the \CNODE{} node.
645   %rule handling the case where the preceding node is a group
646   \item{\verb+*[g#]/+$\NLDROP$}\\
647   remove the $\NLDROP$ append it to the \G{} node.
648   %rule handling the case where the preceding node is a script
649   \item{\verb+*[<sp|sb>#]/+$\NLDROP$}\\
650   remove the $\NLDROP$ append it to the \SP{} or \SB{} node.
651   %rule handling the case where the preceding node is an open-right macro
652   \item{\verb+*[(c[^p[@right-open='1']$])#]/+$\NLDROP$}\\
653   remove the $\NLDROP$ and append it to the \PNODE{} node.
654   %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
655   \item{\verb+*[(c[^p[!(@right-open='1')][@left-open='1'][^$]$])#]/+$\NLDROP$}\\
656   remove the \CNODE node.
657   %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
658   \item{\verb+*[(c[^p[!(@right-open='1')][@left-open='1']$])#]/+$\NLDROP$}\\
659   replace the \CNODE{} node with the content of the \PNODE{} node.
660   %rule handling the case where the preceding node is a macro with parameter(s)
661   \item{\verb+*[c#]/+$\NLDROP$}\\
662   remove the $\NLDROP$ and append it to the \CNODE{} node.
663
664   %rule handling the deletion of primes in superscript
665
666   %there are more than one prime in the phantom group
667   \item{\verb+sp[!(@id)][*#$]/g[!(@id)][o#]/+$\NLDROP$}\\
668   remove the \ONODE node, remove the $\NLDROP$ and insert the cursor after the \SP{} node.
669   %there is one and only one prime in the phantom group
670   \item{\verb+sp[!(@id)][*#$]/g[!(@id)][^o#]/+$\NLDROP$}\\
671   replace the \SP{} node with it's first child and insert the cursor after it
672
673   %*** rules handling the case where the \NLDROP's parent is a macro (with parameter) ***
674
675   %the node preceding the \NLDROP is a delimiter
676   \item{\verb+c[(<i|n|o|s|c>)#]/+$\NLDROP$}\\
677   remove the $\NLDROP$ and insert it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
678   %the node preceding the \NLDROP is parameter
679   \item{\verb+c[p#]/+$\NLDROP$}\\
680   remove the $\NLDROP$ and append it to the \PNODE{} node.
681
682   %********************************************* the \NLDROP has no preceding nodes ****************************************************
683
684   %if the \NLDROP has no preceding nodes, but has following nodes...
685   \item{\verb+<g|p>[#*]/+$\NLDROP$}\\
686   replace the $\NLDROP$ with the cursor.
687   %rule handling the case where the $\NLDROP$ is the only child of a group with id.
688   \item{\verb+g[@id][^#$]/+$\NLDROP$}\\
689   replace the \G{} node with the $\NLDROP$.
690   %\NLDROP is the first child of a macro with no inserted parameter
691   \item{\verb+c[!(p[*])][^#]/+$\NLDROP$}\\
692   replace the \CNODE{} with the $\NLDROP$.
693   %\NLDROP is the first child of a macro with some inserted parameter
694   \item{\verb+c[p[*]][^#]/+$\NLDROP$}\\
695   put the cursor in the first \PNODE{} node.
696   
697
698   %**** rule handling the case where the \NLDROP has a preceding token or a preceding empty macro, which is either undefined or empty ****
699
700   %%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
701   %\item{\verb+*[(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
702   %replace the \INODE{}, \NNODE{}, \SNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node with the cursor and remove the $\NLDROP$.
703   %%the \NLDROP's parent is a macro with argument
704   %\item{\verb+c[((!(p[@left-open='1']))&(!(p[@right-open+'1'])))][(i||n||o||s||c[^$])#]/+$\NLDROP$}\\
705   %remove the $\NLDROP$ and insert it before the \INODE{}, \NNODE{}, \ONODE{}, \SNODE{} or \CNODE{} node.
706   %%rule handling the case where the \NLDROP's parent is a phantom group, which in turn is a sp's child
707   %\item{\verb+sp[!(@id)][^*#$]/g[!(@id)][o#$]/+$\NLDROP$}\\
708   %remove the \ONODE{} node
709
710   %********************************* rules handling the case where the \NLDROP has a preceding group **************************************
711   \item{\verb+*[g#]/+$\NLDROP$}\\
712   remove the $\NLDROP$ and append it to the \G{} node.
713
714 \end{description}
715
716 \paragraph{Special Left Drop}
717
718 \begin{description}
719
720   \item{special left}\\
721
722 \end{description}
723
724 \paragraph{Advance}
725
726 \begin{description}
727   \item{\verb+g/+$\tadvance$}\\
728   replace $\tadvance$ with the cursor
729
730   \item{\verb+p[#$]/+$\tadvance$}\\ %$
731   put $\tadvance$ after the \PNODE{} node
732
733   \item{\verb+c[#p]/+$\tadvance$} \\
734   remove $\tadvance$, put the cursor as first child of the \PNODE{} node
735
736   \item{\verb+c[#*]/+$\tadvance$} \\ %$
737   replace $\tadvance$ with the cursor 
738
739   \item{\verb+c[#$]/+$\tadvance$} \\ %$
740   move $\tadvance$ after the \CNODE{} node
741 \end{description}
742
743 \paragraph{Next Parameter}
744
745 \paragraph{Next Token}
746
747 %% \begin{description}
748 %%   \item{\verb+c[#p]/+$\tnext$} \\
749 %% \end{description}
750
751 % g[@id]/(c[#$][@right-open]/g[!@id][#$]/)+cursor  }   let p = cursor.parent() in remove; advance(p)
752
753 % c/g[!@id]/cursor
754 % c/cursor 
755 % */cursor  {   let g = new group in replace
756
757 % g[@id][^#$]/cursor  <=   cursor.parent().replace(cursor)
758 % g[@id][^#$]/cursor  <-   cursor
759 % (!g[@id][^#$])[A#B]/(g[@id][^#$]/)+cursor  <-  (!g[@id][^#$])[A#B]/cursor  
760
761 \end{document}