public GherkinTextBufferPartialParserListener(GherkinDialect gherkinDialect, ITextSnapshot textSnapshot, IProjectScope projectScope, IGherkinFileScope previousScope, int changeLastLine, int changeLineDelta) : base(gherkinDialect, textSnapshot, projectScope) { this.previousScope = previousScope; this.changeLastLine = changeLastLine; this.changeLineDelta = changeLineDelta; }
private GherkinFileScopeChange FullParse(ITextSnapshot textSnapshot, GherkinDialect gherkinDialect) { visualStudioTracer.Trace("Start full parsing", ParserTraceCategory); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); partialParseCount = 0; var gherkinListener = new GherkinTextBufferParserListener(gherkinDialect, textSnapshot, projectScope); var scanner = new GherkinScanner(gherkinDialect, textSnapshot.GetText(), 0); scanner.Scan(gherkinListener); var gherkinFileScope = gherkinListener.GetResult(); var result = new GherkinFileScopeChange( gherkinFileScope, true, true, gherkinFileScope.GetAllBlocks(), Enumerable.Empty <IGherkinFileBlock>()); stopwatch.Stop(); TraceFinishParse(stopwatch, "full", result); return(result); }
public RegularExpressionScanner(CultureInfo defaultLanguage) { var dialectServices = new GherkinDialectServices(defaultLanguage); GherkinDialect gherkinDialect = dialectServices.GetDefaultDialect(); patternTable = gherkinDialect.GetKeywords().ToList().ConvertAll(x => new Regex(Regex.Escape(x))).ToArray(); }
private IEnumerable <Completion> GetKeywordCompletions() { GherkinDialect dialect = GetDialect(languageService); return(dialect.GetStepKeywords().Select(k => new Completion(k.Trim(), k.Trim(), null, null, null)).Concat( dialect.GetBlockKeywords().Select(k => new Completion(k.Trim(), k.Trim() + ": ", null, null, null)))); }
static internal bool IsStepLine(SnapshotPoint triggerPoint, GherkinLanguageService languageService) { var keywordCandidate = GetFirstWord(triggerPoint); if (keywordCandidate == null) { return(false); } GherkinDialect dialect = GetDialect(languageService); if (dialect == null) { return(false); } if (dialect.IsStepKeyword(keywordCandidate)) { return(true); } keywordCandidate = GetFirstTwoWords(triggerPoint); if (keywordCandidate == null) { return(false); } return(dialect.IsStepKeyword(keywordCandidate)); }
private string GetIndent(string line, GherkinDialect dialect) { if (IsBlockLine(line, dialect)) { var keyword = GetBlockKeyword(line, dialect); switch (keyword) { case GherkinBlockKeyword.Scenario: case GherkinBlockKeyword.ScenarioOutline: case GherkinBlockKeyword.Background: return(_scenarioIndent); case GherkinBlockKeyword.Examples: return(_exampleIndent); case GherkinBlockKeyword.Feature: return(_featureIndent); } } else if (IsStepLine(line, dialect)) { return(GetConfiguredStepLineBreaksAndIndent()); } else if (IsTableLine(line)) { return(_tableIndent); } return(string.Empty); }
public GherkinTextBufferPartialParserListener(GherkinDialect gherkinDialect, ITextSnapshot textSnapshot, GherkinFileEditorClassifications classifications, IGherkinFileScope previousScope, int changeLastLine, int changeLineDelta) : base(gherkinDialect, textSnapshot, classifications) { this.previousScope = previousScope; this.changeLastLine = changeLastLine; this.changeLineDelta = changeLineDelta; }
private static StepKeyword GetStepKeyword(GherkinDialect dialect, string stepKeyword) { if (dialect.AndStepKeywords.Contains(stepKeyword)) // we need to check "And" first, as the '*' is also part of the Given, When and Then keywords { return(StepKeyword.And); } if (dialect.GivenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.Given); } if (dialect.WhenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.When); } if (dialect.ThenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.Then); } if (dialect.ButStepKeywords.Contains(stepKeyword)) { return(StepKeyword.But); } return(StepKeyword.And); }
private List <Completion> GetDefaultKeywordCompletions(GherkinDialect gherkinDialect) { var result = new List <Completion>(); AddDefaultKeywordCompletions(gherkinDialect, result); return(result); }
/// <summary> /// Converts the provided <see cref="Gherkin.StepKeyword"/> into a <see cref="Augurk.Entities.StepKeyword"/>. /// </summary> /// <param name="stepKeyword">The <see cref="Gherkin.StepKeyword"/> that should be converted.</param> /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param> /// <returns>The converted <see cref="Augurk.Entities.StepKeyword"/>.</returns> public static StepKeyword ConvertToStepKeyword(this string stepKeyword, GherkinDialect dialect) { if (dialect.AndStepKeywords.Contains(stepKeyword)) { return(StepKeyword.And); } else if (dialect.ButStepKeywords.Contains(stepKeyword)) { return(StepKeyword.But); } else if (dialect.GivenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.Given); } else if (dialect.WhenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.When); } else if (dialect.ThenStepKeywords.Contains(stepKeyword)) { return(StepKeyword.Then); } else { return(StepKeyword.None); } }
protected virtual void AppendHeader(CultureInfo defaultLanguage, GherkinDialect dialect, StringBuilder result) { if (!DialectEquals(defaultLanguage, dialect)) { result.AppendFormat("#language:{0}", dialect.CultureInfo); AppendLine(result); } }
private GherkinBlockKeyword GetBlockKeyword(string line, GherkinDialect dialect) { var trimmedLine = line.TrimStart(); return(Enum.GetValues(typeof(GherkinBlockKeyword)) .Cast <GherkinBlockKeyword>() .First(keyword => dialect.GetBlockKeywords(keyword).Any(word => trimmedLine.StartsWith(word)))); }
public ListenerExtender(GherkinDialect gherkinDialect, IGherkinListener gherkinListener, GherkinBuffer buffer) { this.gherkinDialect = gherkinDialect; this.gherkinListener = gherkinListener; this.GherkinBuffer = buffer; gherkinListener.Init(buffer, IsIncremental); }
public static string[] GetBlockKeywords(this GherkinDialect gherkinDialect) { return(gherkinDialect.FeatureKeywords .Concat(gherkinDialect.BackgroundKeywords) .Concat(gherkinDialect.ScenarioKeywords) .Concat(gherkinDialect.ScenarioOutlineKeywords) .Concat(gherkinDialect.ExamplesKeywords) .ToArray()); }
protected GherkinTextBufferParserListenerBase(GherkinDialect gherkinDialect, ITextSnapshot textSnapshot, IProjectScope projectScope) { this.textSnapshot = textSnapshot; this.classifications = projectScope.Classifications; this.projectScope = projectScope; this.enableStepMatchColoring = projectScope.IntegrationOptionsProvider.GetOptions().EnableStepMatchColoring; gherkinFileScope = new GherkinFileScope(gherkinDialect, textSnapshot); }
public KeywordTranslation(GherkinDialect dialect) { foreach (StepDefinitionKeyword keyword in EnumHelper.GetValues(typeof(StepDefinitionKeyword))) { var keywordList = getKeywordTranslations[keyword](dialect); this[keyword] = new KeywordSet(keywordList); } DefaultSpecificCulture = CultureInfo.GetCultureInfo(dialect.Language); }
private void AddDefaultKeywordCompletions(GherkinDialect gherkinDialect, List <Completion> completions) { foreach (var keyword in gherkinDialect.StepKeywords) { completions.Add(new Completion(keyword)); } foreach (var blockKeyword in gherkinDialect.GetBlockKeywords()) { completions.Add(new Completion(blockKeyword + ": ")); } }
static internal bool IsStepLine(SnapshotPoint triggerPoint, GherkinLanguageService languageService) { var firstWord = GetFirstWord(triggerPoint); if (firstWord == null) { return(false); } GherkinDialect dialect = GetDialect(languageService); return(dialect.IsStepKeyword(firstWord)); }
private List <GherkinKeyword> GetGherkinKeywords(GherkinDialect dialect) { if (IsLeadingTextWhiteSpace()) { List <GherkinKeyword> keywords = new List <GherkinKeyword>(); keywords.Add(new GherkinKeyword("#language: ", TokenType.Language)); AddRange(keywords, dialect.FeatureKeywords, TokenType.FeatureLine); return(keywords); } else { return(MakeGherkinKeywordsByLastToken()); } }
private List <GherkinKeyword> MakeGherkinKeywordsByLastToken() { List <GherkinKeyword> keywords = new List <GherkinKeyword>(); Token token = GetLastEffectiveToken(); GherkinDialect dialect = token.MatchedGherkinDialect; switch (token.MatchedType) { case TokenType.Language: AddRange(keywords, dialect.FeatureKeywords, TokenType.FeatureLine); break; case TokenType.FeatureLine: AddRange(keywords, dialect.BackgroundKeywords, TokenType.BackgroundLine); AddRange(keywords, dialect.ScenarioKeywords, TokenType.ScenarioLine); AddRange(keywords, dialect.ScenarioOutlineKeywords, TokenType.ScenarioOutlineLine); IsEditingDescription = true; break; case TokenType.BackgroundLine: AddRange(keywords, dialect.GivenStepKeywords, TokenType.StepLine); break; case TokenType.ScenarioLine: case TokenType.ScenarioOutlineLine: AddRange(keywords, dialect.GivenStepKeywords, TokenType.StepLine); AddRange(keywords, dialect.WhenStepKeywords, TokenType.StepLine); IsEditingDescription = true; break; case TokenType.StepLine: MakeCodeCompletion4Step(token, keywords); break; case TokenType.ExamplesLine: AddRange(keywords, dialect.ExamplesKeywords, TokenType.ExamplesLine); AddRange(keywords, dialect.ScenarioKeywords, TokenType.ScenarioLine); AddRange(keywords, dialect.ScenarioOutlineKeywords, TokenType.ScenarioOutlineLine); break; case TokenType.DocStringSeparator: IsEditingDescription = true; break; } keywords.RemoveAll(x => x.Text.Contains("*")); // remove all "*" return(keywords); }
private List <GherkinCodeCompletionWord> MakeCompletionWords() { List <GherkinCodeCompletionWord> completionWords = new List <GherkinCodeCompletionWord>(); if (NeedCompletion()) { GherkinDialect dialect = Parser.CurrentDialect; foreach (var keyword in GetGherkinKeywords(dialect)) { completionWords.Add(new GherkinCodeCompletionWord(keyword, m_AppSettings)); } } return(completionWords); }
private static bool DialectEquals(CultureInfo defaultLanguage, GherkinDialect dialect) { if (!defaultLanguage.IsNeutralCulture) { defaultLanguage = defaultLanguage.Parent; } var dialectCulture = dialect.CultureInfo; if (!dialectCulture.IsNeutralCulture) { dialectCulture = dialectCulture.Parent; } return(defaultLanguage.Equals(dialectCulture)); }
/// <summary> /// Converts the provided <see cref="Gherkin.Ast.Step"/> instance into a <see cref="Augurk.Entities.Step"/> instance. /// </summary> /// <param name="step">The <see cref="Gherkin.Ast.Step"/> instance that should be converted.</param> /// <param name="blockKeyword">Current block of keywords being converted.</param> /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param> /// <returns>The converted <see cref="Augurk.Entities.Step"/> instance.</returns> public static Step ConvertToStep(this Gherkin.Ast.Step step, GherkinDialect dialect) { if (step == null) { throw new ArgumentNullException("step"); } return(new Step() { StepKeyword = step.Keyword.ConvertToStepKeyword(dialect), Keyword = step.Keyword, Content = step.Text, TableArgument = step.Argument.ConvertToTable(), Location = step.Location.ConvertToSourceLocation() }); }
/// <summary> /// Converts the provided <see cref="Gherkin.Ast.Scenario"/> instance into a <see cref="Augurk.Entities.Scenario"/> instance. /// </summary> /// <param name="scenario">The <see cref="Gherkin.Ast.Scenario"/> instance that should be converted.</param> /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param> /// <returns>The converted <see cref="Augurk.Entities.Scenario"/> instance.</returns> public static Scenario ConvertToScenario(this Gherkin.Ast.Scenario scenario, GherkinDialect dialect) { if (scenario == null) { throw new ArgumentNullException(nameof(scenario)); } return(new Scenario() { Title = scenario.Name, Description = scenario.Description, Tags = scenario.Tags.ConvertToStrings(), Steps = scenario.Steps.ConvertToSteps(dialect), ExampleSets = scenario.Examples.ConvertToExampleSets(), Location = scenario.Location.ConvertToSourceLocation() }); }
public static string GenerateKeywordsToolTip(string key) { GherkinDialect dialect = s_GherkinDialectcs.Value.GetCurrentDialect(key); StringBuilder sb = new StringBuilder(); sb.AppendLine("Language: " + key) .AppendLine(GenerateKeywords("Feature", dialect.FeatureKeywords)) .AppendLine(GenerateKeywords("Background", dialect.BackgroundKeywords)) .AppendLine(GenerateKeywords("Scenario", dialect.ScenarioKeywords)) .AppendLine(GenerateKeywords("Scenario Outline", dialect.ScenarioOutlineKeywords)) .AppendLine(GenerateKeywords("Examples", dialect.ExamplesKeywords)) .AppendLine(GenerateKeywords("Given", dialect.GivenStepKeywords)) .AppendLine(GenerateKeywords("When", dialect.WhenStepKeywords)) .AppendLine(GenerateKeywords("Then", dialect.ThenStepKeywords)) .AppendLine(GenerateKeywords("And", dialect.AndStepKeywords)) .Append(GenerateKeywords("But", dialect.ButStepKeywords)); return(sb.ToString()); }
/// <summary> /// Converts the provided <see cref="Gherkin.Ast.Feature"/> instance into a <see cref="Augurk.Entities.Feature"/> instance. /// </summary> /// <param name="feature">The <see cref="Gherkin.Ast.Feature"/> instance that should be converted.</param> /// <param name="dialect">The <see cref="GherkinDialect"/> that is being used for this feature.</param> /// <returns>The converted <see cref="Augurk.Entities.Feature"/> instance.</returns> public static Feature ConvertToFeature(this Gherkin.Ast.Feature feature, GherkinDialect dialect) { if (feature == null) { throw new ArgumentNullException("feature"); } var background = feature.Children.OfType <Gherkin.Ast.Background>().FirstOrDefault(); var scenarios = feature.Children.Where(definition => !(definition is Gherkin.Ast.Background)); return(new Feature() { Title = feature.Name, Description = feature.Description, Tags = feature.Tags.ConvertToStrings(), Scenarios = scenarios.Select(scenario => scenario.ConvertToScenario(dialect)).ToArray(), Background = background?.ConvertToBackground(dialect), Location = feature.Location.ConvertToSourceLocation() }); }
protected override bool TryGetDialect(string language, Location location, out GherkinDialect dialect) { if (language.Contains("-")) { if (base.TryGetDialect(language, location, out dialect)) { return(true); } var languageBase = language.Split('-')[0]; if (!base.TryGetDialect(languageBase, location, out var languageBaseDialect)) { return(false); } dialect = new GherkinDialect(language, languageBaseDialect.FeatureKeywords, languageBaseDialect.RuleKeywords, languageBaseDialect.BackgroundKeywords, languageBaseDialect.ScenarioKeywords, languageBaseDialect.ScenarioOutlineKeywords, languageBaseDialect.ExamplesKeywords, languageBaseDialect.GivenStepKeywords, languageBaseDialect.WhenStepKeywords, languageBaseDialect.ThenStepKeywords, languageBaseDialect.AndStepKeywords, languageBaseDialect.ButStepKeywords); return(true); } return(base.TryGetDialect(language, location, out dialect)); }
private int GetPreceedingLineBreaks(string line, GherkinDialect dialect) { if (IsBlockLine(line, dialect)) { var keyword = GetBlockKeyword(line, dialect); switch (keyword) { case GherkinBlockKeyword.Scenario: case GherkinBlockKeyword.ScenarioOutline: case GherkinBlockKeyword.Background: return(_lineBreaksBeforeScenario); case GherkinBlockKeyword.Examples: return(_lineBreaksBeforeExamples); case GherkinBlockKeyword.Feature: return(_lineBreaksBeforeFeature); } } return(0); }
static internal bool IsKeywordPrefix(SnapshotPoint triggerPoint, GherkinLanguageService languageService) { var line = triggerPoint.GetContainingLine(); SnapshotPoint start = line.Start; ForwardWhile(ref start, triggerPoint, p => char.IsWhiteSpace(p.GetChar())); SnapshotPoint end = start; ForwardWhile(ref end, triggerPoint, p => !char.IsWhiteSpace(p.GetChar())); if (start >= end) { return(true); // returns true for empty word } end = triggerPoint; // if (end < triggerPoint) // return false; var firstWord = triggerPoint.Snapshot.GetText(start, end.Position - start); GherkinDialect dialect = GetDialect(languageService); return(dialect.GetKeywords().Any(k => k.StartsWith(firstWord, StringComparison.CurrentCultureIgnoreCase))); }
private void MakeCodeCompletion4Step(Token lastEffectiveStep, List <GherkinKeyword> keywords) { GherkinDialect dialect = lastEffectiveStep.MatchedGherkinDialect; AddRange(keywords, dialect.AndStepKeywords, TokenType.StepLine); AddRange(keywords, dialect.ButStepKeywords, TokenType.StepLine); if (IsGiven(lastEffectiveStep) && IsFeatureGivenStep) { AddRange(keywords, dialect.WhenStepKeywords, TokenType.StepLine); AddRange(keywords, dialect.ThenStepKeywords, TokenType.StepLine); } else if (IsWhen(lastEffectiveStep)) { AddRange(keywords, dialect.ThenStepKeywords, TokenType.StepLine); } else // It must be a then step { AddRange(keywords, dialect.ExamplesKeywords, TokenType.ExamplesLine); AddRange(keywords, dialect.ScenarioKeywords, TokenType.ScenarioLine); AddRange(keywords, dialect.ScenarioOutlineKeywords, TokenType.ScenarioOutlineLine); } }
public GherkinScanner(GherkinDialect gherkinDialect, string gherkinText) : this(gherkinDialect, gherkinText, 0) { }
public ListenerExtender(GherkinDialect gherkinDialect, IGherkinListener gherkinListener, GherkinBuffer buffer) { this.gherkinDialect = gherkinDialect; this.gherkinListener = gherkinListener; this.GherkinBuffer = buffer; gherkinListener.Init(buffer, IsIncremental); }
public GherkinScanner(GherkinDialect gherkinDialect, string gherkinText, int lineOffset) { this.gherkinDialect = gherkinDialect; this.buffer = new GherkinBuffer(gherkinText, lineOffset); }