How to use CompositeParserException class of Gherkin package

Best Gherkin-dotnet code snippet using Gherkin.CompositeParserException

DeveroomGherkinParser.cs

Source:DeveroomGherkinParser.cs Github

copy

Full Screen

...33 catch (ParserException parserException)34 {35 logger.LogVerbose($"ParserErrors: {parserException.Message}");36 gherkinDocument = GetResultOfInvalid();37 if (parserException is CompositeParserException compositeParserException)38 parserErrors.AddRange(compositeParserException.Errors);39 else40 parserErrors.Add(parserException);41 }42 catch (Exception e)43 {44 logger.LogException(_monitoringService, e, "Exception during Gherkin parsing");45 gherkinDocument = GetResult();46 }47 return false;48 }49 private DeveroomGherkinDocument GetResultOfInvalid()50 {51 // trying to "finish" open nodes by sending dummy <endrule> messages up to 5 levels of nesting52 for (int i = 0; i < 10; i++)53 {54 var result = GetResult();55 if (result != null)56 return result;57 try58 {59 AstBuilder.EndRule(RuleType.None);60 }61 catch (Exception)62 {63 }64 }65 return null;66 }67 public DeveroomGherkinDocument Parse(TextReader featureFileReader, string sourceFilePath)68 {69 var tokenScanner = (ITokenScanner)new HotfixTokenScanner(featureFileReader);70 var tokenMatcher = new TokenMatcher(DialectProvider);71 _astBuilder = new DeveroomGherkinAstBuilder(sourceFilePath, () => tokenMatcher.CurrentDialect);72 var parser = new InternalParser(_astBuilder, AstBuilder.RecordStateForLine, _monitoringService);73 var gherkinDocument = parser.Parse(tokenScanner, tokenMatcher);74 CheckSemanticErrors(gherkinDocument);75 return gherkinDocument;76 }77 class InternalParser : Parser<DeveroomGherkinDocument>78 {79 private readonly Action<int, int> _recordStateForLine;80 private readonly IMonitoringService _monitoringService;81 public InternalParser(IAstBuilder<DeveroomGherkinDocument> astBuilder, Action<int, int> recordStateForLine, IMonitoringService monitoringService)82 : base(astBuilder)83 {84 _recordStateForLine = recordStateForLine;85 _monitoringService = monitoringService;86 }87 public int NullMatchToken(int state, Token token)88 {89 return MatchToken(state, token, new ParserContext()90 {91 Errors = new List<ParserException>(),92 TokenMatcher = new AllFalseTokenMatcher(),93 TokenQueue = new Queue<Token>(),94 TokenScanner = new NullTokenScanner()95 });96 }97 protected override int MatchToken(int state, Token token, ParserContext context)98 {99 _recordStateForLine?.Invoke(token.Location.Line, state);100 try101 {102 return base.MatchToken(state, token, context);103 }104 catch (InvalidOperationException ex)105 {106 _monitoringService.MonitorError(ex);107 throw;108 }109 }110 }111 public DeveroomGherkinDocument GetResult()112 {113 return _astBuilder.GetResult();114 }115 #region Semantic Errors116 protected virtual void CheckSemanticErrors(DeveroomGherkinDocument specFlowDocument)117 {118 var errors = new List<ParserException>();119 errors.AddRange(((DeveroomGherkinAstBuilder)_astBuilder).Errors);120 if (specFlowDocument?.Feature != null)121 {122 CheckForDuplicateScenarios(specFlowDocument.Feature, errors);123 CheckForDuplicateExamples(specFlowDocument.Feature, errors);124 CheckForMissingExamples(specFlowDocument.Feature, errors);125 CheckForRulesPreSpecFlow31(specFlowDocument.Feature, errors);126 }127 // collect128 if (errors.Count == 1)129 throw errors[0];130 if (errors.Count > 1)131 throw new CompositeParserException(errors.ToArray());132 }133 private void CheckForRulesPreSpecFlow31(Feature feature, List<ParserException> errors)134 {135 //TODO: Show error when Rule keyword is used in SpecFlow v3.0 or earlier136 }137 private void CheckForDuplicateScenarios(Feature feature, List<ParserException> errors)138 {139 // duplicate scenario name140 var duplicatedScenarios = feature.FlattenScenarioDefinitions().GroupBy(sd => sd.Name, sd => sd).Where(g => g.Count() > 1).ToArray();141 errors.AddRange(142 duplicatedScenarios.Select(g =>143 new SemanticParserException(144 $"Feature file already contains a scenario with name '{g.Key}'",145 g.ElementAt(1).Location)));...

Full Screen

Full Screen

ParserException.cs

Source:ParserException.cs Github

copy

Full Screen

...114 {115 }116 }117 [Serializable]118 public class CompositeParserException : ParserException119 {120 public IEnumerable<ParserException> Errors { get; private set; }121 public CompositeParserException(ParserException[] errors)122 : base(GetMessage(errors))123 {124 if (errors == null) throw new ArgumentNullException("errors");125 Errors = errors;126 }127 private static string GetMessage(ParserException[] errors)128 {129 return "Parser errors:" + Environment.NewLine + string.Join(Environment.NewLine, errors.Select(e => e.Message));130 }131 protected CompositeParserException(SerializationInfo info, StreamingContext context) : base(info, context)132 {133 Errors = (ParserException[])info.GetValue("Errors", typeof (ParserException[]));134 }135 public override void GetObjectData(SerializationInfo info, StreamingContext context)136 {137 base.GetObjectData(info, context);138 info.AddValue("Errors", Errors.ToArray());139 }140 }141}...

Full Screen

Full Screen

GherkinTokenTagger.cs

Source:GherkinTokenTagger.cs Github

copy

Full Screen

...62 try63 {64 parser.Parse(new TokenScanner(reader), new TokenMatcher(VsGherkinDialectProvider.Instance));65 }66 catch (CompositeParserException compositeParserException)67 {68 parserErrors.AddRange(compositeParserException.Errors);69 }70 catch (ParserException parserException)71 {72 parserErrors.Add(parserException);73 }74 catch (Exception ex)75 {76 //nop;77 Debug.WriteLine(ex);78 }79 var tokenTags = new List<GherkinTokenTag>();80 tokenTags.AddRange((GherkinTokenTag[])tokenTagBuilder.GetResult());...

Full Screen

Full Screen

FeatureParser.cs

Source:FeatureParser.cs Github

copy

Full Screen

...49 if (result != null)50 this.descriptionProcessor.Process(result);51 return result;52 }53 catch (Gherkin.CompositeParserException exception)54 {55 throw new FeatureParseException("Unable to parse feature", exception);56 }57 }58 private IGherkinDialectProvider GetDialectProvider(string language)59 {60 IGherkinDialectProvider dialectProvider;61 if (this.dialectProviderCache.ContainsKey(language))62 {63 dialectProvider = this.dialectProviderCache[language];64 }65 else66 {67 dialectProvider = new CultureAwareDialectProvider(language);...

Full Screen

Full Screen

LexicParcer.cs

Source:LexicParcer.cs Github

copy

Full Screen

...18 using (var reader = new StreamReader(file)) {19 var ts = new TokenScanner(reader);20 try {21 feature = (Feature)parser.Parse(ts);22 } catch (CompositeParserException ex) {23 _errorFiles.Add(new ErrorInfo {24 FilePath = file,25 CompositeException = ex26 });27 return null;28 } catch (NullReferenceException ex) {29 _errorFiles.Add(new ErrorInfo {30 FilePath = file,31 Exception = ex32 });33 return null;34 }35 ts = null;36 }37 var steps = (from scenario in feature.ScenarioDefinitions38 from step in scenario.Steps39 let exampleSteps = GetSteps(step, scenario)40 from s in exampleSteps41 select s).ToList();42 var featureInfo = new FeatureFileInfo(file, steps);43 return featureInfo;44 }45 public static List<GherkinStep> GetSteps(Step step, ScenarioDefinition scenario) {46 var res = new List<GherkinStep>();47 var outline = scenario as ScenarioOutline;48 var stepText = step.Text;49 if (outline != null && stepText.Contains("<") && stepText.Contains(">")) {50 var m = _exampleRegex.Match(stepText);51 if (m.Success) {52 for (int i = 0; i < m.Groups.Count; i++) {53 var exampleValue = m.Groups[i].Value.Replace("<", string.Empty).Replace(">", string.Empty);54 var resStep = GetGherkinStep(step, exampleValue);55 res.Add(resStep);56 }57 }58 }59 else {60 var resStep = GetGherkinStep(step, stepText);61 res.Add(resStep);62 }63 return res;64 }65 private static GherkinStep GetGherkinStep(Step step, string stepText) {66 var resStep = new GherkinStep {67 Text = stepText,68 Column = (ushort) step.Location.Column,69 Line = (ushort) step.Location.Line,70 Keyword = step.Keyword71 };72 return resStep;73 }74 public static List<FeatureFileInfo> ParseFolder(string directory, bool includeSubdirs = true) {75 _errorFiles.Clear();76 var files = Directory.EnumerateFiles(directory, "*.feature",77 includeSubdirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList();78 var res = new List<FeatureFileInfo>(files.Count);79 res.AddRange(files.AsParallel().Select(ParseFile).Where(r=>r!= null));80 return res;81 }82 }83 public class ErrorInfo {84 public string FilePath { get; set; }85 public CompositeParserException CompositeException { get; set; }86 public Exception Exception { get; set; }87 }88}...

Full Screen

Full Screen

GherkinParser.cs

Source:GherkinParser.cs Github

copy

Full Screen

...18 return new GherkinFile(path, Enumerable.Empty<ParseErrorInformation>(),19 gherkinDocument);20 }21 }22 catch (CompositeParserException cpe)23 {24 return new GherkinFile(path, ToErrorInformation(cpe.Errors, text));25 }26 catch (ParserException pe)27 {28 return new GherkinFile(path, new List<ParseErrorInformation> {ToErrorInformation(pe, text)});29 }30 }31 private static IEnumerable<ParseErrorInformation> ToErrorInformation(32 in IEnumerable<ParserException> errors, string text)33 {34 var splitFile = FileUtils.SplitString(text);35 return errors.Select(error => ToErrorInformation(error, splitFile));36 }...

Full Screen

Full Screen

GherkinEvents.cs

Source:GherkinEvents.cs Github

copy

Full Screen

...29 }30 if (printPickles) {31 throw new NotSupportedException ("Gherkin.NET doesn't have a pickle compiler yet");32 }33 } catch (CompositeParserException e) {34 foreach (ParserException error in e.Errors) {35 addErrorAttachment (events, error, sourceEvent.uri);36 }37 } catch (ParserException e) {38 addErrorAttachment (events, e, sourceEvent.uri);39 }40 return events;41 }42 private void addErrorAttachment (List<IEvent> events, ParserException e, String uri)43 {44 events.Add (new AttachmentEvent (45 new AttachmentEvent.SourceRef (46 uri,47 new AttachmentEvent.Location (...

Full Screen

Full Screen

MissingExamplesParserFactory.cs

Source:MissingExamplesParserFactory.cs Github

copy

Full Screen

...37 return;3839 throw;40 }41 catch (CompositeParserException e)42 {43 if(e.Errors.All(ShouldIgnoreException))44 return;4546 throw;47 }48 }4950 private static bool ShouldIgnoreException(ParserException e) =>51 Regex.IsMatch(e.Message, @"^\(\d+:\d+\): Scenario Outline '.*?' has no examples defined$");52 } ...

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using Gherkin.Ast;8{9 {10 static void Main(string[] args)11 {12 var parser = new Parser();13 var feature = parser.Parse("Feature: Hello World14");15 Console.WriteLine("Feature: " + feature.Name);16 Console.WriteLine("Scenario: " + feature.Children[0].Name);17 Console.WriteLine("Given: " + feature.Children[0].Steps[0].Text);18 Console.WriteLine("When: " + feature.Children[0].Steps[1].Text);19 Console.WriteLine("Then: " + feature.Children[0].Steps[2].Text);20 Console.ReadLine();21 }22 }23}24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29using Gherkin;30using Gherkin.Ast;31{32 {33 static void Main(string[] args)34 {35 var parser = new Parser();36 {37 var feature = parser.Parse("Feature: Hello World38");39 Console.WriteLine("Feature: " + feature.Name);40 Console.WriteLine("Scenario: " + feature.Children[0].Name);41 Console.WriteLine("Given: " + feature.Children[0].Steps[0].Text);42 Console.WriteLine("When: " + feature.Children[0].Steps[1].Text);

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7{8 {9 static void Main(string[] args)10 {11";12 {13 var parser = new Parser();14 var feature1 = parser.Parse(feature);15 }16 catch (CompositeParserException e)17 {18 Console.WriteLine("Error occured at line {0} and column {1}", e.Line, e.Column);19 Console.WriteLine(e.Message);20 }21 }22 }23}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using Gherkin;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 {12 CompositeParserException ex = new CompositeParserException();13 ex.Add(new Exception("Exception 1"));14 ex.Add(new Exception("Exception 2"));15 ex.Add(new Exception("Exception 3"));16 ex.Add(new Exception("Exception 4"));17 throw ex;18 }19 catch (CompositeParserException e)20 {21 Console.WriteLine(e.Message);22 Console.WriteLine(e.StackTrace);23 }24 }25 }26}27 at ConsoleApp1.Program.Main(String[] args) in C:\Users\Nishant\Documents\Visual Studio 2015\Projects\ConsoleApp1\ConsoleApp1\Program.cs:line 19

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using Gherkin.Ast;8using Gherkin.Parser;9using Gherkin.TokenMatcher;10using System.IO;11using System.Text.RegularExpressions;12{13 {14 static void Main(string[] args)15 {16 {17 Feature feature = parser.Parse(text);18 }19 catch (CompositeParserException ex)20 {21 foreach (var error in ex.Errors)22 {23 Console.WriteLine(error.Message);24 }25 }26 }27 }28}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using System.IO;8{9 {10 static void Main(string[] args)11 {12 var parser = new Parser();13 var feature = parser.Parse(File.ReadAllText("C:\\Users\\Sarang\\Desktop\\GherkinTest\\GherkinTest\\1.feature"));14 Console.WriteLine(feature.Name);15 Console.ReadLine();16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using Gherkin;25using System.IO;26{27 {28 static void Main(string[] args)29 {30 var parser = new Parser();31 var feature = parser.Parse(File.ReadAllText("C:\\Users\\Sarang\\Desktop\\GherkinTest\\GherkinTest\\2.feature"));32 Console.WriteLine(feature.Name);33 Console.ReadLine();34 }35 }36}37 at Gherkin.Parser.Parse(String feature, String defaultLanguage)38 at Gherkin.Parser.Parse(String feature)39 at GherkinTest.Program.Main(String[] args) in C:\Users\Sarang\Desktop\GherkinTest\GherkinTest\Program.cs:line 12

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using Gherkin;2using Gherkin.Ast;3using Gherkin.Parser;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 public CompositeParserException(string message, Exception innerException)12 : base(message, innerException)13 {14 }15 }16}17using Gherkin;18using Gherkin.Ast;19using Gherkin.Parser;20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25{26 {27 public Parser()28 {29 }30 public GherkinDocument Parse(string feature)31 {32 return new GherkinDocument();33 }34 }35}36using Gherkin;37using Gherkin.Ast;38using Gherkin.Parser;39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44{45 {46 public GherkinDocument()47 {48 }49 }50}51using Gherkin;52using Gherkin.Ast;53using Gherkin.Parser;54using System;55using System.Collections.Generic;56using System.Linq;57using System.Text;58using System.Threading.Tasks;59{60 {61 public GherkinDialectProvider()62 {63 }64 public GherkinDialect GetDialect(string language, string location)65 {66 return new GherkinDialect();67 }68 }69}70using Gherkin;71using Gherkin.Ast;72using Gherkin.Parser;73using System;74using System.Collections.Generic;75using System.Linq;76using System.Text;77using System.Threading.Tasks;78{79 {80 public GherkinDialect()81 {82 }

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Linq;4using Gherkin;5using Gherkin.Ast;6using Gherkin.Parser;7using Gherkin.TokenMatcher;8{9 {10 public static void Main(string[] args)11 {12 var parser = new Parser<GherkinDocument>();13 var parserException = new CompositeParserException();14 var gherkinDcoument = parser.Parse("1.cs", ReadFileContent("1.cs"), parserException);15 if (parserException.Errors.Any())16 {17 foreach (var error in parserException.Errors)18 {19 Console.WriteLine(error.Message);20 }21 }22 }23 private static string ReadFileContent(string fileName)24 {25 return File.ReadAllText(fileName);26 }27 }28}291.cs(1): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'Feature: 1'301.cs(2): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'Scenario: 1'311.cs(3): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'Given I have 1'321.cs(4): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'When I add 2'331.cs(5): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'Then I get 3'341.cs(6): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'Given I have 4'351.cs(7): error : expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ScenarioLine, #ExamplesLine, #RuleLine, got 'When I add

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in CompositeParserException

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful