Class PipelineParser

java.lang.Object
org.jline.shell.impl.PipelineParser

public class PipelineParser extends Object
Parses a command line string into a Pipeline.

By default, the parser recognizes all operators defined in Pipeline.Operator, using their default symbols. Custom symbol mappings can be provided via the PipelineParser(Map) constructor to override default symbols:

 // Replace > and >> with |> and |>> (e.g. for Groovy)
 new PipelineParser(Map.of("|>", Operator.REDIRECT, "|>>", Operator.APPEND))
 
When a custom mapping targets an Pipeline.Operator that already has a default symbol, the default symbol is replaced. This allows languages where > has a different meaning to use alternative redirect syntax.

The parser respects quoting (single and double) and bracket nesting, so operators inside quoted strings or brackets are not treated as pipeline operators.

Subclasses can override matchOperator(String, int) to customize operator matching beyond what the constructor-based approach supports.

Since:
4.0
  • Constructor Details

    • PipelineParser

      public PipelineParser()
      Creates a new PipelineParser with default operator symbols from Pipeline.Operator.
    • PipelineParser

      public PipelineParser(Map<String,Pipeline.Operator> customOperators)
      Creates a new PipelineParser with custom operator symbol mappings.

      Each entry maps a symbol string to an Pipeline.Operator. If a custom mapping targets an operator that already has a default symbol, the default symbol is removed and replaced by the custom one. For example:

       // "|>" replaces ">" for REDIRECT, "|>>" replaces ">>" for APPEND
       new PipelineParser(Map.of("|>", Operator.REDIRECT, "|>>", Operator.APPEND))
       
      Operators not mentioned in the custom map keep their default symbols.
      Parameters:
      customOperators - a map from operator symbol to Pipeline.Operator
  • Method Details

    • parse

      public Pipeline parse(String line)
      Parses a command line into a Pipeline.
      Parameters:
      line - the command line to parse
      Returns:
      the parsed pipeline
    • matchOperator

      protected String matchOperator(String line, int pos)
      Tries to match a pipeline operator at the given position. Returns the matched operator string, or null.

      The default implementation checks all operators in the operator table (longest-match first). Subclasses can override this method for fully custom matching logic.

      Parameters:
      line - the full command line string
      pos - the current position in the line
      Returns:
      the matched operator string, or null if no operator matches