コード例 #1
0
        protected override NativeXAnalyzingResult Calculate(string input)
        {
            NativeXAnalyzingResult result = new NativeXAnalyzingResult();
            result.IdTokens = new Dictionary<int, List<CodeToken>>();

            List<CodeToken> tokens = NativeXCodeParser.Tokenize(input.ToCharArray());
            int lastRow = -1;
            List<CodeToken> lastLines = null;
            for (int i = 0; i < tokens.Count; i++)
            {
                CodeToken token = tokens[i];
                if (token.Id == NativeXTokenizer.IdToken)
                {
                    int row = token.Start.row;
                    if (row != lastRow)
                    {
                        lastLines = new List<CodeToken>();
                        result.IdTokens.Add(row, lastLines);
                        lastRow = row;
                    }
                    lastLines.Add(token);
                }
            }

            int currentToken = 0;
            bool parseSuccess = false;
            result.Unit = NativeXCodeParser.ParseUnit(tokens, ref currentToken, ref parseSuccess);
            if (result.Unit != null)
            {
                result.Unit.BuildScope(null);
            }
            result.Unit.OwningScope.ExtraScopes = this.headers.PredifinedHeaders.Select(u => u.OwningScope).ToArray();
            return result;
        }
コード例 #2
0
            public virtual NativeXEditingDeclarations ParseEditingNodeContainer(string code)
            {
                List <CodeToken> tokens = NativeXCodeParser.Tokenize(code.ToCharArray());
                int  currentToken       = 0;
                bool parseSuccess       = false;

                return(NativeXCodeParser.ParseEditingDeclarations(tokens, ref currentToken, ref parseSuccess));
            }
コード例 #3
0
        public void AddPredefinedHeader(string code)
        {
            List <CodeToken> tokens  = NativeXCodeParser.Tokenize(code.ToCharArray());
            int         currentToken = 0;
            bool        parseSuccess = false;
            NativeXUnit unit         = NativeXCodeParser.ParseUnit(tokens, ref currentToken, ref parseSuccess);

            if (unit != null && parseSuccess)
            {
                unit.BuildScope(null);
                this.predefinedHeaders.Add(unit);
            }
        }
コード例 #4
0
        private T Parse <T>(string input, ParserMethod <T> parser)
            where T : NativeXNode
        {
            List <CodeToken> tokens = NativeXCodeParser.Tokenize(input.ToCharArray());
            int  currentToken       = 0;
            bool parseSuccess       = false;
            T    result             = parser(tokens, ref currentToken, ref parseSuccess);

            Assert.AreEqual(tokens.Count, currentToken);
            Assert.AreEqual(tokens[0].Start, result.Start);
            Assert.AreEqual(tokens[tokens.Count - 1].End, result.End);
            if (result != null)
            {
                result.BuildScope(null);
            }
            return(result);
        }