|
1 | 1 | package vibes |
2 | 2 |
|
3 | | -import ( |
4 | | - "fmt" |
5 | | -) |
6 | | - |
7 | 3 | func (p *parser) parseExpression(precedence int) Expression { |
8 | 4 | prefix := p.prefixFns[p.curToken.Type] |
9 | 5 | if prefix == nil { |
@@ -124,81 +120,6 @@ func (p *parser) parseGroupedExpression() Expression { |
124 | 120 | return expr |
125 | 121 | } |
126 | 122 |
|
127 | | -func (p *parser) parseArrayLiteral() Expression { |
128 | | - pos := p.curToken.Pos |
129 | | - elements := []Expression{} |
130 | | - |
131 | | - if p.peekToken.Type == tokenRBracket { |
132 | | - p.nextToken() |
133 | | - return &ArrayLiteral{Elements: elements, position: pos} |
134 | | - } |
135 | | - |
136 | | - p.nextToken() |
137 | | - elements = append(elements, p.parseExpression(lowestPrec)) |
138 | | - |
139 | | - for p.peekToken.Type == tokenComma { |
140 | | - p.nextToken() |
141 | | - p.nextToken() |
142 | | - elements = append(elements, p.parseExpression(lowestPrec)) |
143 | | - } |
144 | | - |
145 | | - if !p.expectPeek(tokenRBracket) { |
146 | | - return nil |
147 | | - } |
148 | | - |
149 | | - return &ArrayLiteral{Elements: elements, position: pos} |
150 | | -} |
151 | | - |
152 | | -func (p *parser) parseHashLiteral() Expression { |
153 | | - pos := p.curToken.Pos |
154 | | - pairs := []HashPair{} |
155 | | - |
156 | | - if p.peekToken.Type == tokenRBrace { |
157 | | - p.nextToken() |
158 | | - return &HashLiteral{Pairs: pairs, position: pos} |
159 | | - } |
160 | | - |
161 | | - p.nextToken() |
162 | | - if pair := p.parseHashPair(); pair.Key != nil { |
163 | | - pairs = append(pairs, pair) |
164 | | - } |
165 | | - |
166 | | - for p.peekToken.Type == tokenComma { |
167 | | - p.nextToken() |
168 | | - p.nextToken() |
169 | | - if pair := p.parseHashPair(); pair.Key != nil { |
170 | | - pairs = append(pairs, pair) |
171 | | - } |
172 | | - } |
173 | | - |
174 | | - if !p.expectPeek(tokenRBrace) { |
175 | | - return nil |
176 | | - } |
177 | | - |
178 | | - return &HashLiteral{Pairs: pairs, position: pos} |
179 | | -} |
180 | | - |
181 | | -func (p *parser) parseHashPair() HashPair { |
182 | | - if !isLabelNameToken(p.curToken.Type) || p.peekToken.Type != tokenColon { |
183 | | - p.addParseError(p.curToken.Pos, "invalid hash pair: expected symbol-style key like name:") |
184 | | - return HashPair{} |
185 | | - } |
186 | | - |
187 | | - key := &SymbolLiteral{Name: p.curToken.Literal, position: p.curToken.Pos} |
188 | | - p.nextToken() |
189 | | - p.nextToken() |
190 | | - if p.curToken.Type == tokenComma || p.curToken.Type == tokenRBrace { |
191 | | - p.addParseError(p.curToken.Pos, fmt.Sprintf("missing value for hash key %s", key.Name)) |
192 | | - return HashPair{} |
193 | | - } |
194 | | - |
195 | | - value := p.parseExpression(lowestPrec) |
196 | | - if value == nil { |
197 | | - return HashPair{} |
198 | | - } |
199 | | - return HashPair{Key: key, Value: value} |
200 | | -} |
201 | | - |
202 | 123 | func (p *parser) parsePrefixExpression() Expression { |
203 | 124 | pos := p.curToken.Pos |
204 | 125 | operator := p.curToken.Type |
|
0 commit comments