|
| 1 | +const { log, err, warn, info, json, success } = require('../../helpers/logger'); |
| 2 | + |
| 3 | +module.exports = (peek, consume, peekBack, recall, nextLine, parse) => { |
| 4 | + console.log(peek()); |
| 5 | + if (peek().type == "CLASS") { |
| 6 | + // Class creation |
| 7 | + consume(); |
| 8 | + if (peek().type != "ID") |
| 9 | + err(`Expected 'ID' but got '${consume().type}'`); |
| 10 | + let className = consume().value; |
| 11 | + console.log(peek()); |
| 12 | + if (peek().type != "BRACE_OPEN") |
| 13 | + err(`Expected '{' but got '${consume().type}'`); |
| 14 | + consume(); |
| 15 | + let code = []; |
| 16 | + do { |
| 17 | + let parsed = parse(peek()); |
| 18 | + if (parsed) |
| 19 | + code.push(parsed); |
| 20 | + } while (peek().type != "BRACE_CLOSE"); |
| 21 | + consume(); |
| 22 | + return { |
| 23 | + type: 'CLASS', |
| 24 | + name: className, |
| 25 | + code: code |
| 26 | + }; |
| 27 | + } else { |
| 28 | + // New class instance |
| 29 | + consume(); |
| 30 | + if (peek().type != "ID") |
| 31 | + err(`Expected 'ID' but got '${consume().type}'`); |
| 32 | + let initializer = parse(peek()); |
| 33 | + console.log(peek()); |
| 34 | + return { |
| 35 | + type: 'CLASS_INSTANCE', |
| 36 | + name: initializer.function, |
| 37 | + args: initializer.args |
| 38 | + }; |
| 39 | + } |
| 40 | +} |
0 commit comments