private static IWhitespaceNode[] CreateWhitespaces([NotNull] this IEnumerable <string> wsTexts)
        {
            if (wsTexts == null)
            {
                throw new ArgumentNullException("wsTexts");
            }

            var nodes = new List <IWhitespaceNode>();

            foreach (var text in wsTexts)
            {
                if (text.IsEmpty())
                {
                    continue;
                }

                if (text.IsNewLine())
                {
                    nodes.Add(CreateNewLine());
                }
                else
                {
                    // consistency check (remove in release?)
                    if (!PsiLexer.IsWhitespace(text))
                    {
                        throw new ApplicationException("Inconsistent space structure");
                    }

                    nodes.Add(CreateSpace(text));
                }
            }

            return(nodes.ToArray());
        }
示例#2
0
文件: Program.cs 项目: MasterQ32/psi
        private static Grammar.Module Load(string fileName)
        {
            using (var lexer = new PsiLexer(fileName))
            {
                var parser = new PsiParser(lexer);

                var success = parser.Parse();

                if (success)
                {
                    return(parser.Result);
                }
                Console.WriteLine("Line: {0}", lexer.yylloc.StartLine);
                return(null);
            }
        }
示例#3
0
 protected static Module Load(string source)
 {
     using (var lexer = new PsiLexer(new StringReader(source), "???"))
     {
         var parser  = new PsiParser(lexer);
         var success = parser.Parse();
         if (success)
         {
             return(parser.Result);
         }
         else
         {
             return(null);
         }
     }
 }
示例#4
0
        private static IWhitespaceNode[] CreateWhitespaces([NotNull] this IEnumerable <string> wsTexts)
        {
            if (wsTexts == null)
            {
                throw new ArgumentNullException("wsTexts");
            }

            return(wsTexts.Where(text => !text.IsEmpty()).Select(text =>
            {
                if (text.IsNewLine())
                {
                    return CreateNewLine("\r\n");
                }
                // consistency check (remove in release?)
                if (!PsiLexer.IsWhitespace(text))
                {
                    throw new ApplicationException("Inconsistent space structure");
                }
                return CreateSpace(text);
            }).ToArray());
        }
            public override void VisitNode(ITreeNode node, IHighlightingConsumer consumer)
            {
                String s = node.GetText();

                if (PsiLexer.IsKeyword(s))
                {
                    AddHighlighting(consumer, node);
                }
                else
                {
                    var token = node as PsiGenericToken;
                    if (token != null)
                    {
                        if (token.GetTokenType().IsStringLiteral)
                        {
                            AddHighlighting(consumer, new PsiStringLiteralHighlighting(node));
                        }
                        else if (token.GetTokenType().IsComment)
                        {
                            AddHighlighting(consumer, new PsiCommentHighlighting(node));
                        }
                    }
                }
            }
示例#6
0
        private static bool IsTokensGlued(TokenTypePair key)
        {
            var lexer = new PsiLexer(new StringBuffer(key.Type1.GetSampleText() + key.Type2.GetSampleText()));

            return(lexer.LookaheadToken(1) == null);
        }