Class DelegatingInstructionParser
java.lang.Object
dev.zemco.codegame.compilation.parsing.DelegatingInstructionParser
- All Implemented Interfaces:
IInstructionParser
Implementation of an
instruction parser that delegates parsing to other provided
parsers. The first successfully parsed instruction is used as an output.
The used parsers cannot be changed after construction.- Author:
- Erik Zemčík
-
Constructor Summary
ConstructorsConstructorDescriptionDelegatingInstructionParser(List<IInstructionParser> instructionParsers) Creates an instance ofDelegatingInstructionParserthat delegatesinstructionparsing to given parsers. -
Method Summary
Modifier and TypeMethodDescriptionparseInstruction(String rawInstruction) Delegates parsing of a singleinstructionencoded in a givenstringto given parsers.
-
Constructor Details
-
DelegatingInstructionParser
Creates an instance ofDelegatingInstructionParserthat delegatesinstructionparsing to given parsers.- Parameters:
instructionParsers- instruction parsers to use for parsing- Throws:
IllegalArgumentException- ifinstructionParsersisnull
-
-
Method Details
-
parseInstruction
Delegates parsing of a singleinstructionencoded in a givenstringto given parsers. This method may return an emptyoptional, if no parsers support the given rawinstruction.- Specified by:
parseInstructionin interfaceIInstructionParser- Parameters:
rawInstruction-instructionencoded in astring- Returns:
- parsed
instructionor an emptyoptional - Throws:
IllegalArgumentException- ifrawInstructionisnullor emptyInstructionParseException- if any provided parser fails to decoderawInstruction
-