parser

package
v1.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 17 Imported by: 48

Documentation

Overview

Package parser parses all the specs in the list of directories given and also de-duplicates all specs passed through `specDirs` before parsing specs.

  Gets all the specs files in the given directory and generates token for each spec file.
  While parsing a concept file, concepts are inlined i.e. concept in the spec file is replaced with steps that concept has in the concept file.
  While creating a specification file parser applies the converter functions.
  Parsing a spec file gives a specification with parseresult. ParseResult contains ParseErrors, CriticalErrors, Warnings and FileName

  Errors can be generated, While
	- Generating tokens
	- Applying converters
	- After Applying converters

  If a parse error is found in a spec, only that spec is ignored and others will continue execution.
  This doesn't invoke the language runner.
  Eg : Multiple spec headings found in same file.
       Scenario should be defined after the spec heading.

  Critical error :
  	Circular reference of concepts - Doesn't parse specs becz it goes in recursion and crashes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToStepText

func ConvertToStepText(fragments []*gauge_messages.Fragment) string

ConvertToStepText accumulates fragments of a step, (ex. parameters) and returns the step text used to generate the annotation text in a step implementation

func CreateStepValue

func CreateStepValue(step *gauge.Step) gauge.StepValue

CreateStepValue converts a Step to StepValue

func ExtractStepArgsFromToken added in v0.9.1

func ExtractStepArgsFromToken(stepToken *Token) ([]gauge.StepArg, error)

ExtractStepArgsFromToken extracts step args(Static and Dynamic) from the given step token.

func ExtractStepValueAndParams

func ExtractStepValueAndParams(stepText string, hasInlineTable bool) (*gauge.StepValue, error)

ExtractStepValueAndParams parses a stepText string into a StepValue struct

func FilterTableRelatedScenarios added in v0.8.5

func FilterTableRelatedScenarios(scenarios []*gauge.Scenario, fun func(*gauge.Scenario) bool) (otherScenarios, tableRelatedScenarios []*gauge.Scenario)

FilterTableRelatedScenarios filters Scenarios that are using dynamic params from data table.

func GetResolvedDataTablerows added in v1.0.1

func GetResolvedDataTablerows(table *gauge.Table)

GetResolvedDataTablerows resolves any dynamic parameters in a table cell

func GetSpecsForDataTableRows added in v0.8.4

func GetSpecsForDataTableRows(s []*gauge.Specification, errMap *gauge.BuildErrors) (specs []*gauge.Specification)

GetSpecsForDataTableRows creates a spec for each data table row

func GetUnescapedString

func GetUnescapedString(string1 string) string

GetUnescapedString uses the go escape sequences to escape control characters and non printable characters.

func HandleParseResult

func HandleParseResult(results ...*ParseResult) bool

HandleParseResult collates list of parse result and determines if gauge has to break flow.

func NewSpecFileCollection added in v1.0.6

func NewSpecFileCollection(s []string) *specFileCollection

func ParseSpecs added in v0.6.2

func ParseSpecs(specsToParse []string, conceptsDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, bool)

ParseSpecs parses specs in the give directory and gives specification and pass/fail status, used in validation.

func PopulateConceptDynamicParams

func PopulateConceptDynamicParams(concept *gauge.Step, dataTableLookup *gauge.ArgLookup) error

PopulateConceptDynamicParams creates a copy of the lookup and populates table values

func Resolve added in v1.0.3

func Resolve(step *gauge.Step, parent *gauge.Step, lookup *gauge.ArgLookup, target *gauge_messages.ProtoStep) error

Resolve takes a step, a lookup and updates the target after reconciling the dynamic paramters from the given lookup

Types

type ConceptParser

type ConceptParser struct {
	// contains filtered or unexported fields
}

ConceptParser is used for parsing concepts. Similar, but not the same as a SpecParser

func (*ConceptParser) Parse

func (parser *ConceptParser) Parse(text, fileName string) ([]*gauge.Step, *ParseResult)

Parse Generates token for the given concept file and cretes concepts(array of steps) and parse results. concept file can have multiple concept headings.

func (*ConceptParser) ParseFile added in v0.1.8

func (parser *ConceptParser) ParseFile(file string) ([]*gauge.Step, *ParseResult)

ParseFile Reads file contents from a give file and parses the file.

type ParseError

type ParseError struct {
	FileName string
	LineNo   int
	SpanEnd  int
	Message  string
	LineText string
}

ParseError holds information about a parse failure

func AddConcept added in v0.9.4

func AddConcept(concepts []*gauge.Step, file string, conceptDictionary *gauge.ConceptDictionary) ([]ParseError, error)

AddConcept adds the concept in the ConceptDictionary.

func AddConcepts

func AddConcepts(conceptFiles []string, conceptDictionary *gauge.ConceptDictionary) ([]*gauge.Step, []ParseError, error)

AddConcepts parses the given concept file and adds each concept to the concept dictionary.

func (ParseError) Error

func (se ParseError) Error() string

Error prints error with filename, line number, error message and step text.

type ParseResult

type ParseResult struct {
	ParseErrors []ParseError
	Warnings    []*Warning
	Ok          bool
	FileName    string
}

ParseResult is a collection of parse errors and warnings in a file.

func CreateConceptsDictionary

func CreateConceptsDictionary() (*gauge.ConceptDictionary, *ParseResult, error)

CreateConceptsDictionary generates a ConceptDictionary which is map of concept text to concept. ConceptDictionary is used to search for a concept.

func CreateStepUsingLookup added in v0.3.2

func CreateStepUsingLookup(stepToken *Token, lookup *gauge.ArgLookup, specFileName string) (*gauge.Step, *ParseResult)

CreateStepUsingLookup generates gauge steps from step token and args lookup.

func ParseConcepts added in v0.6.2

func ParseConcepts() (*gauge.ConceptDictionary, *ParseResult, error)

ParseConcepts creates concept dictionary and concept parse result.

func ParseSpecFiles

func ParseSpecFiles(specFiles []string, conceptDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, []*ParseResult)

func ValidateConcepts added in v0.9.4

func ValidateConcepts(conceptDictionary *gauge.ConceptDictionary) *ParseResult

ValidateConcepts ensures that there are no circular references within

func (*ParseResult) Errors added in v0.5.0

func (result *ParseResult) Errors() (errors []string)

Errors Prints parse errors and critical errors.

type SpecParser

type SpecParser struct {
	// contains filtered or unexported fields
}

SpecParser is responsible for parsing a Specification. It delegates to respective processors composed sub-entities

func (*SpecParser) CreateSpecification

func (parser *SpecParser) CreateSpecification(tokens []*Token, conceptDictionary *gauge.ConceptDictionary, specFile string) (*gauge.Specification, *ParseResult, error)

CreateSpecification creates specification from the given set of tokens.

func (*SpecParser) GenerateTokens

func (parser *SpecParser) GenerateTokens(specText, fileName string) ([]*Token, []ParseError)

GenerateTokens gets tokens based on the parsed line.

func (*SpecParser) Parse

func (parser *SpecParser) Parse(specText string, conceptDictionary *gauge.ConceptDictionary, specFile string) (*gauge.Specification, *ParseResult, error)

Parse generates tokens for the given spec text and creates the specification.

func (*SpecParser) ParseSpecText added in v0.9.4

func (parser *SpecParser) ParseSpecText(specText string, specFile string) (*gauge.Specification, *ParseResult)

ParseSpecText without validating and replacing concepts.

type Token

type Token struct {
	Kind    gauge.TokenKind
	LineNo  int
	Suffix  string
	Args    []string
	Value   string
	Lines   []string
	SpanEnd int
}

Token defines the type of entity identified by the lexer

func (*Token) LineText

func (t *Token) LineText() string

func (*Token) String

func (token *Token) String() string

type Warning

type Warning struct {
	FileName    string
	LineNo      int
	LineSpanEnd int
	Message     string
}

Warning is used to indicate discrepancies that do not necessarily need to break flow.

func (*Warning) String

func (warning *Warning) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL