Class AbstractNamedParametrizedInstructionParser
java.lang.Object
dev.zemco.codegame.compilation.parsing.AbstractNamedParametrizedInstructionParser
- All Implemented Interfaces:
IInstructionParser
- Direct Known Subclasses:
FactorySingleParameterInstructionParser,SupplierInstructionParser
public abstract class AbstractNamedParametrizedInstructionParser
extends Object
implements IInstructionParser
Abstract base for
instruction parsers parsing a single named
instruction encoded with parameters separated by whitespace.
First part of a raw instruction is treated as the instruction name.- Author:
- Erik Zemčík
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractNamedParametrizedInstructionParser(String instructionName) Initializes a subclass instance ofAbstractNamedParametrizedInstructionParserthat parses a parametrizedinstructionwith the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckParameterFixedCount(String[] parameters, int parameterCount) Checks if the given parameters have a required fixed count.parseInstruction(String rawInstruction) Parses a singleinstructionencoded in a givenstring.protected abstract Optional<IInstruction>parseInstructionFromParameters(String[] parameters) Parses the namedinstructionfrom its given parameters.
-
Constructor Details
-
AbstractNamedParametrizedInstructionParser
Initializes a subclass instance ofAbstractNamedParametrizedInstructionParserthat parses a parametrizedinstructionwith the given name.- Parameters:
instructionName- name of theinstructionto parse- Throws:
IllegalArgumentException- ifinstructionNameisnull
-
-
Method Details
-
parseInstructionFromParameters
Parses the namedinstructionfrom its given parameters. This method may return an emptyoptional, if the parser does not support the given rawinstruction.- Parameters:
parameters- raw instruction parameters- Returns:
- parsed
instructionor an emptyoptional
-
parseInstruction
Description copied from interface:IInstructionParserParses a singleinstructionencoded in a givenstring. This method may return an emptyoptional, if the parser does not support the given rawinstruction.- Specified by:
parseInstructionin interfaceIInstructionParser- Parameters:
rawInstruction-instructionencoded in astring- Returns:
- parsed
instructionor an emptyoptional
-
checkParameterFixedCount
Checks if the given parameters have a required fixed count. This method is intended to be used by subclasses which require a fixed parameter count for theirinstructionparsing.- Parameters:
parameters- instruction parametersparameterCount- expected fixed instruction parameter count- Throws:
IllegalArgumentException- ifparametersisnullor ifparameterCountis not a positive integerInstructionParseException- if the count of parameters does not match the requestedparameterCount
-