static CompileUnit SyntaxTreeFor(IFile file)
        {
            var compileUnit = new CompileUnit();

            UnityScriptParser.ParseReader(file.OpenText(), "", new CompilerContext(), compileUnit);
            return(compileUnit);
        }
예제 #2
0
        private IList <Comment> CollectCommentsFor(SourceFile sourceFile, IEnumerable <string> definedSymbols)
        {
            var comments = new List <Comment>();
            var p        = new PreProcessor();

            p.PreserveLines = true;
            foreach (var symbol in definedSymbols)
            {
                p.Define(symbol);
            }

            var result = p.Process(sourceFile.Contents);

            var lexer = UnityScriptParser.UnityScriptLexerFor(new StringReader(result), sourceFile.FileName, 4);

            lexer.PreserveComments = true;

            var    token = lexer.nextToken();
            IToken last  = null;

            while (token != null && token.Type != UnityScriptLexer.EOF)
            {
                try
                {
                    if (token.Type == UnityScriptLexer.SL_COMMENT || token.Type == UnityScriptLexer.ML_COMMENT)
                    {
                        comments.Add(new Comment(token, token.Type == UnityScriptLexer.SL_COMMENT ? CommentKind.SingleLine : CommentKind.MultipleLine, last));
                    }
                    else
                    {
                        last = token;
                    }
                }
                catch (TokenStreamRecognitionException tre)
                {
                    //TODO: Collect errors from this phase so we can at least show them to user ?
                }
                finally
                {
                    try
                    {
                        token = lexer.nextToken();
                    }
                    catch (TokenStreamRecognitionException tre)
                    {
                    }
                }
            }

            return(comments);
        }
예제 #3
0
        private void ParseInput(ICompilerInput input)
        {
            TextReader  reader;
            IDisposable disposable = (reader = input.Open()) as IDisposable;

            try
            {
                UnityScriptParser.ParseReader(reader, input.Name, this.Context, this.CompileUnit);
            }
            finally
            {
                if (disposable != null)
                {
                    disposable.Dispose();
                    disposable = null;
                }
            }
        }