alecthomas / alecthomas/participle
Missing Position when Capture errors
- Langage dominant
- Go
- Étoiles
- 3.9k
- Forks
- 213
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Running this code produces a ParseError (as expected), but the error doesn't have position information:
```
package main
import (
"fmt"
"time"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
)
type Expression struct {
Alias string `@Ident "="`
Timestamp *Timestamp `@Number`
}
type Timestamp int64
func (ts *Timestamp) Capture(values []string) error {
t, err := time.Parse("2006", values[0])
if err != nil {
return err
}
*ts = Timestamp(t.Unix())
return nil
}
var exprLexer = lexer.MustSimple([]lexer.Rule{
{"Whitespace", `\s+`, nil},
{"String", `"(\\"|[^"])*"`, nil},
{"Number", `[-+]?(\d*\.)?\d+`, nil},
{"Ident", `[a-zA-Z_]\w*`, nil},
{"Punct", `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`, nil},
})
func main() {
parser := participle.MustBuild(&Expression{}, participle.Lexer(exprLexer), participle.Unquote(), participle.Elide("Whitespace"))
expr := &Expression{}
err := parser.ParseString("", "foo = 03", expr)
if err != nil {
parseErr := err.(participle.Error)
fmt.Println("error at position", parseErr.Position(), parseErr)
return
}
fmt.Println("success:", expr.Alias, "=", *expr.Timestamp)
}
```
The output is:
```
error at position 0:0 Expression.Timestamp: parsing time "03" as "2006": cannot parse "03" as "2006"
```
(using github.com/alecthomas/participle/v2 v2.0.0-alpha7)
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.