@Override public Token parse() { Token next = first.getNext(); if (!next.isOperator(Operator.BRACKET_LEFT)) throw new RuntimeException("Expected '(' after WHILE, found: " + next); next = next.getNext(); testExp = new BooleanExpression(next, scope); next = testExp.parse(); if (!next.isOperator(Operator.BRACKET_RIGHT)) throw new RuntimeException("Expected ')' after WHILE condition, found: " + next); next = next.getNext(); if (!next.isNewline()) throw new RuntimeException("Expected newline, found: " + next); next = next.getNext(); Keyword[] target = {Keyword.END}; statements = new StatementGroup(next, target, scope); next = statements.parse(); return next.getNext(); }
@Override public Token parse() { funcName = first.getNext(); if (!funcName.isIdentifier()) throw new RuntimeException("Expected identifier for function name, found: " + funcName); GluonFunction.registerFunction(funcName.getValue()); Token test = funcName.getNext(); if (!test.isOperator(Operator.BRACKET_LEFT)) throw new RuntimeException("Expected '(' for function parmater list, found: " + test); test = test.getNext(); while (test.isIdentifier()) { Variable param = new Variable(test, scope, true); parameters.add(param); test = param.parse(true); if (test.isOperator(Operator.COMMA)) test = test.getNext(); } if (!test.isOperator(Operator.BRACKET_RIGHT)) throw new RuntimeException("Expected ')' for function parmater list, found: " + test); test = test.getNext(); if (!test.isOperator(Operator.COLON) && !test.isOperator(Operator.BRACE_LEFT)) throw new RuntimeException("Expected ':' or '{' in function def, found: " + test); if (test.isOperator(Operator.COLON)) { test = funcName.getNext(); if (!test.isOperator(Operator.BRACKET_LEFT)) throw new RuntimeException("Expected '(' for function return list, found: " + test); test = test.getNext(); while (test.isIdentifier()) { returns.add(test); test = test.getNext(); if (test.isOperator(Operator.COMMA)) test = test.getNext(); } if (!test.isOperator(Operator.BRACKET_RIGHT)) throw new RuntimeException("Expected ')' for function return list, found: " + test); } if (!test.isOperator(Operator.BRACE_LEFT)) throw new RuntimeException("Expected opening brace for function logic, found: " + test); test = test.getNext(); if (!test.isNewline()) throw new RuntimeException("Expected newline before function logic, found: " + test); test = test.getNext(); Operator[] targets = {Operator.BRACE_RIGHT}; logic = new StatementGroup(test, targets, scope); test = logic.parse(); if (!test.isOperator(Operator.BRACE_RIGHT)) throw new RuntimeException("Expected closing brace for function logic, found: " + test); return test.getNext(); }