19 Start ← items_:Item+ _ EOF {
20 items := items_.([]interface{})
24 return Tuple(items), nil
27 Item ← _ it:(Array / Tuple / Hex / TypedNumeric / UntypedNumeric / Placeholder / String) {
31 Array ← '[' items:Item* _ ']' {
32 return Array(items.([]interface{})), nil
35 Tuple ← '(' items:Item+ _ ')' {
36 return Tuple(items.([]interface{})), nil
39 UntypedNumeric ← number:Integer {
42 Number: number.(string),
46 TypedNumeric ← t:Type ':' number:Integer {
49 Number: number.(string),
53 Hex ← HexLengthPrefixed / HexRaw
55 HexLengthPrefixed ← "0x" hexbytes:HexBytes {
56 return NewBytes(hexbytes.([]byte), true), nil
59 HexRaw ← "x" hexbytes:HexBytes {
60 return NewBytes(hexbytes.([]byte), false), nil
63 HexBytes ← [0-9abcdefABCDEF]+ {
64 bytez, err := hex.DecodeString(string(c.text))
71 Type ← ("u64" / "i64") {
72 return string(c.text), nil
75 Integer ← '-'? [0-9]+ {
76 return string(c.text), nil
79 Label ← [0-9a-zA-Z:]+ {
80 return string(c.text), nil
83 Placeholder ← '<' label:Label '>' {
85 Label: label.(string),
89 String ← '"' ( !EscapedChar . / '\\' EscapeSequence )* '"' {
90 // TODO : the forward slash (solidus) is not a valid escape in Go, it will
91 // fail if there's one in the string
92 text, err := strconv.Unquote(string(c.text))
96 return NewString(text), nil
100 EscapedChar ← [\x00-\x1f"\\]
102 EscapeSequence ← SingleCharEscape / UnicodeEscape
104 SingleCharEscape ← ["\\/bfnrt]
106 UnicodeEscape ← 'u' HexDigit HexDigit HexDigit HexDigit
110 _ "whitespace" ← [ \n\t\r]*