コード例 #1
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 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();
   }
 }
コード例 #2
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /**
  * 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;
 }
コード例 #3
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /** 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");
   }
 }
コード例 #4
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /**
  * 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;
 }
コード例 #5
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
  /** 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;
  }
コード例 #6
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /** Formats a new line statement. */
 private void formatNewLine() {
   if (lexer.atCommandEnd()) append(lexer.getNext(), Syntax.Null);
 }
コード例 #7
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /** Formats a motor direction statement. */
 private void formatDirection() {
   if (NXTalk.getDirection(lexer.peekNext()) != null) append(lexer.getNext(), Syntax.Direction);
 }
コード例 #8
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /** Formats one or more motors. */
 private void formatMotors() {
   while (lexer.hasNext() && NXTalk.getMotor(lexer.peekNext()) != null)
     append(lexer.getNext(), Syntax.Motor);
 }
コード例 #9
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /** Formats an operator. */
 private void formatOperator() {
   append(lexer.getNext(), Syntax.Operator);
   if (lexer.atCommandEnd()) append();
 }
コード例 #10
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /**
  * 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()));
 }
コード例 #11
0
ファイル: NXTalkFormatter.java プロジェクト: zacklukem/NXTalk
 /**
  * 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);
 }