0adac9baba91c77604a1fd8889711c619dc12081
[m17n/m17n-lib-cs.git] / xex.txt
1 EXPR =
2   '<expr>' [ DEFUN | DEFMACRO | DEFVAR | TERM ] * '</expr>'
3
4 TERM = [ INT | STRING | SYMBOL | LIST | ERROR | VARREF | FUNCALL ]
5
6 DEFUN =
7   '<defun fname="' FNAME '">'
8   ARGS ?
9   TERM *
10   '</defun>'
11
12 DEFMACRO =
13   '<defmacro fname="' FNAME '">'
14   ARGS ?
15   TERM *
16   '</defmacro>'
17
18 ARGS =
19   '<args>' FIXED * OPTIONAL * REST ? '</args>'
20
21 FIXED =
22   '<fixed vname="' VNAME '">'
23
24 OPTIONAL =
25   '<optional vname="' VNAME '">'
26
27 REST =
28   '<rest vname="' VNAME '">'
29
30 DEFVAR = DEFVAR-INT | DEFVAR-STR | DEFVAR-SYM
31
32 DEFVAR-INT =
33   '<defvar vname="' VNAME '">'
34   DESCRIPTION ?
35   [ INT POSSIBLE-INT-VALUE ? ] ?
36   '</defvar>'
37
38 POSSIBLE-INT-VALUE =
39   <possible-value> [ INT | '<range>' INT INT '</range>' ] + </possible-value>
40
41 DEFVAR-STR =
42   '<defvar vname"' VNAME '">'
43   DESCRIPTION ?
44   [ STR DEFVAR-STR_VALUE ? ] ?
45   '</defvar>'
46
47 DEFVAR-STR_VALUE =
48   <possible-value> STR + </possible-value>
49
50 DEFVAR-SYM =
51   '<defvar vname"' VNAME '">'
52   DESCRIPTION ?
53   [ SYMBOL POSSIBLE-SYM-VALUE ? ] ?
54   '</defvar>'
55
56 POSSIBLE-SYM-VALUE =
57   <possible-value> SYMBOL + </possible-value>
58
59 DESCRIPTION =
60   '<description>' [ TEXT | GETTEXT ] '</description>'
61
62 GETTEXT =
63   '<gettext>' TEXT '</gettext>'
64
65 INT =
66   '<integer>' INTEGER '</integer>'
67 STR =
68   '<string>' STRING '</string>'
69 SYMBOL =
70   '<symbol>' NAME '</symbol>'
71 LIST =
72   '<list>' TERM * '</list>'
73 ERROR =
74   [ '<error>' | '<error ename="' ENAME '">"' ] STRING '</error>'
75
76 VARREF =
77   '<varref vname="' VNAME '"/>'
78
79 FUNCALL =
80   '<funcall fname="' FNAME '">' TERM * '</funcall>'
81   | PREDEFINED
82
83 PREDEFINED =
84   SET
85   | AND | OR | NOT | EQ | NOTEQ | EQUAL | MATCH
86   | LT | LE | GE | GT
87   | ADD | SUB | MUL | DIV | MOD
88   | LOGAND | LOGIOR | LOGXOR | LSH
89   | APPEND | CONCAT | LENGTH | NTH  | COPY | INS | DEL
90   | PROGN | IF | WHEN | COND
91   | LOOP | WHILE | FOREACH | BREAK | RETURN | CATCH | THROW
92   | QUOTE | EVAL | TYPE
93
94 ;; TERM contains an object, and is evaluated to a TERM as below.
95 ;; INT contains an integer, and is evaluated to itself .
96 ;;   Two integers of the same value are regarded as the same object.
97 ;; STRING contains a string, and is evaluated to itself.
98 ;; SYMBOL contains a named symbol, and is evaluated to itself.
99 ;;   Two symbols of the same name are reguarded as the same object.
100 ;; LIST contains a list and, is evaluated to itself.
101 ;; ERROR contains an error type symbol and an error message (optional).
102 ;; VARREF contains a variable, and is evalued to the value of that variable.
103 ;; FUNCALL contains a function and arguments to it, and is evalued to the
104 ;; value of function called with those arguments.
105
106 INTTERM = INT | VAR (value is INT) | FUNCALL (return INT)
107 STRTERM = STR | VAR (value is STR) | FUNCALL (return STR)
108 SYMTERM = SYMBOL | VAR (value is SYMBOL) | FUNCALL (return SYMBOL)
109 LISTTERM = LIST | VAR (value is LIST) | FUNCALL (return LIST)
110 XXXTERM = TERM
111
112 ;; Here after, when an argument written as TERM, it is given to a
113 ;; function without being evaluted.  Otherwise, an evaluated term is
114 ;; given.  "the value is NUM" means "the value is
115 ;; <integer>NUM</integer>".
116
117 SET = '<set vname="' VNAME '">' XXXTERM '</set>'
118
119 ;; Set the value of the variable VNAME to XXXTERM, and the value is
120 ;; XXXTERM.
121
122 ADD = '<add>' INTTERM + '</add>'
123       | '<add vname="' VNAME '">' INTTERM + '</add>'
124 SUB = '<sub>' INTTERM + '</sub>'
125       | '<sub vname="' VNAME '">' INTTERM + '</sub>'
126 MUL = '<mul>' INTTERM + '</mul>'
127       | '<mul vname="' VNAME '">' INTTERM + '</mul>'
128 DIB = '<div>' INTTERM + '</div>'
129       | '<div vname="' VNAME '">' INTTERM + '</div>'
130 MOD = '<mod>' INTTERM INTTERM '</mod>'
131       | '<mod vname="' VNAME '">' INTTERM '</div>'
132 LOGAND = '<logand> INTTERM + '</logand>'
133          | '<logand vname="' VNAME '">' INTTERM + '</logand>'
134 LOGIOR = '<logior> INTTERM + '</logior>'
135          | '<logior vname="' VNAME '">' INTTERM + '</logior>'
136 LOGXOR = '<logxor> INTTERM + '</logxor>'
137          | '<logxor vname="' VNAME '">' INTTERM + '</logxor>'
138 LSH = '<lsh>' INTTERM INTTERM '</lsh>'
139       | '<lsh vname="' VNAME '">' INTTERM '</mul>'
140 LT = '<lt>' INTTERM INTTERM '</lt>'
141 LE = '<le>' INTTERM INTTERM '</le>'
142 GE = '<ge>' INTTERM INTTERM '</ge>'
143 GT ='<gt>' INTTERM INTTERM '</gt>'
144
145 EQ = '<eq>' XXXTERM + '</eq>'
146
147 ;; If XXXTERMs have the same object, the value is 1.  Otherwise the
148 ;; value is 0.
149
150 NOTEQ = '<noteq>' XXXTERM XXXTERM '</noteq>'
151
152 ;; If XXXTERMs have the same object, the value is 0.  Othersise the
153 ;; value is 1.
154
155 APPEND = '<append>' XXXTERM + '</append>'
156          | '<append vname=" VNAME '">' XXXTERM + '</append>'
157
158 ;; In the first form, the value is a LIST made by concatinating all
159 ;; elements of XXXTERM (if it is a LIST) or XXXTERM itself (if it is
160 ;; not a LIST) in the specified order.
161
162 ;; In the second form, the value of the variable VNAME must be a LIST,
163 ;; and that LIST is modified destructively by concatinating ANYterms
164 ;; in the same manner as the previous case.  The value is the
165 ;; resulting LIST.
166
167 CONCAT = '<concat>' [ STRTERM | INTTERM | LISTTERM ] + '</concat>'
168          | '<concat vname=" VNAME '">' [ STRTERM | INTTERM | LISTTERM ] + '</concat>'
169
170 ;; In the first form, the value is a STR made by concatinating all
171 ;; the strings made from the arguments as below:
172 ;;    STRTERM gives a string contained in it.
173 ;;    INTTERM gives a string of a character whose code is INTTERM's integer.
174 ;;    LISTTERM must contain only INTTERMs, and give a string containing
175 ;;      characters whose codes are INTTERM's integer.
176
177 ;; In the second form, the value of the variable VNAME must be a STR,
178 ;; and that STR is modified destructively by concatinating the
179 ;; arguments in the same manner as the previous case.  The value is
180 ;; the resulting STR.
181
182 LENGTH = '<length>' [ STRTERM | LISTTERM ] '</length>'
183 NTH = '<nth>' INTTERM [ STRTERM | LISTTERM ] '</nth>'
184 COPY = '<copy>' LISTTERM '</nth>'
185 INS = '<ins vname="' VNAME '">' INTTERM [ STRTERM | LISTTERM ] '</ins>'
186 DEL = '<del vname="' VNAME '">' INTTERM INTTERM '</ins>'
187
188 AND = '<and>' TERM + '</and>'
189
190 ;; Evaluates TERMs one by one until one is evaluated to 0.  If none is
191 ;; evaluated to 0, the value is 1.  Othersise the value is 0.
192
193 OR = '<or>' TERM + '</or>'
194
195 ;; Evaluates TERMs one by one until one is evaluated not to 0.  If
196 ;; none is evaluated not to 0, the value is 0.  Othersise the value is
197 ;; 1.
198
199 NOT = '<not>' XXXTERM '</not>'
200
201 ;; If XXX is 0, the value is 1.  Othersise the value is 0.
202
203 EQUAL = '<equal>' XXXTERM1 XXXTERM2 '</equal>'
204
205 ;; If XXX1 equals to XXX2, the value is 1.  Otherwise the value is 0.
206 ;; The equality of terms is decided as below:
207 ;;   INT: INT1 equals to INT2 iff they contain the same integer values.
208 ;;   STR: STR1 equals to STR2 iff they contain strings of the same characters.
209 ;;   SYM: SYM1 equals to SSYM2 iff they contain the same symbol.
210 ;;   LIST: LIST1 equals to LIST2 iff they have the same length, and
211 ;;     the Nth element of LIST1 equals to the Nth element of LIST2.
212
213 MATCH = '<match>' XXXTERM1 XXXTERM2 <'/match>'
214
215 ;; If XXX1 matches with XXX2, the value is 1.  Otherwise the value is
216 ;; 0.  Two terms match as below:
217 ;;   INT: INT1 matches with INT2 iff they contain the same integer values.
218 ;;   STR: STR1 matches with STR2 iff STR1's string is a valid regular
219 ;;      expression matching with STR2's string
220 ;;   SYM: SYM1 matches with SSYM2 iff they contain the same symbol.
221 ;;   LIST: LIST1 matches with LIST2 iff LIST1 is not longer than
222 ;;     LIST2, and Nth element of LIST1 equals to Nth element of LIST2.
223 ;;   ERROR: ERROR1 matches with ERROR2 iff ERROR1's error type is
224 ;;     <symbol/> or is the same as ERROR2's error type.
225
226 PROGN = '<progn>' TERM * '</progn>'
227 IF = '<if>' TERM TERM TERM ? '</if>'
228 WHEN = '<when>' TERM TERM * '</when>'
229 COND = '<cond>' LIST + '</cond>'
230 LOOP = '<loop>' TERM + '</loop>'
231 WHILE = '<while>' TERM + '</while>'
232 FOREACH = '<foreach vname="' VNAME '">' [STRTERM | LISTTERM] TERM + '</foreach>'
233 BREAK = '<break>' TERM ? '</break>'
234 RETURN = '<return>' TERM ? '</return>'
235 QUOTE = '<quote>' TERM '</quote>'
236
237 CATCH = '<catch>' [ SYMBOL | ERROR ] TERM + '</catch>'
238         | '<catch vname="' VNAME '">' [ SYMBOL | ERROR ] TERM + '</catch>'
239
240 ;; Evaluate TERMs one by one until a term matching with the specified
241 ;; SYMBOL or ERROR is thrown by <throw/>.  If thrown, the value is 1,
242 ;; otherwise the value is 0.  If VNAME is specified, its value is set
243 ;; to the last evaluated term.  It is the value of <throw/> if thrown.
244
245 THROW = '<throw>' SYMBOL XXXTERM ? '</throw>'
246         | '<throw>' ERROR '</throw>'
247
248 ;; Throw to the catch for SYMBOL or ERROR.  The value is XXXTERM (if
249 ;; any) or SYMBOL in the first form, and ERROR in the second form.
250
251 EVAL = '<eval>' TERM '</eval>'
252
253 TYPE = '<type>' XXXTERM '</type>'
254
255 ;; The value is SYM representing the type of XXXTERM as below:
256 ;;   INT: the type is <symbol>integer</symbol>
257 ;;   STR: the type is <symbol>string</symbol>
258 ;;   SYM: the type is <symbol>symbol</symbol>
259 ;;   LIST: the type is <symbol>list</symbol>
260 ;;   ERROR: the type is <symbol>error</symbol>