Package com.sonar.sslr.api

Examples of com.sonar.sslr.api.PreprocessorAction


    // Every identifier and every keyword can be a macro instance.
    // Pipe the resulting string through a lexer to create proper Tokens
    // and to expand recursively all macros which may be in there.
    //

    PreprocessorAction ppaction = PreprocessorAction.NO_OPERATION;
    Macro macro = macros.get(curr.getValue());
    if (macro != null) {
      List<Token> replTokens = new LinkedList<Token>();
      int tokensConsumed = 0;
      List<Token> arguments = new ArrayList<Token>();

      if (macro.params == null) {
        tokensConsumed = 1;
        replTokens = expandMacro(macro.name, serialize(evaluateHashhashOperators(macro.body)));
      }
      else {
        int tokensConsumedMatchingArgs = expandFunctionLikeMacro(macro.name,
            tokens.subList(1, tokens.size()),
            replTokens);
        if (tokensConsumedMatchingArgs > 0) {
          tokensConsumed = 1 + tokensConsumedMatchingArgs;
        }
      }

      if (tokensConsumed > 0) {
        replTokens = reallocate(replTokens, curr);

        LOG.trace("[{}:{}]: replacing '" + curr.getValue()
          + (arguments.isEmpty()
              ? ""
              : "(" + serialize(arguments, ", ") + ")") + "' -> '" + serialize(replTokens) + "'",
            filename, curr.getLine());

        ppaction = new PreprocessorAction(
            tokensConsumed,
            Lists.newArrayList(Trivia.createSkippedText(tokens.subList(0, tokensConsumed))),
            replTokens);
      }
    }
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.