Class PipelineParser
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA token from tokenization -- either text or an operator. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new PipelineParser with default operator symbols fromPipeline.Operator.PipelineParser(Map<String, Pipeline.Operator> customOperators) Creates a new PipelineParser with custom operator symbol mappings. -
Method Summary
-
Constructor Details
-
PipelineParser
public PipelineParser()Creates a new PipelineParser with default operator symbols fromPipeline.Operator. -
PipelineParser
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 toPipeline.Operator
-
-
Method Details
-
parse
-
matchOperator
Tries to match a pipeline operator at the given position. Returns the matched operator string, ornull.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 stringpos- the current position in the line- Returns:
- the matched operator string, or null if no operator matches
-