public bool Match_DocStringSeparator(Token token) { return activeDocStringSeparator == null // open ? Match_DocStringSeparator(token, GherkinLanguageConstants.DOCSTRING_SEPARATOR, true) || Match_DocStringSeparator(token, GherkinLanguageConstants.DOCSTRING_ALTERNATIVE_SEPARATOR, true) // close : Match_DocStringSeparator(token, activeDocStringSeparator, false); }
public bool Match_EOF(Token token) { if (token.IsEOF) { SetTokenMatched(token, TokenType.EOF); return true; } return false; }
public bool Match_Empty(Token token) { if (token.Line.IsEmpty()) { SetTokenMatched(token, TokenType.Empty); return true; } return false; }
protected virtual void SetTokenMatched(Token token, TokenType matchedType, string text = null, string keyword = null, int? indent = null, GherkinLineSpan[] items = null) { token.MatchedType = matchedType; token.MatchedKeyword = keyword; token.MatchedText = text; token.MatchedItems = items; token.MatchedGherkinDialect = CurrentDialect; token.MatchedIndent = indent ?? (token.Line == null ? 0 : token.Line.Indent); token.Location = new Location(token.Location.Line, token.MatchedIndent + 1); }
public bool Match_Comment(Token token) { if (token.Line.StartsWith(GherkinLanguageConstants.COMMENT_PREFIX)) { var text = token.Line.GetLineText(); //take the entire line SetTokenMatched(token, TokenType.Comment, text, indent: 0); return true; } return false; }
public bool Match_TagLine(Token token) { if (token.Line.StartsWith(GherkinLanguageConstants.TAG_PREFIX)) { SetTokenMatched(token, TokenType.TagLine, items: token.Line.GetTags().ToArray()); return true; } return false; }
public bool Match_TableRow(Token token) { if (token.Line.StartsWith(GherkinLanguageConstants.TABLE_CELL_SEPARATOR)) { SetTokenMatched(token, TokenType.TableRow, items: token.Line.GetTableCells().ToArray()); return true; } return false; }
public bool Match_StepLine(Token token) { var keywords = CurrentDialect.StepKeywords; foreach (var keyword in keywords) { if (token.Line.StartsWith(keyword)) { var stepText = token.Line.GetRestTrimmed(keyword.Length); SetTokenMatched(token, TokenType.StepLine, keyword: keyword, text: stepText); return true; } } return false; }
public bool Match_ScenarioOutlineLine(Token token) { return MatchTitleLine(token, TokenType.ScenarioOutlineLine, CurrentDialect.ScenarioOutlineKeywords); }
public void Feature(Token keyword, Token name) { if (NextEvent("feature", keyword.Position)) listener.Feature(keyword, name); }
public void Step(Token keyword, Token name, StepKind stepKind) { if (NextEvent("step", keyword.Position)) listener.Step(keyword, name, stepKind); }
private bool Match_DocStringSeparator(Token token, string separator, bool isOpen) { if (token.Line.StartsWith(separator)) { string contentType = null; if (isOpen) { contentType = token.Line.GetRestTrimmed(separator.Length); activeDocStringSeparator = separator; indentToRemove = token.Line.Indent; } else { activeDocStringSeparator = null; indentToRemove = 0; } SetTokenMatched(token, TokenType.DocStringSeparator, contentType); return true; } return false; }
private static string GetMessage(Token receivedToken, string[] expectedTokenTypes) { if (receivedToken == null) throw new ArgumentNullException("receivedToken"); if (expectedTokenTypes == null) throw new ArgumentNullException("expectedTokenTypes"); return string.Format("expected: {0}, got '{1}'", string.Join(", ", expectedTokenTypes), receivedToken.GetTokenValue().Trim()); }
public UnexpectedTokenException(Token receivedToken, string[] expectedTokenTypes, string stateComment) : base(GetMessage(receivedToken, expectedTokenTypes), receivedToken) { if (receivedToken == null) throw new ArgumentNullException("receivedToken"); if (expectedTokenTypes == null) throw new ArgumentNullException("expectedTokenTypes"); ReceivedToken = receivedToken; ExpectedTokenTypes = expectedTokenTypes; StateComment = stateComment; }
private static Location GetLocation(Token receivedToken) { return receivedToken.IsEOF || receivedToken.Location.Column > 1 ? receivedToken.Location : new Location(receivedToken.Location.Line, receivedToken.Line.Indent + 1); }
protected TokenParserException(string message, Token receivedToken) : base(message, GetLocation(receivedToken)) { }
protected TokenParserException(string message, Token receivedToken) : base(message, GetLocation(receivedToken)) { if (receivedToken == null) throw new ArgumentNullException("receivedToken"); }
private static string GetMessage(Token receivedToken, string[] expectedTokenTypes) { return string.Format("expected: {0}, got '{1}'", string.Join(", ", expectedTokenTypes), receivedToken.GetTokenValue().Trim()); }
public void Tag(Token name) { if (NextEvent("tag", name.Position)) listener.Tag(name); }
private ParserException CreateTokenMatcherException(Token token, string message) { return new AstBuilderException(message, new Location(token.Location.Line, token.Line.Indent + 1)); }
private bool MatchTitleLine(Token token, TokenType tokenType, string[] keywords) { foreach (var keyword in keywords) { if (token.Line.StartsWithTitleKeyword(keyword)) { var title = token.Line.GetRestTrimmed(keyword.Length + GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR.Length); SetTokenMatched(token, tokenType, keyword: keyword, text: title); return true; } } return false; }
public void Scenario(Token keyword, Token name) { if (NextEvent("scenario", keyword.Position)) listener.Scenario(keyword, name); }
public bool Match_BackgroundLine(Token token) { return MatchTitleLine(token, TokenType.BackgroundLine, CurrentDialect.BackgroundKeywords); }
public void ScenarioOutline(Token keyword, Token name) { if (NextEvent("scenario_outline", keyword.Position)) listener.ScenarioOutline(keyword, name); }
public bool Match_ExamplesLine(Token token) { return MatchTitleLine(token, TokenType.ExamplesLine, CurrentDialect.ExamplesKeywords); }
public void PythonString(Token pyString) { if (NextEvent("py_string", pyString.Position)) listener.PythonString(pyString); }
public bool Match_Language(Token token) { var match = LANGUAGE_PATTERN.Match(token.Line.GetLineText()); if (match.Success) { var language = match.Groups[1].Value; SetTokenMatched(token, TokenType.Language, language); try { currentDialect = dialectProvider.GetDialect(language, token.Location); } catch (NotSupportedException ex) { throw CreateTokenMatcherException(token, ex.Message); } return true; } return false; }
public bool Match_Other(Token token) { var text = token.Line.GetLineText(indentToRemove); //take the entire line, except removing DocString indents SetTokenMatched(token, TokenType.Other, text, indent: 0); return true; }
public bool Match_FeatureLine(Token token) { return MatchTitleLine(token, TokenType.FeatureLine, CurrentDialect.FeatureKeywords); }
public void Examples(Token keyword, Token name) { if (NextEvent("examples", keyword.Position)) listener.Examples(keyword, name); }