Class PipelineParser
- java.lang.Object
-
- org.jline.shell.impl.PipelineParser
-
public class PipelineParser extends java.lang.ObjectParses a command line string into aPipeline.By default, the parser recognizes all operators defined in
Pipeline.Operator, using their default symbols. Custom symbol mappings can be provided via thePipelineParser(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 anPipeline.Operatorthat 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 Classes Modifier and Type Class Description protected static classPipelineParser.TokenA token from tokenization -- either text or an operator.
-
Constructor Summary
Constructors Constructor Description PipelineParser()Creates a new PipelineParser with default operator symbols fromPipeline.Operator.PipelineParser(java.util.Map<java.lang.String,Pipeline.Operator> customOperators)Creates a new PipelineParser with custom operator symbol mappings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringmatchOperator(java.lang.String line, int pos)Tries to match a pipeline operator at the given position.Pipelineparse(java.lang.String line)Parses a command line into aPipeline.
-
-
-
Constructor Detail
-
PipelineParser
public PipelineParser()
Creates a new PipelineParser with default operator symbols fromPipeline.Operator.
-
PipelineParser
public PipelineParser(java.util.Map<java.lang.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 toPipeline.Operator
-
-
Method Detail
-
parse
public Pipeline parse(java.lang.String line)
Parses a command line into aPipeline.- Parameters:
line- the command line to parse- Returns:
- the parsed pipeline
-
matchOperator
protected java.lang.String matchOperator(java.lang.String line, int pos)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
-
-