Package com.sonar.sslr.api

Examples of com.sonar.sslr.api.PreprocessorAction


                .setURI(token.getURI())
                .setType(CxxTokenType.STRING)
                .setValueAndOriginalValue("\"" + stripQuotes(token.getValue()) + sb.toString() + "\"")
                .build()
            );
        return new PreprocessorAction(numberOfStrings, Collections.EMPTY_LIST, tokensToInject);
      }

      return PreprocessorAction.NO_OPERATION;
    }
    return PreprocessorAction.NO_OPERATION;
View Full Code Here


      AstNode lineAst = null;
      try {
        lineAst = pplineParser.parse(token.getValue()).getFirstChild();
      } catch (com.sonar.sslr.api.RecognitionException re) {
        LOG.warn("Cannot parse '{}', ignoring...", token.getValue());
        return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
      }

      String lineKind = lineAst.getName();

      if ("ifdefLine".equals(lineKind)) {
        return handleIfdefLine(lineAst, token, filePath);
      } else if ("elseLine".equals(lineKind)) {
        return handleElseLine(lineAst, token, filePath);
      } else if ("endifLine".equals(lineKind)) {
        return handleEndifLine(lineAst, token, filePath);
      } else if ("ifLine".equals(lineKind)) {
        return handleIfLine(lineAst, token, filePath);
      } else if ("elifLine".equals(lineKind)) {
        return handleElIfLine(lineAst, token, filePath);
      }

      if (inSkippingMode()) {
        return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
      }

      if ("defineLine".equals(lineKind)) {
        return handleDefineLine(lineAst, token, filePath);
      } else if ("includeLine".equals(lineKind)) {
        return handleIncludeLine(lineAst, token, filePath);
      } else if ("undefLine".equals(lineKind)) {
        return handleUndefLine(lineAst, token, filePath);
      }

      // Ignore all other preprocessor directives (which are not handled explicitly)
      // and strip them from the stream

      return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
    }

    if (ttype != EOF) {
      if (inSkippingMode()) {
        return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
      }

      if (ttype != STRING && ttype != NUMBER) {
        return handleIdentifiersAndKeywords(tokens, token, filePath);
      }
View Full Code Here

            new Object[] {filename, token.getLine(), token.getValue()});
        state.skipping = true;
      }
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

      }

      state.skipping = !state.skipping;
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

        LOG.trace("[{}:{}]: #endif, returning to non-skipping mode", filename, token.getLine());
      }
      state.skipping = false;
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

        LOG.trace("[{}:{}]: '{}' evaluated to false, skipping tokens that follow",
            new Object[] {filename, token.getLine(), token.getValue()});
      }
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

        state.skipping = !state.skipping;
        LOG.trace("[{}:{}]: skipping tokens inside the #elif", filename, token.getLine());
      }
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

    if (macro != null) {
      LOG.trace("[{}:{}]: storing macro: '{}'", new Object[] {filename, token.getLine(), macro});
      macros.put(macro.name, macro);
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

    }
    else {
      LOG.debug("[{}:{}]: skipping already included file '{}'", new Object[] {filename, token.getLine(), includedFile});
    }

    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

  }

  PreprocessorAction handleUndefLine(AstNode ast, Token token, String filename) {
    String macroName = ast.getFirstDescendant(IDENTIFIER).getTokenValue();
    macros.removeLowPrio(macroName);
    return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
  }
View Full Code Here

TOP

Related Classes of com.sonar.sslr.api.PreprocessorAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.