Switched to expression-based timestamps
This commit is contained in:
parent
7bf586757a
commit
5c89c44ff7
7 changed files with 215 additions and 151 deletions
35
cmds/timestamps/input.go
Normal file
35
cmds/timestamps/input.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/participle/v2"
|
||||
"github.com/alecthomas/participle/v2/lexer"
|
||||
)
|
||||
|
||||
var basicLexer = lexer.MustSimple([]lexer.SimpleRule{
|
||||
{"Identifier", `[a-zA-Z_][a-zA-Z0-9_]*`},
|
||||
{"Date", `\d{4}-\d{2}-\d{2}`},
|
||||
{"Timestamp", `\d{4}-\d{2}-\d{2}T?\d{2}:\d{2}:\d{2}Z?`},
|
||||
{"Time", `\d{2}:\d{2}:\d{2}Z?`},
|
||||
{"Int", `\d+`},
|
||||
{"Whitespace", `[ ]+`},
|
||||
})
|
||||
|
||||
var parser = participle.MustBuild[Atom](
|
||||
participle.Lexer(basicLexer),
|
||||
participle.Elide("Whitespace"),
|
||||
)
|
||||
|
||||
func Parse(expr string) (TimeResult, error) {
|
||||
res, err := parser.ParseString("expr", expr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
type TimeResult interface {
|
||||
Time() (time.Time, error)
|
||||
RequiresRefreshing() bool
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue