diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-08-12 07:19:43 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-08-12 07:19:43 -0700 |
commit | 632deb8aa26bec72d3b5b9d920551239a3e5f559 (patch) | |
tree | 8d351a791b3d006109ba9180df95db2e1f608630 | |
parent | 08bd6d07429bfaa2abd6ddccc4812272eb0b08cb (diff) | |
download | txr-632deb8aa26bec72d3b5b9d920551239a3e5f559.tar.gz txr-632deb8aa26bec72d3b5b9d920551239a3e5f559.tar.bz2 txr-632deb8aa26bec72d3b5b9d920551239a3e5f559.zip |
Revision to .. syntax.
* parser.y (r_exprs, n_expr): Move the DOTDOT syntactic sugar rule from
r_exprs to n_expr, where it is much simpler. This also means that the
a..b syntax is now an expression by itself; it need not be enclosed in
a list. The DOTDOT operator is made right associative; or rather
its existing %right declaration is now activated.
* txr.1: Remove documentation stating that the .. notation must
be used in a list, and not in the dotted position of an improper
list. Document the behavior in the dotted position, and document
right associativity.
-rw-r--r-- | parser.y | 13 | ||||
-rw-r--r-- | txr.1 | 36 |
2 files changed, 18 insertions, 31 deletions
@@ -763,16 +763,6 @@ r_exprs : n_expr { val exprs = cons($1, nil); misplaced_consing_dot_check(scnr, term_atom_cons); rplaca(term_atom_cons, $3); $$ = $1; } - | r_exprs DOTDOT n_expr { uses_or2; - val term_atom_cons = $1; - val exprs = cdr($1); - misplaced_consing_dot_check(scnr, term_atom_cons); - rplacd(term_atom_cons, - rlcp(cons(list(cons_s, car(exprs), - $3, nao), - cdr(exprs)), - or2($3, exprs))); - $$ = term_atom_cons; } | WSPLICE wordslit { $$ = cons(nil, nreverse(rl($2, num($1)))); rlcp($$, cdr($$)); } | r_exprs WSPLICE @@ -816,6 +806,9 @@ n_expr : SYMTOK { $$ = symhlpr($1, t); } num(parser->lineno)); } | SPLICE n_expr { $$ = rl(rlcp(list(sys_splice_s, $2, nao), $2), num(parser->lineno)); } + | n_expr DOTDOT n_expr { uses_or2; + $$ = rlcp(list(cons_s, $1, $3, nao), + or2($1, $3)); } | n_expr '.' n_expr { uses_or2; if (consp($3) && car($3) == qref_s) { rplacd($3, rlcp(cons($1, cdr($3)), $1)); @@ -9509,28 +9509,22 @@ computes a sublist of consisting of elements 1 through 2 (counting from zero). -Restrictions: - -The notation must be enclosed in a list. For instance -.code a..b -is not, by itself, an -expression, but -.code (a..b) -is. This is important if Lisp data is being parsed from -a string or stream using the read function. If the data -.str "a..b" -is parsed, the symbol -.code a -will be extracted, leaving -.strn ..a , -which, if parsed, -produces a syntax error since it consists of a "dotdot" token followed by -a symbol, which is not valid syntax. - -The notation cannot occur in the dot position; that is, the syntax +Note that if this notation is used in the dot position of an improper +list, the transformation still applies. That is, the syntax .code (a . b .. c) -is invalid. The dotdot operator can only be used between the non-dot-position -elements of a list. +is valid and produces the object +.code (a . (cons b c)) +which is another way of writing +.codn (a cons b c) . + +The notation's +.code .. +operator associates right to left, so that +.code a..b..c +denotes +.code (cons a (cons b c)) +or +.codn (a b . c) . .NP* The DWIM Brackets \*(TL has a square bracket notation. The syntax |