public CompiledScript CompileScript source where ITokenStreamFactory n

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
public CompiledScript CompileScript<T, S>(S source)
where T : ITokenStreamFactory<S>, new()
{
ScriptContext scriptContext = null;
var scriptCompiler = new ScriptCompiler<T, S>(source);
var compiledNode = scriptCompiler.Compile(new ScriptContext()
{
GetConstant = (constantName) =>
{
return scriptContext.GetConstant(constantName) ?? _defaultContext.GetConstant(constantName);
},
GetFunction = (functionName) =>
{
return scriptContext.GetFunction(functionName) ?? _defaultContext.GetFunction(functionName);
}
});
if (compiledNode != null)
{
return new CompiledScript((context) =>
{
scriptContext = context ?? _defaultContext;
return compiledNode.Eval();
}, compiledNode);
}
return null;
}
public Node RunScript<T, S>(S source, ScriptContext context = null)
where T : ITokenStreamFactory<S>, new()
{
var compiledScript = CompileScript<T, S>(source);
if (compiledScript != null)
{
return compiledScript.Run(context);
}
return null;
}
public CompiledScript CompileScript(String source)
{
return CompileScript<TextTokenStreamFactory, String>(source);
}
public Node RunScript(String source, ScriptContext context = null)
{
return RunScript<TextTokenStreamFactory, String>(source, context);
}