/// <summary> /// Keeps stream open. /// </summary> /// <exception cref="InvalidSourceException">Source file cannot be opened for reading.</exception> public override void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink, Parsers.Position initialPosition, LanguageFeatures features) { Parser parser = new Parser(); StreamReader source_reader; try { stream = new FileStream(sourceFile.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read); source_reader = new StreamReader(stream, encoding, true); // if the file contains a byte-order-mark, we must advance the offset in order to // get correct token positions in lexer (unfortunately, StreamReader skips BOM without // a possibility to detect it from outside, so we have to do that manually): // TODO: // initialPosition.FirstOffset += FileSystemUtils.GetByteOrderMarkLength(stream); } catch (Exception e) { throw new InvalidSourceException(sourceFile.FullPath, e); } ast = parser.Parse(this, source_reader, errors, reductionsSink, initialPosition, Lexer.LexicalStates.INITIAL, features); }
public GlobalCode Parse(SourceUnit /*!*/ sourceUnit, TextReader /*!*/ reader, ErrorSink /*!*/ errors, IReductionsSink reductionsSink, Parsers.Position initialPosition, Lexer.LexicalStates initialLexicalState, LanguageFeatures features) { Debug.Assert(reader != null && errors != null); // initialization: this.sourceUnit = sourceUnit; this.errors = errors; this.features = features; this.reader = reader; this.reductionsSink = reductionsSink ?? NullReductionSink; InitializeFields(); this.scanner = new Scanner(initialPosition, reader, sourceUnit, errors, reductionsSink as ICommentsSink, features); this.scanner.CurrentLexicalState = initialLexicalState; this.currentScope = new Scope(1); // starts assigning scopes from 2 (1 is reserved for prepended inclusion) this.unicodeSemantics = (features & LanguageFeatures.UnicodeSemantics) != 0; base.Scanner = this.scanner; base.Parse(); GlobalCode result = astRoot; // clean and let GC collect unused AST and other stuff: ClearFields(); return(result); }
public override void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink, LanguageFeatures features) { Parser parser = new Parser(); using (StringReader source_reader = new StringReader(code)) { ast = parser.Parse(this, source_reader, errors, reductionsSink, initialState, features); } }
private void ClearFields() { scanner = null; features = 0; errors = null; sourceUnit = null; reductionsSink = null; astRoot = null; reader = null; }
public override void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink, LanguageFeatures features) { Parser parser = new Parser(); parser.AllowGlobalCode = this.allowGlobalCode; using (StringReader reader = new StringReader(code)) { ast = parser.Parse(this, reader, errors, reductionsSink, Lexer.LexicalStates.INITIAL, features); } }
/// <summary> /// Creates source unit and parses given <paramref name="code"/>. /// </summary> /// <param name="code">Source code to be parsed.</param> /// <param name="sourceFile">Source file used for error reporting.</param> /// <param name="errors">Errors sink. Can be <c>null</c>.</param> /// <param name="reductionsSink">Reduction sink. Can be <c>null</c>.</param> /// <param name="features">Optional. Language features.</param> /// <param name="initialState"> /// Optional. Initial parser state. /// This allows e.g. to parse PHP code without encapsulating the code into opening and closing tags.</param> /// <returns></returns> public static SourceUnit /*!*/ ParseCode(string code, PhpSourceFile sourceFile, ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink = null, LanguageFeatures features = LanguageFeatures.Php5, Lexer.LexicalStates initialState = Lexer.LexicalStates.INITIAL) { var /*!*/ unit = new CodeSourceUnit(code, sourceFile, Encoding.UTF8, initialState); unit.Parse(errors, reductionsSink, features); unit.Close(); // return(unit); }
/// <summary> /// Keeps stream open. /// </summary> /// <exception cref="InvalidSourceException">Source file cannot be opened for reading.</exception> public override void Parse(ErrorSink errors, IReductionsSink reductionsSink, LanguageFeatures features) { Parser parser = new Parser(); StreamReader source_reader; try { stream = new FileStream(sourceFile.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read); source_reader = new StreamReader(stream, encoding, true); } catch (Exception e) { throw new InvalidSourceException(sourceFile.FullPath, e); } ast = parser.Parse(this, source_reader, errors, reductionsSink, Lexer.LexicalStates.INITIAL, features); }
public abstract void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink, Parsers.Position initialPosition, LanguageFeatures features);
public abstract void Parse( ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink, LanguageFeatures features);
public abstract void Parse(ErrorSink/*!*/ errors, IReductionsSink/*!*/ reductionsSink, Parsers.Position initialPosition, LanguageFeatures features);