1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
use lang.bs;
optional delimiter = SDelimiter;
required delimiter = SRequiredDelimiter;
SConst => formattedStr(pos, block, fmt) : "f" #keyword - "\"" #string - SFmtStr(block) fmt - "\"" #string;
FormatBuilder SFmtStr(Block block);
SFmtStr => FormatBuilder() : (SFmtPart(block, me))*;
void SFmtPart(Block block, FormatBuilder b) #string;
SFmtPart => b : "[^\"\\\n}]*" -> add;
SFmtPart => b : "}" -> add;
SFmtPart => b : "\\[nrt]" -> addUnescape;
SFmtPart => b : "\\" - "\"" -> add;
SFmtPart : "\\" - SFmtAction(block, b, fmt) - "{" - SFmtStr(block) fmt - "}";
void SFmtAction(Block block, FormatBuilder base, FormatBuilder content);
SFmtAction => italic(base, content) : "i";
SFmtAction => bold(base, content) : "b";
SFmtAction => underline(base, content) : "u";
SFmtAction => strikeOut(base, content) : "x";
SFmtAction[100] => weight(base, content, weight) : "w\[", SIntConst weight, "]";
SFmtAction[100] => scale(base, content, scale) : "s\[", SFloatConst scale, "]";
SFmtAction[100] => color(base, content, r, g, b) : "c\[", SFloatConst r, ",", SFloatConst g, ",", SFloatConst b, "]";
SFmtAction[100] => font(base, content, font) : "f\[", "'", "[^']*" font, "'", "]";
// Dynamic versions of effects that accept parameters from surrounding context.
SFmtAction => weight(base, block, content, expr) : "w\[" - SExpr(block) expr - "]";
SFmtAction => scale(base, block, content, expr) : "s\[" - SExpr(block) expr - "]";
SFmtAction => font(base, block, content, expr) : "f\[" - SExpr(block) expr - "]";
SFmtAction => color(base, block, content, expr) : "c\[" - SExpr(block) expr - "]";
Float SFloatConst();
SFloatConst => toFloat(x) : "-?[0-9]+\.?[0-9]*" x;
Int SIntConst();
SIntConst => toInt(x) : "-?[0-9]+" x;
|