24
24
Model = require './model'
26
exports.walk = (top) ->
25
{ InterpolatedValue, StringValue, ListValue, InlineOp, ExpandOp, CallOp, NonceOp, semanticError } = Model
27
callUnhandled = (obj) -> @unhandled obj
30
constructor : (overrides) ->
32
for own k, v of overrides
35
unhandled : (obj) -> semanticError obj, "Unexpected item"
36
interpolatedValue : callUnhandled
37
stringValue : callUnhandled
38
listValue : callUnhandled
39
inlineOp : callUnhandled
40
expandOp : callUnhandled
41
callOp : callUnhandled
42
nonceOp : callUnhandled
44
walkVisitable = new Visitable
45
interpolatedValue : (node) -> walkInterpolated node
47
exports.walk = (top) -> top.visit walkVisitable
50
interpElementVisitable = new Visitable
51
stringValue : (node) -> textOfStringValue node
52
callOp : (node) -> walkCallOp node
54
walkInterpolated = (node) -> node.visit interpElementVisitable
57
codepointToString = (cp) ->
58
adj = (cp - 0x10000) & 0xFFFFF
59
throw Error("Invalid codepoint " + cp) if cp isnt (adj + 0x10000)
62
String.fromCharCode(0xD800 + hi) + String.fromCharCode(0xDC00 + lo)
65
stringTextVisitable = new Visitable
66
stringValue : (node) ->
67
text = node.textToken.text
68
if node.doBslashEscapes
69
text = text.replace ///
80
(fullMatch, x8, x4, xarb, x2, letter, any) ->
81
hex = x8 ? x4 ? xarb ? x2
83
codepointToString parseInt hex, 16
97
textOfStringValue = (node) -> node.visit stringTextVisitable