github.com/mithrandie/csvq@v1.18.1/lib/json/path_lexer.go (about)

     1  package json
     2  
     3  import "fmt"
     4  
     5  type PathLexer struct {
     6  	PathScanner
     7  	path  PathExpression
     8  	token PathToken
     9  	err   error
    10  }
    11  
    12  func (l *PathLexer) Lex(lval *jpSymType) int {
    13  	tok := l.Scan()
    14  
    15  	lval.token = tok
    16  	l.token = lval.token
    17  	return tok.Token
    18  }
    19  
    20  func (l *PathLexer) Error(_ string) {
    21  	if l.token.Token == EOF {
    22  		l.err = NewPathSyntaxError("unexpected termination", l.token)
    23  	} else {
    24  		l.err = NewPathSyntaxError(fmt.Sprintf("unexpected token %q", l.token.Literal), l.token)
    25  	}
    26  }
    27  
    28  type PathToken struct {
    29  	Token   int
    30  	Literal string
    31  	Column  int
    32  }
    33  
    34  type PathSyntaxError struct {
    35  	Column  int
    36  	Message string
    37  }
    38  
    39  func (e PathSyntaxError) Error() string {
    40  	return e.Message
    41  }
    42  
    43  func NewPathSyntaxError(message string, token PathToken) error {
    44  	return &PathSyntaxError{
    45  		Column:  token.Column,
    46  		Message: message,
    47  	}
    48  }