/* This file is used with goyacc to generate a parser. See https://godoc.org/golang.org/x/tools/cmd/goyacc for more about goyacc. */ %{ package datemath import ( "fmt" "math" "time" ) var epoch = time.Unix(0, 0).In(time.UTC) // convert a list of significant digits to an integer // assumes most to least significant // e.g. 5,2,3 -> 523 func digitsToInt(digits ...int) int { n := 0 for i := range digits { n += digits[i] * int(math.Pow10(len(digits)-i-1)) } return n } %} /* set of valid tokens; generated constants used by lexer */ %token tNOW tPLUS tMINUS tPIPES tBACKSLASH tTIME_DELIMITER tCOLON tDOT tUNIT tUTC tDIGIT tINVALID_TOKEN /* Go variables to hold the corresponding token values */ %union { i64 int64 i int unit timeUnit month time.Month expression mathExpression anchorDateExpression anchorDateExpression timeAdjuster timeAdjuster timeAdjusters []timeAdjuster location *time.Location time time.Time } /* associate tokens with Go types */ %type tUNIT %type sign factor number year day hour minute second nanoseconds tDIGIT %type month %type expression %type