module php/pp/helpers
strategies

/**
 * Creates a block structure for a list of boxes.
 *
 * @type (Int, List(Box)) -> Box
 * @todo Use the integer of the lhs as the value of vs
 */
rules

  block-structure :
    (1, elems) -> 
V([SOpt(VS(), "0")], [ H([SOpt(HS(), "1")], [ S("{") | [ V([SOpt(VS(), "0")], [ S("") | [ V([SOpt(VS(), "1")], [ elems ]) ] ]) ] ]) | [ S("}") ] ])
box |[ V vs=0 [H hs=1 ["{" V vs=0 ["" V vs=1 [~*elems]]] "}"] ]|
where not(!elems => []) block-structure : (0, elems) ->
V([SOpt(VS(), "0")], [ H([SOpt(HS(), "1")], [ S("{") | [ V([SOpt(VS(), "0")], [ S("") | [ V([SOpt(VS(), "0")], [ elems ]) ] ]) ] ]) | [ S("}") ] ])
box |[ V vs=0 [H hs=1 ["{" V vs=0 ["" V vs=0 [~*elems]]] "}"] ]|
where not(!elems => []) block-structure : (_, []) -> H([SOpt(HS(), "1")], [ S("{") | [ S("}") ] ])
box |[ H hs=1 ["{" "}"] ]|
rules hbox = ( is-list < id + ![<id>]) ; !H([SOpt(HS(), "0")], [ <id> ])
box |[ H hs=0 [ ~*<id> ] ]|
comma = !S(",")
box |[ "," ]|
point = !S(".")
box |[ "." ]|
/** * Rewrites a list of boxes to a single box, where the elements are * separated by commas and between parenthesis. * * @type List(Box) -> Box */ rules list-to-args : [] -> H([SOpt(HS(), "0")], [ S("(") | [ S(")") ] ])
box |[ H hs=0 ["(" ")"] ]|
list-to-args : [arg] -> H([SOpt(HS(), "0")], [ S("(") | [ arg | [ S(")") ] ] ])
box |[ H hs=0 ["(" ~arg ")"] ]|
list-to-args : exprs@[_ | tail ] -> H([SOpt(HS(), "0")], [ S("(") | [ args | [ S(")") ] ] ])
box |[ H hs=0 ["(" ~args ")"] ]|
where <not(?[])> tail ; <separate-by-comma> exprs => args /** * Rewrites a list of boxes to a single box, where the elements are * separated by commas. * * @type List(Box) -> Box */ rules separate-by-comma = rec x( ?[<id>] <+ \ [] -> H([SOpt(HS(), "0")], [ ])
H hs=0 []
\ <+ {b1, b2: ?[b1 | <x>] ; ?b2 ; !H([SOpt(HS(), "1")], [ H([SOpt(HS(), "0")], [ b1 | [ S(",") ] ]) | [ b2 ] ])
H hs=1 [H hs=0 [b1 ","] b2]
} ) /** * Rewrites a list of Literal and Escape constructors to a single box. * The rules for the Escape constructor reside in the files for the * specific qouted strings */ rules lit-of-esc-to-string : [] -> H([SOpt(HS(), "0")], [ ])
H hs=0 []
lit-of-esc-to-string : [head | tail ] -> H([SOpt(HS(), "0")], [ head' | [ tail' ] ])
H hs=0 [ ~head' ~tail' ]
where <lit-to-string <+ esc-to-string <+ php-to-box> head => head' ; <lit-of-esc-to-string> tail => tail' lit-to-string : Literal(s) -> H([], [ S(s) ])
H [ s ]
esc-to-string : Escape(b) -> H([], [ b' ])
H [ ~b' ]
where <asc-to-norm> b => b' /** * Same as above, but this rewrites a list of literals or inline-echo statements * to a single box. */ rules lit-or-echo : // base case [] -> H([], [ ])
H []
lit-or-echo : [head | tail ] -> H([SOpt(HS(), "0")], [ head' | [ tail' ] ])
H hs=0 [ ~head' ~tail' ]
where <php-to-box> head => head' ; <lit-or-echo> tail => tail' lit-or-echo : [head | tail ] -> H([SOpt(HS(), "0")], [ head' | [ tail' ] ])
H hs=0 [ ~head' ~tail' ]
where <lit-to-string> head => head' ; <lit-or-echo> tail => tail' /** * Transform an ASCII-char to a box with the right * string */ rules asc-to-norm : 34 -> H([], [ S("\\\"") ])
H [ "\\\"" ]
asc-to-norm : 36 -> H([], [ S("\\$") ])
H [ "\\$" ]
asc-to-norm : 39 -> H([], [ S("\\'") ])
H [ "\\'" ]
asc-to-norm : 48 -> H([], [ S("0") ])
H [ "0" ]
asc-to-norm : 49 -> H([], [ S("1") ])
H [ "1" ]
asc-to-norm : 50 -> H([], [ S("2") ])
H [ "2" ]
asc-to-norm : 51 -> H([], [ S("3") ])
H [ "3" ]
asc-to-norm : 52 -> H([], [ S("4") ])
H [ "4" ]
asc-to-norm : 53 -> H([], [ S("5") ])
H [ "5" ]
asc-to-norm : 54 -> H([], [ S("6") ])
H [ "6" ]
asc-to-norm : 55 -> H([], [ S("7") ])
H [ "7" ]
asc-to-norm : 56 -> H([], [ S("8") ])
H [ "8" ]
asc-to-norm : 57 -> H([], [ S("9") ])
H [ "9" ]
asc-to-norm : 65 -> H([], [ S("A") ])
H [ "A" ]
asc-to-norm : 66 -> H([], [ S("B") ])
H [ "B" ]
asc-to-norm : 67 -> H([], [ S("C") ])
H [ "C" ]
asc-to-norm : 68 -> H([], [ S("D") ])
H [ "D" ]
asc-to-norm : 69 -> H([], [ S("E") ])
H [ "E" ]
asc-to-norm : 70 -> H([], [ S("F") ])
H [ "F" ]
asc-to-norm : 92 -> H([], [ S("\\\\") ])
H [ "\\\\" ]
asc-to-norm : 96 -> H([], [ S("\\\`") ])
H [ "\\\`" ]
asc-to-norm : 97 -> H([], [ S("a") ])
H [ "a" ]
asc-to-norm : 98 -> H([], [ S("b") ])
H [ "b" ]
asc-to-norm : 99 -> H([], [ S("c") ])
H [ "c" ]
asc-to-norm : 100 -> H([], [ S("d") ])
H [ "d" ]
asc-to-norm : 101 -> H([], [ S("e") ])
H [ "e" ]
asc-to-norm : 102 -> H([], [ S("f") ])
H [ "f" ]
asc-to-norm : 110 -> H([], [ S("\\n") ])
H [ "\\n" ]
asc-to-norm : 114 -> H([], [ S("\\r") ])
H [ "\\r" ]
asc-to-norm : 116 -> H([], [ S("\\t") ])
H [ "\\t" ]