ref: ee58f398fec62d3096b0e01da51a3969ed37a32d
parent: b71e694a565be65d648cd3b70d938b4417622782
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jun 18 19:36:29 EDT 2024
make {} synonyms to (), in addition to []
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
Some of the changes from the original include:
* aggressive clean up and removal (like Windows and Mac OS X support)
- * `[` and `]` are synonyms to `(` and `)`
+ * `[` and `]`, `{` and `}` are synonyms to `(` and `)`
* some of the previously available (but not merged) patches from the community and [Julia](https://github.com/JuliaLang/julia) are applied
* "boot" image is built into the executable
* vm opcode definitions and tables are generated from a single file
--- a/read.c
+++ b/read.c
@@ -7,7 +7,8 @@
TOK_NONE, TOK_OPEN, TOK_CLOSE, TOK_DOT, TOK_QUOTE, TOK_SYM, TOK_NUM,
TOK_BQ, TOK_COMMA, TOK_COMMAAT, TOK_COMMADOT,
TOK_SHARPDOT, TOK_LABEL, TOK_BACKREF, TOK_SHARPQUOTE, TOK_SHARPOPEN,
- TOK_OPENB, TOK_CLOSEB, TOK_SHARPSYM, TOK_GENSYM, TOK_DOUBLEQUOTE
+ TOK_OPENB, TOK_CLOSEB, TOK_SHARPSYM, TOK_GENSYM, TOK_DOUBLEQUOTE,
+ TOK_OPENC, TOK_CLOSEC,
};
#if defined(__plan9__)
@@ -264,6 +265,10 @@
toktype = TOK_OPENB;
else if(c == ']')
toktype = TOK_CLOSEB;
+ else if(c == '{')
+ toktype = TOK_OPENC;
+ else if(c == '}')
+ toktype = TOK_CLOSEC;
else if(c == '\'')
toktype = TOK_QUOTE;
else if(c == '`')
@@ -405,8 +410,6 @@
else
return toktype;
ios_getc(F);
- }else if(c == '{' || c == '}'){
- lerrorf(ParseError, "invalid character %c", c);
}else{
if(!read_token(c, 0)){
if(buf[0] == '.' && buf[1] == '\0')
@@ -592,7 +595,11 @@
lerrorf(ParseError, "unexpected end of input");
if(t != closer){
take();
- lerrorf(ParseError, "expected '%c'", closer == TOK_CLOSEB ? ']' : ')');
+ lerrorf(
+ ParseError,
+ "expected '%c'",
+ closer == TOK_CLOSEB ? ']' : (closer == TOK_CLOSEC ? '}' : ')')
+ );
}
}
}
@@ -617,6 +624,8 @@
lerrorf(ParseError, "unexpected ')'");
case TOK_CLOSEB:
lerrorf(ParseError, "unexpected ']'");
+ case TOK_CLOSEC:
+ lerrorf(ParseError, "unexpected '}'");
case TOK_DOT:
lerrorf(ParseError, "unexpected '.'");
case TOK_SYM:
@@ -653,6 +662,10 @@
case TOK_OPENB:
PUSH(NIL);
read_list(&Stack[SP-1], label, TOK_CLOSEB);
+ return POP();
+ case TOK_OPENC:
+ PUSH(NIL);
+ read_list(&Stack[SP-1], label, TOK_CLOSEC);
return POP();
case TOK_SHARPSYM:
sym = tokval;