Class PreprocessorAction

java.lang.Object
com.sonar.sslr.api.PreprocessorAction

@Deprecated public class PreprocessorAction extends Object
Deprecated.
in 1.20, use your own preprocessor API instead.
This class encapsulates the actions to be performed by a preprocessor.
  • Field Details

    • NO_OPERATION

      public static final PreprocessorAction NO_OPERATION
      Deprecated.

      Use this no operation preprocessor action for improved readability and performances.

      Equivalent to: new PreprocessorAction(0, new ArrayList<Trivia>(), new ArrayList<Token>());

  • Constructor Details

    • PreprocessorAction

      public PreprocessorAction(int numberOfConsumedTokens, List<Trivia> triviaToInject, List<Token> tokensToInject)
      Deprecated.

      Construct a preprocessor action.

      The actions are executed in this order:

      1. Deletions of tokens, handled by numberOfConsumedTokens
      2. Injections of trivia, handled by triviaToInject
      3. Injections of tokens, handled by tokensToInject

      Preprocessor actions are executed as follows:

      1. If numberOfConsumedTokens is greater than 0, then this number of tokens are deleted. Their trivia is added to a pending list of trivia. The preprocessor will not be called on deleted tokens.
      2. All trivia from triviaToInject are added to the same pending list of trivia
      3. All tokens from tokensToInject are injected. If present, the first token of tokensToInject is augmented with the pending trivia, which is then cleared. If not present, the pending trivia is left unchanged.
      4. Finally, if numberOfConsumedTokens was 0, the current token is injected, with any pending trivia which is then cleared.

      A few examples:
      • No operation action: new PreprocessorAction(0, new ArrayList<Trivia>(), new ArrayList<Token>());
      • Delete current token action: new PreprocessorAction(1, new ArrayList<Trivia>(), new ArrayList<Token>());
      • Modify current token action: new PreprocessorAction(1, new ArrayList<Trivia>(), Arrays.asList(modifiedToken));
      • Inject trivia to current token action: new PreprocessorAction(0, Arrays.asList(newTrivia), new ArrayList<Token>());
      Parameters:
      numberOfConsumedTokens - Number of tokens consumed by the preprocessor, which can be 0. Consumed tokens are deleted and will not lead to successive calls to the preprocessor.
      triviaToInject - Trivia to inject.
      tokensToInject - Tokens to inject. Injected tokens will not lead to successive calls to the preprocessor.
  • Method Details

    • getNumberOfConsumedTokens

      public int getNumberOfConsumedTokens()
      Deprecated.
    • getTriviaToInject

      public List<Trivia> getTriviaToInject()
      Deprecated.
    • getTokensToInject

      public List<Token> getTokensToInject()
      Deprecated.