2 <!-- ============ User Notation ====================== -->
3 <chapter id="sec_usernotation">
4 <title>Extending the syntax</title>
7 <title>notation</title>
8 <titleabbrev>notation</titleabbrev>
9 <para><userinput>notation usage "presentation" associativity with precedence p for content</userinput></para>
12 <varlistentry role="tactic.synopsis">
13 <term>Synopsis:</term>
15 <para><emphasis role="bold">notation</emphasis>
16 [&usage;] <emphasis role="bold">"</emphasis>¬ation_lhs;<emphasis role="bold">"</emphasis> [&associativity;] <emphasis role="bold">with</emphasis> <emphasis role="bold">precedence</emphasis> &nat;
17 <emphasis role="bold">for</emphasis>
25 <para>Declares a mapping between the presentation
26 AST <command>presentation</command> and the content AST
27 <command>content</command>. The declared presentation AST fragment
28 <command>presentation</command> is at precedence level
29 <command>p</command>. The precedence level is used to determine where
30 parentheses must be inserted. In particular, the content AST fragment
31 <command>content</command> is actually a pattern, since it contains
32 placeholders (variables) for sub-ASTs. Every placeholder for a term
33 is given an expected precedence level. Parentheses must be inserted
34 around sub-ASTs having a precedence level strictly smaller than the
36 <para>If <command>presentation</command> describes a binary
37 infix operator and if no precedence level is explicitly given for the
38 operator arguments, an <command>associativity</command> declaration
39 can be given to automatically choose the right level for the operands.
40 Otherwise, no <command>associativity</command> can be given.</para>
41 <para>If <command>direction</command> is
42 omitted, the mapping is bi-directional and is used both during
43 parsing and pretty-printing of terms. If <command>direction</command>
44 is <command>></command>, the mapping is used only during parsing;
45 if it is <command><</command>, it is used only during
46 pretty-printing. Thus it is possible to use simple notations to type
47 for writing the term, and nicer ones for rendering it.</para>
51 <term>Notation arguments:</term>
54 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
59 <entry id="grammar.usage">&usage;</entry>
61 <entry><emphasis role="bold"><</emphasis></entry>
62 <entry>Only for pretty-printing</entry>
67 <entry><emphasis role="bold">></emphasis></entry>
68 <entry>Only for parsing</entry>
74 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
75 <title>associativity</title>
79 <entry id="grammar.associativity">&associativity;</entry>
81 <entry><emphasis role="bold">left</emphasis> <emphasis role="bold">associative</emphasis></entry>
82 <entry>Left associative</entry>
87 <entry><emphasis role="bold">right</emphasis> <emphasis role="bold">associative</emphasis></entry>
88 <entry>Right associative</entry>
93 <entry><emphasis role="bold">non</emphasis> <emphasis role="bold">associative</emphasis></entry>
94 <entry>Non associative (default)</entry>
100 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
101 <title>notation_rhs</title>
105 <entry id="grammar.notation_rhs">¬ation_rhs;</entry>
107 <entry>&unparsed_ast;</entry>
108 <entry>&TODO;</entry>
113 <entry>&unparsed_meta;</entry>
114 <entry>&TODO;</entry>
120 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
121 <title>unparsed_ast</title>
125 <entry id="grammar.unparsed_ast">&unparsed_ast;</entry>
127 <entry><emphasis role="bold">@{</emphasis>&enriched_term;<emphasis role="bold">}</emphasis></entry>
128 <entry>A content level AST (a term which is parsed, but not disambiguated).</entry>
133 <entry><emphasis role="bold">@</emphasis>&id;</entry>
134 <entry><command>@id</command> is just an abbreviation for <command>@{id}</command></entry>
139 <entry><emphasis role="bold">@</emphasis>&csymbol;</entry>
140 <entry><command>@'symbol</command> is just an abbreviation for <command>@{'symbol}</command></entry>
146 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
147 <title>enriched_term</title>
151 <entry id="grammar.enriched_term">&enriched_term;</entry>
153 <entry>〈〈A term that may contain occurrences of &unparsed_meta;, even as variable names in binders, and occurrences of &csymbol;〉〉</entry>
154 <entry>&TODO;</entry>
160 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
161 <title>unparsed_meta</title>
165 <entry id="grammar.unparsed_meta">&unparsed_meta;</entry>
167 <entry><emphasis role="bold">${</emphasis>&level2_meta;<emphasis role="bold">}</emphasis></entry>
168 <entry>&TODO;</entry>
173 <entry><emphasis role="bold">$</emphasis>&id;</entry>
174 <entry><command>$id</command> is just an abbreviation for <command>${id}</command></entry>
179 <entry><emphasis role="bold">$</emphasis><emphasis role="bold">_</emphasis></entry>
180 <entry><command>$_</command> is just an abbreviation for <command>${_}</command></entry>
186 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
187 <title>level2_meta</title>
191 <entry id="grammar.level2_meta">&level2_meta;</entry>
193 <entry>&unparsed_ast;</entry>
194 <entry>&TODO;</entry>
199 <entry><emphasis role="bold">term</emphasis> &nat; &id;</entry>
200 <entry>&TODO;</entry>
205 <entry><emphasis role="bold">number</emphasis> &id;</entry>
206 <entry>&TODO;</entry>
211 <entry><emphasis role="bold">ident</emphasis> &id;</entry>
212 <entry>&TODO;</entry>
217 <entry><emphasis role="bold">fresh</emphasis> &id;</entry>
218 <entry>&TODO;</entry>
223 <entry><emphasis role="bold">anonymous</emphasis></entry>
224 <entry>&TODO;</entry>
230 <entry>&TODO;</entry>
235 <entry><emphasis role="bold">fold</emphasis> [<emphasis role="bold">left</emphasis>|<emphasis role="bold">right</emphasis>] &level2_meta; <emphasis role="bold">rec</emphasis> &id; &level2_meta;</entry>
236 <entry>&TODO;</entry>
241 <entry><emphasis role="bold">default</emphasis> &level2_meta; &level2_meta;</entry>
242 <entry>&TODO;</entry>
247 <entry><emphasis role="bold">if</emphasis> &level2_meta; <emphasis role="bold">then</emphasis> &level2_meta; <emphasis role="bold">else</emphasis> &level2_meta;</entry>
248 <entry>&TODO;</entry>
253 <entry><emphasis role="bold">fail</emphasis></entry>
254 <entry>&TODO;</entry>
260 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
261 <title>notation_lhs</title>
265 <entry id="grammar.notation_lhs">¬ation_lhs;</entry>
267 <entry>&layout; [&layout;]…</entry>
273 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
274 <title>layout</title>
278 <entry id="grammar.layout">&layout;</entry>
280 <entry>&layout; <emphasis role="bold">\sub</emphasis> &layout;</entry>
281 <entry>Subscript</entry>
286 <entry>&layout; <emphasis role="bold">\sup</emphasis> &layout;</entry>
287 <entry>Superscript</entry>
292 <entry>&layout; <emphasis role="bold">\below</emphasis> &layout;</entry>
298 <entry>&layout; <emphasis role="bold">\above</emphasis> &layout;</entry>
304 <entry>&layout; <emphasis role="bold">\over</emphasis> &layout;</entry>
310 <entry>&layout; <emphasis role="bold">\atop</emphasis> &layout;</entry>
316 <entry>&layout; <emphasis role="bold">\frac</emphasis> &layout;</entry>
317 <entry>Fraction</entry>
322 <entry><emphasis role="bold">\infrule</emphasis> &layout; &layout; &layout;</entry>
323 <entry>Inference rule (premises, conclusion, rule name)</entry>
328 <entry><emphasis role="bold">\sqrt</emphasis> &layout;</entry>
329 <entry>Square root</entry>
334 <entry><emphasis role="bold">\root</emphasis> &layout; <emphasis role="bold">\of</emphasis> &layout;</entry>
335 <entry>Generalized root</entry>
340 <entry><emphasis role="bold">hbox</emphasis> <emphasis role="bold">(</emphasis> &layout; [&layout;]… <emphasis role="bold">)</emphasis></entry>
341 <entry>Horizontal box</entry>
346 <entry><emphasis role="bold">vbox</emphasis> <emphasis role="bold">(</emphasis> &layout; [&layout;]… <emphasis role="bold">)</emphasis></entry>
347 <entry>Vertical box</entry>
352 <entry><emphasis role="bold">hvbox</emphasis> <emphasis role="bold">(</emphasis> &layout; [&layout;]… <emphasis role="bold">)</emphasis></entry>
353 <entry>Horizontal and vertical box</entry>
358 <entry><emphasis role="bold">hovbox</emphasis> <emphasis role="bold">(</emphasis> &layout; [&layout;]… <emphasis role="bold">)</emphasis></entry>
359 <entry>Horizontal or vertical box</entry>
364 <entry><emphasis role="bold">break</emphasis></entry>
365 <entry>Breakable space</entry>
370 <entry><emphasis role="bold">(</emphasis> &layout; [&layout;]… <emphasis role="bold">)</emphasis></entry>
377 <entry>Placeholder for a term with no explicit precedence</entry>
382 <entry><emphasis role="bold">term</emphasis> &nat; &id;</entry>
383 <entry>Placeholder for a term with explicit expected precedence</entry>
388 <entry><emphasis role="bold">number</emphasis> &id;</entry>
389 <entry>Placeholder for a natural number</entry>
394 <entry><emphasis role="bold">ident</emphasis> &id;</entry>
395 <entry>Placeholder for an identifier</entry>
400 <entry>&literal;</entry>
401 <entry>Literal</entry>
406 <entry><emphasis role="bold">opt</emphasis> &layout;</entry>
407 <entry>Optional layout (it can be omitted for parsing)</entry>
412 <entry><emphasis role="bold">list0</emphasis> &layout;
413 [<emphasis role="bold">sep</emphasis> &literal;]</entry>
414 <entry>List of layouts separated by <command>sep</command> (default:
421 <entry><emphasis role="bold">list1</emphasis> &layout;
422 [<emphasis role="bold">sep</emphasis> &literal;]</entry>
423 <entry>Non empty list of layouts separated by <command>sep</command>
424 (default: any blank)</entry>
430 <entry><emphasis role="bold">mstyle</emphasis> &id; value (&layout;)
432 <entry>Style attributes like color #ff0000</entry>
438 <entry><emphasis role="bold">mpadded</emphasis> &id; value (&layout;)
440 <entry>padding attributes like width -150%</entry>
446 <entry><emphasis role="bold">maction</emphasis> (&layout;)
449 <entry>Alternative notations (output only)</entry>
457 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
458 <title>literal</title>
462 <entry id="grammar.literal">&literal;</entry>
464 <entry>&symbol;</entry>
465 <entry>Unicode symbol</entry>
471 <entry>Natural number (a constant)</entry>
476 <entry><emphasis role="bold">'</emphasis>&id;<emphasis role="bold">'</emphasis></entry>
477 <entry>New keyword for the lexer</entry>
489 <title>interpretation</title>
490 <titleabbrev>interpretation</titleabbrev>
491 <para><userinput>interpretation "description" 'symbol p<subscript>1</subscript> … p<subscript>n</subscript> =
492 rhs</userinput></para>
493 <para id="interpretation">
495 <varlistentry role="tactic.synopsis">
496 <term>Synopsis:</term>
498 <para><emphasis role="bold">interpretation</emphasis>
499 &qstring; &csymbol; [&interpretation_argument;]…
500 <emphasis role="bold">=</emphasis>
508 <para>It declares a bi-directional mapping <command>{…}</command> between the content-level AST <command>'symbol t<subscript>1</subscript> … t<subscript>n</subscript></command> and the semantic term <command>rhs[{t<subscript>1</subscript>}/p<subscript>1</subscript>;…;{t<subscript>n</subscript>}/p<subscript>n</subscript>]</command>
509 (the simultaneous substitution in <command>rhs</command> of the
510 interpretation <command>{…}</command> of every content-level
511 actual argument <command>t<subscript>i</subscript></command> for its
512 corresponding formal parameter
513 <command>p<subscript>i</subscript></command>). The
514 <command>description</command> must be a textual description of the
515 meaning associated to <command>'symbol</command> by this
516 interpretation, and is used by the user interface of Matita to
517 provide feedback on the interpretation of ambiguous terms.
522 <term>Interpretation arguments:</term>
525 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
526 <title>interpretation_argument</title>
530 <entry id="grammar.interpretation_argument">&interpretation_argument;</entry>
532 <entry>[<emphasis role="bold">η</emphasis><emphasis role="bold">.</emphasis>]… &id;</entry>
533 <entry>A formal parameter. If the name of the formal parameter is
534 prefixed by n symbols "η", then the mapping performs
535 (multiple) η-expansions to grant that the semantic actual
536 parameter begins with at least n λ-abstractions.</entry>
541 <table frame="topbot" rowsep="0" colsep="0" role="grammar">
542 <title>interpretation_rhs</title>
546 <entry id="grammar.interpretation_rhs">&interpretation_rhs;</entry>
549 <entry>A constant, specified by its URI</entry>
555 <entry>A constant, specified by its name, or a bound variable. If
556 the constant name is ambiguous, the one corresponding to the
557 last implicitly or explicitly specified alias is used.</entry>
562 <entry><emphasis role="bold">?</emphasis></entry>
563 <entry>An implicit parameter</entry>
568 <entry><emphasis role="bold">(</emphasis>
570 [&interpretation_rhs;]…
571 <emphasis role="bold">)</emphasis></entry>
572 <entry>An application</entry>