optional BraceExp ReaderExpDef
This commit is contained in:
@@ -666,6 +666,8 @@ class Helpers {
|
|||||||
CallExp(recurse(func), evalUnquoteLists(callArgs, innerRunAtCompileTime).map(recurse));
|
CallExp(recurse(func), evalUnquoteLists(callArgs, innerRunAtCompileTime).map(recurse));
|
||||||
case ListExp(elements):
|
case ListExp(elements):
|
||||||
ListExp(evalUnquoteLists(elements, innerRunAtCompileTime).map(recurse));
|
ListExp(evalUnquoteLists(elements, innerRunAtCompileTime).map(recurse));
|
||||||
|
case BraceExp(elements):
|
||||||
|
BraceExp(evalUnquoteLists(elements, innerRunAtCompileTime).map(recurse));
|
||||||
case TypedExp(type, innerExp):
|
case TypedExp(type, innerExp):
|
||||||
TypedExp(type, recurse(innerExp));
|
TypedExp(type, recurse(innerExp));
|
||||||
case FieldExp(field, innerExp, safe):
|
case FieldExp(field, innerExp, safe):
|
||||||
@@ -764,6 +766,8 @@ class Helpers {
|
|||||||
CallExp(func(f), Lambda.map(args, func));
|
CallExp(func(f), Lambda.map(args, func));
|
||||||
case ListExp(args):
|
case ListExp(args):
|
||||||
ListExp(Lambda.map(args, func));
|
ListExp(Lambda.map(args, func));
|
||||||
|
case BraceExp(args):
|
||||||
|
BraceExp(Lambda.map(args, func));
|
||||||
case TypedExp(type, exp):
|
case TypedExp(type, exp):
|
||||||
TypedExp(type, func(exp));
|
TypedExp(type, func(exp));
|
||||||
case MetaExp(meta, exp):
|
case MetaExp(meta, exp):
|
||||||
|
|||||||
@@ -31,10 +31,16 @@ typedef HasReadTables = {
|
|||||||
identAliases:Map<String,ReaderExpDef>
|
identAliases:Map<String,ReaderExpDef>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef ReadTableOptions = {
|
||||||
|
// When this is false (the default), {<...>} always becomes (begin <...>) instead of BraceExp(<...>)
|
||||||
|
?keepBraceExps:Bool
|
||||||
|
};
|
||||||
|
|
||||||
@:allow(kiss.Helpers)
|
@:allow(kiss.Helpers)
|
||||||
class Reader {
|
class Reader {
|
||||||
// The built-in readtable
|
// The built-in readtable
|
||||||
public static function builtins() {
|
public static function builtins(?options:ReadTableOptions) {
|
||||||
|
if (options == null) options = {};
|
||||||
var readTable:ReadTable = [];
|
var readTable:ReadTable = [];
|
||||||
|
|
||||||
readTable["("] = (stream, k) -> {
|
readTable["("] = (stream, k) -> {
|
||||||
@@ -49,9 +55,13 @@ class Reader {
|
|||||||
readTable["[::"] = (stream, k) -> ListEatingExp(_readExpArray(stream, "]", k));
|
readTable["[::"] = (stream, k) -> ListEatingExp(_readExpArray(stream, "]", k));
|
||||||
readTable["..."] = (stream, k) -> ListRestExp(nextToken(stream, "name for list-eating rest exp", true));
|
readTable["..."] = (stream, k) -> ListRestExp(nextToken(stream, "name for list-eating rest exp", true));
|
||||||
|
|
||||||
|
if (options.keepBraceExps) {
|
||||||
|
readTable["{"] = (stream, k) -> BraceExp(_readExpArray(stream, "}", k));
|
||||||
|
} else {
|
||||||
// Provides a nice syntactic sugar for (if... {<then block...>} {<else block...>}),
|
// Provides a nice syntactic sugar for (if... {<then block...>} {<else block...>}),
|
||||||
// and also handles string interpolation cases like "${exp}moreString":
|
// and also handles string interpolation cases like "${exp}moreString":
|
||||||
readTable["{"] = (stream:Stream, k) -> CallExp(Symbol("begin").withPos(stream.position()), _readExpArray(stream, "}", k));
|
readTable["{"] = (stream:Stream, k) -> CallExp(Symbol("begin").withPos(stream.position()), _readExpArray(stream, "}", k));
|
||||||
|
}
|
||||||
|
|
||||||
readTable["<>["] = (stream, k) -> TypeParams(_readExpArray(stream, "]", k));
|
readTable["<>["] = (stream, k) -> TypeParams(_readExpArray(stream, "]", k));
|
||||||
|
|
||||||
@@ -671,6 +681,16 @@ class Reader {
|
|||||||
].join(" ");
|
].join(" ");
|
||||||
str += ']';
|
str += ']';
|
||||||
str;
|
str;
|
||||||
|
case BraceExp(exps):
|
||||||
|
// {e1 e2 e3}
|
||||||
|
var str = '{';
|
||||||
|
str += [
|
||||||
|
for (exp in exps) {
|
||||||
|
exp.def.toString();
|
||||||
|
}
|
||||||
|
].join(" ");
|
||||||
|
str += '}';
|
||||||
|
str;
|
||||||
case TypeParams(exps):
|
case TypeParams(exps):
|
||||||
// <>[T1 T2 T3]
|
// <>[T1 T2 T3]
|
||||||
var str = '<>[';
|
var str = '<>[';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ typedef ReaderExp = {
|
|||||||
enum ReaderExpDef {
|
enum ReaderExpDef {
|
||||||
CallExp(func:ReaderExp, args:Array<ReaderExp>); // (f a1 a2...)
|
CallExp(func:ReaderExp, args:Array<ReaderExp>); // (f a1 a2...)
|
||||||
ListExp(exps:Array<ReaderExp>); // [v1 v2 v3]
|
ListExp(exps:Array<ReaderExp>); // [v1 v2 v3]
|
||||||
|
BraceExp(exps:Array<ReaderExp>); // {e1 e2 e3}
|
||||||
StrExp(s:String); // "literal"
|
StrExp(s:String); // "literal"
|
||||||
Symbol(name:String); // s
|
Symbol(name:String); // s
|
||||||
RawHaxe(code:String); // #| haxeCode() |# // deprecated!
|
RawHaxe(code:String); // #| haxeCode() |# // deprecated!
|
||||||
|
|||||||
Reference in New Issue
Block a user