internal ScriptCode(CodeBlock code, LanguageContext languageContext, CompilerContext compilerContext) { Assert.NotNull(code, languageContext, compilerContext); _code = code; _languageContext = languageContext; _compilerContext = compilerContext; }
public override CodeBlock ParseInteractiveCode(CompilerContext cc, bool allowIncomplete, out InteractiveCodeProperties properties) { ToyParser tp = new ToyParser(cc.SourceUnit.GetCode()); CodeBlock block = CodeBlock.MakeCodeBlock("top", tp.ParseInteractiveStatement()); properties = InteractiveCodeProperties.None; return block; }
public override CodeBlock ParseSourceCode(CompilerContext context) { InfixParser parser = new InfixParser(); Program tree = parser.Parse(context); if (tree != null) { return InfixGenerator.Generate(tree, context.SourceUnit.Id); } else { return null; } }
public override CodeBlock ParseSourceCode(CompilerContext context) { throw new NotImplementedException(); }
static CompilerContext GetContext(Stream s, CompilerContext old) { if (s is FileStream) { return new CompilerContext(SourceUnit.CreateFileUnit(ScriptEngine, ((FileStream)s).Name), old.Options, old.Errors, old.ParserSink); } return old; }
/// <summary> /// Updates code properties of the specified source unit. /// The default implementation invokes code parsing. /// </summary> public virtual void UpdateSourceCodeProperties(CompilerContext context) { Contract.RequiresNotNull(context, "context"); CodeBlock block = ParseSourceCode(context); if (!context.SourceUnit.CodeProperties.HasValue) { context.SourceUnit.CodeProperties = (block != null) ? SourceCodeProperties.None : SourceCodeProperties.IsInvalid; } }
/// <summary> /// Parses the source code within a specified compiler context. /// The source unit to parse is held on by the context. /// </summary> /// <param name="context">Compiler context.</param> /// <returns><b>null</b> on failure.</returns> /// <remarks>Could also set the code properties and line/file mappings on the source unit.</remarks> public abstract CodeBlock ParseSourceCode(CompilerContext context);
public ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { Contract.RequiresNotNull(sourceUnit, "sourceUnit"); if (options == null) options = GetCompilerOptions(); if (errorSink == null) errorSink = Engine.GetCompilerErrorSink(); CompilerContext context = new CompilerContext(sourceUnit, options, errorSink); CodeBlock block = ParseSourceCode(context); if (block == null) { throw new SyntaxErrorException(); } //DumpBlock(block, sourceUnit.Id); AnalyzeBlock(block); DumpBlock(block, sourceUnit.Id); // TODO: ParseSourceCode can update CompilerContext.Options return new ScriptCode(block, Engine.GetLanguageContext(context.Options), context); }
public ScriptCode CompileSourceCode(CodeBlock block, string sourcefile) { CompilerContext context = new CompilerContext(SourceUnit.CreateFileUnit(Engine, sourcefile), GetCompilerOptions(), Engine.GetCompilerErrorSink()); AnalyzeBlock(block); DumpBlock(block, null); return new ScriptCode(block, Engine.GetLanguageContext(context.Options), context); }
internal Program Parse(CompilerContext context) { SourceUnit unit = context.SourceUnit; Scanner scan = new Scanner(); string code = unit.GetCode(); scan.SetSource(code, 0); scanner = scan; //Trace = true; try { Parse(); return _tree; } catch (InfixSyntaxErrorException lse) { if (unit.Kind == SourceCodeKind.InteractiveCode) { if (lse.Eof) { unit.CodeProperties = SourceCodeProperties.IsIncompleteStatement; } else { throw; } } } return null; }
public override Microsoft.Scripting.Ast.CodeBlock ParseSourceCode(CompilerContext context) { throw new NotSupportedException(); }
public override CodeBlock ParseStatementCode(CompilerContext cc) { throw new Exception("The method or operation is not implemented."); }
public bool TryExpression(string expression) { CompilerOptions copts = engine.GetDefaultCompilerOptions(); ErrorSink sink = new ErrorSink(); SourceCodeUnit scu = new SourceCodeUnit(engine, expression); CompilerContext cc = new CompilerContext(scu, copts, sink); engine.Compiler.ParseExpressionCode(cc); return !sink.AnyError; }