private void formatTerminal() { if (canFormatScalarTerminal()) { formatScalarTerminal(); formatUnit(); } else if (NXTalk.getSensor(lexer.peekNext()) != null) formatSensorTerminal(); else if (lexer.peekNext().equals(NXTalk.stringDelimiter)) formatStringTerminal(); else if (lexer.peekNext().equals("yes") || lexer.peekNext().equals("no")) append(lexer.getNext(), Syntax.Boolean); else if (recognizedSymbols.contains(lexer.peekNext())) { append(lexer.getNext(), Syntax.Symbol); formatUnit(); } }
/** * Skips the next token if it matches the given input, and appends it to the output formatting * stream with the given syntax value. */ private boolean skipNext(String token, int syntax) { if (lexer.hasNext() && lexer.peekNext().equals(token)) { append(lexer.getNext(), syntax); return true; } return false; }
/** Formats one or more motor directives that are appended to the end of motor commands. */ private void formatMotorDirectives() { if (lexer.atCommandEnd()) return; while (NXTalk.getMotorDirective(lexer.peekNext()) != null) { append(lexer.getNext(), Syntax.MotorDirective); skipNext("and"); } }
/** * Formats a loop command. * * @return */ private boolean formatLoopCommand() { Loop l = NXTalk.getLoop(lexer.peekNext()); if (l == null) return false; append(lexer.getNext(), Syntax.Loop); formatExpression(); return true; }
/** Formats the text input. */ public NXTalkFormatterOutput formatInput(String input, int caretPosition) { // Reset the output data structures output.reset(); // Set the output data structures and lex the input text output.set(input); lexer.lex(input); caret = caretPosition; // Go through each token in the input stream, and pass it to a // coloring function if it matches certain key phrases. while (lexer.hasNext()) { // Passes commands to a command formatter if (formatCommand()) { } // Passes loop commands to a loop formatter else if (formatLoopCommand()) { } else append(lexer.getNext(), Syntax.Null); } output.setCaretPosition(caret); return output; }
/** Formats a new line statement. */ private void formatNewLine() { if (lexer.atCommandEnd()) append(lexer.getNext(), Syntax.Null); }
/** Formats a motor direction statement. */ private void formatDirection() { if (NXTalk.getDirection(lexer.peekNext()) != null) append(lexer.getNext(), Syntax.Direction); }
/** Formats one or more motors. */ private void formatMotors() { while (lexer.hasNext() && NXTalk.getMotor(lexer.peekNext()) != null) append(lexer.getNext(), Syntax.Motor); }
/** Formats an operator. */ private void formatOperator() { append(lexer.getNext(), Syntax.Operator); if (lexer.atCommandEnd()) append(); }
/** * Appends the next token in the lexer output to the NXTalkFormatterOutput instance, inferring the * syntax type of the token. */ private void append() { append(lexer.peekNext(), lexer.getDictionary().contains(lexer.getNext())); }
/** * Appends the next token in the lexer output to the NXTalkFormatterOutput instance, with the * given syntax type. */ private void append(int syntaxType) { append(lexer.getNext(), syntaxType); }