github.com/getgauge/gauge@v1.6.9/parser/result.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package parser 8 9 import "fmt" 10 11 // ParseError holds information about a parse failure 12 type ParseError struct { 13 FileName string 14 LineNo int 15 SpanEnd int 16 Message string 17 LineText string 18 } 19 20 // Error prints error with filename, line number, error message and step text. 21 func (se ParseError) Error() string { 22 if se.LineNo == 0 && se.FileName == "" { 23 return se.Message 24 } 25 return fmt.Sprintf("%s:%d %s => '%s'", se.FileName, se.LineNo, se.Message, se.LineText) 26 } 27 28 func (token *Token) String() string { 29 return fmt.Sprintf("kind:%d, lineNo:%d, value:%s, line:%s, args:%s", token.Kind, token.LineNo, token.Value, token.LineText(), token.Args) 30 } 31 32 // ParseResult is a collection of parse errors and warnings in a file. 33 type ParseResult struct { 34 ParseErrors []ParseError 35 Warnings []*Warning 36 Ok bool 37 FileName string 38 } 39 40 // Errors Prints parse errors and critical errors. 41 func (result *ParseResult) Errors() (errors []string) { 42 for _, err := range result.ParseErrors { 43 errors = append(errors, fmt.Sprintf("[ParseError] %s", err.Error())) 44 } 45 return 46 } 47 48 // Warning is used to indicate discrepancies that do not necessarily need to break flow. 49 type Warning struct { 50 FileName string 51 LineNo int 52 LineSpanEnd int 53 Message string 54 } 55 56 func (warning *Warning) String() string { 57 return fmt.Sprintf("%s:%d %s", warning.FileName, warning.LineNo, warning.Message) 58 }