OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-wire / expr / expr.peg
1 {
2 package expr
3
4 import (
5         "bytes"
6   "encoding/hex"
7         "errors"
8         "fmt"
9         "io"
10         "io/ioutil"
11         "os"
12   "strconv"
13         "strings"
14         "unicode"
15         "unicode/utf8"
16 )
17 }
18
19 Start ← items_:Item+ _ EOF {
20     items := items_.([]interface{})
21     if len(items) == 1 {
22         return items[0], nil
23     }
24     return Tuple(items), nil
25 }
26
27 Item ← _ it:(Array / Tuple / Hex / TypedNumeric / UntypedNumeric / Placeholder / String) {
28     return it, nil
29 }
30
31 Array ← '[' items:Item* _ ']' {
32     return Array(items.([]interface{})), nil
33 }
34
35 Tuple ← '(' items:Item+ _ ')' {
36     return Tuple(items.([]interface{})), nil
37 }
38
39 UntypedNumeric ← number:Integer {
40     return Numeric{
41       Type: "i",
42       Number: number.(string),
43     }, nil
44 }
45
46 TypedNumeric ← t:Type ':' number:Integer {
47     return Numeric{
48       Type: t.(string),
49       Number: number.(string),
50     }, nil
51 }
52
53 Hex ← HexLengthPrefixed / HexRaw
54
55 HexLengthPrefixed ← "0x" hexbytes:HexBytes {
56     return NewBytes(hexbytes.([]byte), true), nil
57 }
58
59 HexRaw ← "x" hexbytes:HexBytes {
60     return NewBytes(hexbytes.([]byte), false), nil
61 }
62
63 HexBytes ← [0-9abcdefABCDEF]+ {
64     bytez, err := hex.DecodeString(string(c.text))
65     if err != nil {
66         return nil, err
67     }
68     return bytez, nil
69 }
70
71 Type ← ("u64" / "i64") {
72     return string(c.text), nil
73 }
74
75 Integer ← '-'? [0-9]+ {
76     return string(c.text), nil
77 }
78
79 Label ← [0-9a-zA-Z:]+ {
80     return string(c.text), nil
81 }
82
83 Placeholder ← '<' label:Label '>' {
84     return Placeholder{
85       Label: label.(string),
86     }, nil
87 }
88
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))
93     if err != nil {
94       return nil, err
95     } else {
96       return NewString(text), nil
97     }
98 }
99
100 EscapedChar ← [\x00-\x1f"\\]
101
102 EscapeSequence ← SingleCharEscape / UnicodeEscape
103
104 SingleCharEscape ← ["\\/bfnrt]
105
106 UnicodeEscape ← 'u' HexDigit HexDigit HexDigit HexDigit
107
108 HexDigit ← [0-9a-f]i
109
110 _ "whitespace" ← [ \n\t\r]*
111
112 EOF ← !.