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