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()); }
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); } }
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); } } }
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)); } } } }
private static bool IsTokensGlued(TokenTypePair key) { var lexer = new PsiLexer(new StringBuffer(key.Type1.GetSampleText() + key.Type2.GetSampleText())); return(lexer.LookaheadToken(1) == null); }