/// <summary> /// Generates a xml from the specified char stream of the source code. /// </summary> /// <param name="charStream"></param> /// <param name="parsingCompleteCode"></param> /// <param name="throwingParseError"></param> /// <returns></returns> protected CstNode GenerateSyntaxTree( ICharStream charStream, bool parsingCompleteCode, bool throwingParseError) { var tokenStream = CreateTokenStream(charStream); var parser = CreateParser(tokenStream); parser.TraceDestination = Console.Error; if (!parsingCompleteCode) { return(ParseFragment(parser, tokenStream)); } var builder = throwingParseError ? new CstBuilderForAntlr3WithReportingError(tokenStream, parser.TokenNames) : new CstBuilderForAntlr3(tokenStream, parser.TokenNames); parser.TreeAdaptor = builder; return(builder.FinishParsing(Parse(parser))); }
/// <summary> /// Creates and returns a lexer. /// </summary> /// <param name="stream"></param> /// <returns></returns> protected abstract ITokenSource CreateLexer(ICharStream stream);
/// <summary> /// Creates a token stream which provides tokenized code. /// </summary> /// <param name="stream"></param> /// <returns></returns> private CommonTokenStream CreateTokenStream(ICharStream stream) { var lexer = CreateLexer(stream); return(new CommonTokenStream(lexer)); }