()
| 201 | } |
| 202 | |
| 203 | function parsePrimary() { |
| 204 | const token = tokens[i]; |
| 205 | switch (token.type) { |
| 206 | case 'boolean': { |
| 207 | i++; |
| 208 | return t.booleanLiteral(token.value); |
| 209 | } |
| 210 | case 'name': { |
| 211 | i++; |
| 212 | return t.memberExpression(ctxIdentifier, t.identifier(token.name)); |
| 213 | } |
| 214 | case 'string': { |
| 215 | i++; |
| 216 | return t.stringLiteral(token.value); |
| 217 | } |
| 218 | case '(': { |
| 219 | i++; |
| 220 | const expression = parseExpression(); |
| 221 | const closingParen = tokens[i]; |
| 222 | if (closingParen === undefined || closingParen.type !== ')') { |
| 223 | throw Error('Expected closing )'); |
| 224 | } |
| 225 | i++; |
| 226 | return expression; |
| 227 | } |
| 228 | default: { |
| 229 | throw Error('Unexpected token: ' + token.type); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | const program = parseExpression(); |
| 235 | if (tokens[i] !== undefined) { |
no test coverage detected