internal ScriptSource(ScriptEngine engine, SourceUnit sourceUnit) { Assert.NotNull(engine, sourceUnit); _unit = sourceUnit; _engine = engine; }
public virtual void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) { CountError(severity); }
public SourceLocation MapLine(SourceLocation location) { return(SourceUnit.MakeLocation(location)); }
private CompiledCode CompileInternal(CompilerOptions compilerOptions, ErrorListener errorListener) { ErrorSink errorSink = new ErrorListenerProxySink(this, errorListener); ScriptCode code = compilerOptions != null?SourceUnit.Compile(compilerOptions, errorSink) : SourceUnit.Compile(errorSink); return((code != null) ? new CompiledCode(Engine, code) : null); }
/// <summary> /// Comvenience hosting API. /// </summary> public ICompiledCode CompileStatements(string statement, IScriptModule module) { Contract.RequiresNotNull(statement, "statement"); return(CompileSourceUnit(SourceUnit.CreateSnippet(this, statement, SourceCodeKind.Statements), module)); }
/// <summary> /// Executes the source code. The execution is not bound to any particular scope. /// </summary> public dynamic Execute() { // The host doesn't need the scope so do not create it here. // The language can treat the code as not bound to a DLR scope and change global lookup semantics accordingly. return(SourceUnit.Execute()); }
public string GetCodeLine(int line) { return(SourceUnit.GetCodeLine(line)); }
public void ExecuteSourceUnit(SourceUnit sourceUnit, IScriptModule module) { Contract.RequiresNotNull(sourceUnit, "sourceUnit"); CompileSourceUnit(sourceUnit, module).Execute(module); }
/// <summary> /// Detects the encoding of the content. /// </summary> /// <returns> /// An encoding that is used by the reader of the script source to transcode its content to Unicode text. /// <c>Null</c> if the content is already textual and no transcoding is performed. /// </returns> /// <remarks> /// Note that the default encoding specified when the script source is created could be overridden by /// an encoding that is found in the content preamble (Unicode BOM or a language specific encoding preamble). /// In that case the preamble encoding is returned. Otherwise, the default encoding is returned. /// </remarks> /// <exception cref="IOException">An I/O error occurs.</exception> public Encoding DetectEncoding() { using (var reader = SourceUnit.GetReader()) { return(reader.Encoding); } }
/// <summary> /// Reads specified range of lines (or less) from the source unit. /// </summary> /// <param name="start">1-based number of the first line to fetch.</param> /// <param name="count">The number of lines to fetch.</param> /// <remarks> /// Which character sequences are considered line separators is language specific. /// If language doesn't specify otherwise "\r", "\n", "\r\n" are recognized line separators. /// </remarks> /// <exception cref="IOException">An I/O error occurs.</exception> public string[] GetCodeLines(int start, int count) { return(SourceUnit.GetCodeLines(start, count)); }
public SourceCodeReader GetReader() { return(SourceUnit.GetReader()); }
public ScriptCodeParseResult GetCodeProperties(CompilerOptions options) { return(SourceUnit.GetCodeProperties(options)); }
public ScriptCodeParseResult GetCodeProperties() { return(SourceUnit.GetCodeProperties()); }
public object EvaluateSourceUnit(SourceUnit sourceUnit, IScriptModule module) { Contract.RequiresNotNull(sourceUnit, "sourceUnit"); return(CompileSourceUnit(sourceUnit, module).Evaluate(module)); }
public string GetCode() { return(SourceUnit.GetCode()); }
/// <summary> /// Execute a snippet of code within the scope of the specified module. Convenience API. /// </summary> public void Execute(string code, IScriptModule module) { Contract.RequiresNotNull(code, "code"); ExecuteSourceUnit(SourceUnit.CreateSnippet(this, code), module); }
// TODO: can this be removed? no one uses it #region line number mapping public int MapLine(int line) { return(SourceUnit.MapLine(line)); }
public ICompiledCode CompileSourceUnit(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { Contract.RequiresNotNull(sourceUnit, "sourceUnit"); return(new CompiledCode(_languageContext.CompileSourceCode(sourceUnit, options, errorSink))); }
public SourceSpan MapLine(SourceSpan span) { return(new SourceSpan(SourceUnit.MakeLocation(span.Start), SourceUnit.MakeLocation(span.End))); }
public ICompiledCode CompileInteractiveCode(string code, IScriptModule module) { Contract.RequiresNotNull(code, "code"); return(CompileSourceUnit(SourceUnit.CreateSnippet(this, code, SourceCodeKind.InteractiveCode), module)); }
/// <summary> /// Executes the code in the specified scope. /// Returns an object that is the resulting value of running the code. /// /// When the ScriptSource is a file or statement, the engine decides what is /// an appropriate value to return. Some languages return the value produced /// by the last expression or statement, but languages that are not expression /// based may return null. /// </summary> /// <exception cref="SyntaxErrorException">Code cannot be compiled.</exception> public dynamic Execute(ScriptScope scope) { ContractUtils.RequiresNotNull(scope, nameof(scope)); return(SourceUnit.Execute(scope.Scope)); }