示例#1
0
        /// <summary>
        /// Parses an arbitrary string returning a corresponding ISourceFile.
        /// </summary>
        /// <returns>Whether parsing succeded</returns>
        public static bool TryParseSourceFile(FrontEndContext context, AbsolutePath sourceFilePath, string sourceFileContent, out TypeScript.Net.Types.SourceFile sourceFile)
        {
            var parser = new DScriptParser(context.PathTable);

            sourceFile = (TypeScript.Net.Types.SourceFile)parser.ParseSourceFileContent(sourceFilePath.ToString(context.PathTable), sourceFileContent, ParsingOptions.DefaultParsingOptions);

            return(sourceFile.ParseDiagnostics.Count != 0);
        }
示例#2
0
        /// <summary>
        /// Parses the specified input stream.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>A list of ExecutableCommands.</returns>
        public static CommandList Parse(ICharStream input)
        {
            DScriptLexer lexer = new DScriptLexer(input);
            CommonTokenStream tokenStream = new CommonTokenStream(lexer);

            DScriptParser parser = new DScriptParser(tokenStream);
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new LogErrorListener());

            List<ExecutableCommand> commands = parser.compileUnit().finalCommands;

            if (parser.NumberOfSyntaxErrors > 0)
            {
                throw new ParseException("Parser finished with syntax errors");
            }

            return new CommandList(commands);
        }