public abstract class Model extends Object
Compiler
.
parse(String[], msgr) V parse(String, msgr) // blanks are escaped ! | V / main parsing loop <========================================= \ | \ (recover after error!) \ V \ -------------------------------------- GENERATED CODE | | parseName /parseAbbrev/parsePositionals | | V | | | parse_Please not that the lexer process = the tokenization (implemented by| | | | | | | | ---------------------------------|--------------------- | | | V | | | V parseEnum | | V parseInt | | parseInit | | | V V | T_ERROR ERROR_UNKNOWN_NAME / \ \ / \_________\_________>THROW exception /
getOptToken()
and getNextArgToken()
) is
driven by the top-level parsing process:
A long-name option key and an argument token are all characters up to the
next whitespace (or end of input),
but a short-name option token is only the next character.Modifier and Type | Class and Description |
---|---|
protected class |
Model.ExcDuplicate
Thrown if option appears more than once.
|
protected class |
Model.ExcFinish
Thrown if "skip to next option" error recovery reaches end of input.
|
protected class |
Model.ExcNoData
Thrown if argument is needed, but end of line reached.
|
protected class |
Model.ExcNoData_allowed
Thrown if end of line reached when new positional option could start.
|
protected class |
Model.ExcUnknownOpt
Thrown if option name / abbrev is unknown.
|
protected class |
Model.ExcWrongType
Thrown if argument is of wrong type.
|
class |
Model.Pre20220613 |
class |
Model.SeemsToWorkForLinuxAndSomeWindowsVersions20220613 |
Modifier and Type | Field and Description |
---|---|
protected boolean |
boolresult
Result of trying the boolean parser.
|
protected int |
curArg
Number of the argument currently being parsed.
|
protected int |
curArgGroup
Number of the repeting group which is under parsing, or
-1
in case the fixed part is currently being parsed. |
protected String |
curOption
Human readable identification of the option currently being parsed.
|
CatalogByString |
descriptions
Filled in by generated code.
|
protected static Rational |
dummyRat |
boolean |
hasNonMetaOptions
Reflects whether there are any payload-options in the parsed command line.
|
protected int |
inputlength
Length of
inputstring . |
protected String |
inputstring
Input concatentated into one single string, only input data for
the parsing process.
|
protected Matcher |
matcher
Re-used matcher for the input, once loaded with string data,
then re-linked to different patterns.
|
protected Messages |
messages |
protected @Opt String |
nextAbbrev
Written to by
updateOptTokens() |
protected @Opt String |
nextArgToken
Argument token, written be
lookForArgToken() , when such a token could be parsed,
and read by type-specific scanners parseInt() , etc., and cleared again. |
protected @Opt String |
nextName
Written to by
updateOptTokens() |
protected boolean |
optTokenValid
Whether an opt token has been consumed and stored
to
nextName or to nextAbbrev . |
protected Pattern |
p_argRAUS
Pattern for arguments, ie sections without blanks, or only with
BACKSLASH-ESCAPED blanks.
|
protected static Pattern |
p_hideblanks
Pattern to recognize blank characters, for escaping them prior to parsing.
|
protected static Pattern |
p_option
Pattern for option keywords (long and short).
|
protected Pattern |
p_rest |
protected SimpleMessage.Generator<Location<String>> |
parseErrorGenerator |
protected boolean |
positionalPhase
Set by runtime code for correct end-of-cmdline handling.
|
protected boolean |
positionalsExplicit
Set by generated code, whenever a positional option has
already been set explicitly.
|
protected boolean |
positionalsFound
Set by generated code, whenever a positional option is set implicitly.
|
protected StringBuilder |
protocol
Text which reflects the parsing and interpretation process, for debugging only.
|
protected eu.bandm.tools.option.runtime.Model.ShellAdapter |
shellAdapter
can be changed by subclassing.
|
Constructor and Description |
---|
Model() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
_finalCheck()
Callback, overridden by compiled code.
|
protected abstract String |
_getMissingParams()
Is overridden in the generated code and concatenates the "longest names"
of all otions marked as required, but not present in the parsed input.
|
protected void |
ARG_ERROR(String msg)
Generate error message related to the current option, the argument number,
and (possibly) the repetition group number.
|
protected boolean |
canReenterRepetitionGroup()
Returns only true if the next consumable input is not an option key
(i.e.
|
protected abstract void |
checkActive()
The generated code will evaluate all conditions to activate/deactive
options in the GUI.
|
static String |
descriptionKeyForCommentField(String name)
Generated MuLi-Catalog key to store a (multilingual) comment field.
|
static String |
descriptionKeyForEnum(Class<?> cl)
Generated MuLi-Catalog key to store the description of an enum type.
|
static String |
descriptionKeyForEnum(MetaClass cl)
Generated MuLi-Catalog key to store the description of an enum type.
|
static String |
descriptionKeyForEnumItem(Class<?> cl,
Object item)
Generated MuLi-Catalog key to store the description of an enum item value.
|
protected void |
ERROR_plus()
Generate the error message that the repeting group of "plus" type is empty.
|
protected void |
ERROR_UNKNOWN_ABBREV()
Called from compiled code and the end of the switch between short optipn names.
|
protected void |
ERROR_UNKNOWN_NAME()
Called from compiled code and the end of the switch between long optipn names.
|
protected void |
ERROR(String s)
Only source of error messages.
|
protected void |
ERROR(String s,
Object rest) |
String |
getInputString()
Get parsing input, maybe constructred from a String-array.
|
String |
getMissingParams()
Get String of missing parameters, is empty if none are missing.
|
protected void |
getNextArgToken()
Decodes next argument token to consume, if this has not yet been done.
|
protected void |
getOptToken()
Test whether next input is an option key token.
|
String |
getParsingProtocol() |
protected void |
lookForArgToken()
Decode argument token, advance input, set nextArgToken for further processing.
|
abstract Model |
makeDefaultInstance()
Overriden by the generated code to make a constructor call of the actual
Model (sub-)class.
|
void |
parse(String[] args,
MessageReceiver<SimpleMessage<?>> mr)
The main entry for setting all values according to some
command line input, as reaching
public void main(String[])
from some exec system call. |
protected abstract void |
parseAbbrev(String s)
Callback, overridden by compiled code, which realizes a switch over all one character
option names.
|
protected boolean |
parseBool_optional()
Called by compiled code for "switch-type", argument-less options.
|
protected boolean |
parseBool_X()
Aux function, return whether the next token is a representation of
a boolean value, and put the result into
boolresult . |
protected boolean |
parseBool()
Called by compiled code for required boolean arguments.
|
protected char |
parseChar()
Deprecated.
To take a character value from the input text *verbatim* as an
option arguments' value is not a good idea, because one never knows
what the accidentally employed shell will do to special characters.
Instead use an integer value (possibly with hexadecimal input format).
|
protected <E extends Enum<E>> |
parseEnum(Class<E> enumclass)
Called by compiled code.
|
protected <E extends Enum<E>> |
parseEnumSet(Class<E> enumclass)
Called by compiled code.
FIXME: only the "compilable" enumItem is parsed, not a possibly "uncomilable" @value. |
protected double |
parseFloat()
Get the next argument token, parse it into a double value, invalidate
the argument token and return the value.
|
protected void |
parseInit(String opt,
boolean hasIt)
Called from compiled code when starting the parsing of the arguments for
a recognized/accepted option key.
|
protected int |
parseInt_16or10() |
protected int |
parseInt()
Get the next argument token, parse it into an integer value, invalidate
the argument token and return the value.
|
protected abstract void |
parseName(String s)
Callback, overridden by compiled code, which realizes a switch over all long
option names.
|
void |
parseOneString(String s,
MessageReceiver mr)
Central entry point in case the command line data is already
packed into one single String, with escaped blanks.
|
protected String |
parseOneUri()
Called by compiled code.
|
protected abstract void |
parsePositionals()
Callback, overridden by compiled code, which calls one after the other
the positional parameters.
|
protected Rational |
parseRational()
Get the next argument token, parse it into a rational value, invalidate
the argument token and return the value.
|
protected String |
parseString()
Called by compiled code.
|
protected void |
putprot_option(String s)
Append the name of the option and set parentheses.
|
protected void |
putprot(String s) |
abstract String |
serialize()
Called to generate a String representation of the model's state.
|
protected static String |
serialize(boolean value)
Called by compiled code.
|
protected static String |
serialize(char value)
Called by compiled code.
|
protected static String |
serialize(double value)
Called by compiled code.
|
protected static <E extends Enum<E>> |
serialize(E value)
Called by compiled code.
|
protected static <E extends Enum<E>> |
serialize(EnumSet<E> value)
Called by compiled code.
|
protected static String |
serialize(int value)
Called by compiled code.
|
protected static String |
serialize(Rational rat)
Called by compiled code.
|
protected String |
serialize(String value)
Called by compiled code.
|
protected void |
skipToOption()
Skip input to next option token, if not already done.
|
protected void |
T_ERROR(String msg)
Generate error message on wrong argument type and throw the corresponding exception.
|
protected void |
updateOptTokens()
Decide whether long or short name, and store it to
nextName or nextAbbrev . |
abstract void |
usage()
The generated code will print the documentation text of all options,
in the default language.
|
abstract void |
usage(String language)
The generated code will print the documentation text of all options,
in the given language.
|
protected void |
WARNING(String s)
Only source of warning messages.
|
protected eu.bandm.tools.option.runtime.Model.ShellAdapter shellAdapter
protected Messages messages
protected SimpleMessage.Generator<Location<String>> parseErrorGenerator
protected transient StringBuilder protocol
getParsingProtocol()
.
The entering the parsing of an option with name "xxx" is indicated by "xxx("
and the recognized argument types follow, like "int", "string", etc.public CatalogByString descriptions
public boolean hasNonMetaOptions
protected String inputstring
protected transient int inputlength
inputstring
. For conveniece,
because it is frequently used in Matcher set-ups.protected transient String curOption
protected transient int curArg
protected transient int curArgGroup
-1
in case the fixed part is currently being parsed.protected static final Pattern p_option
protected final Pattern p_rest
protected Pattern p_argRAUS
protected transient Matcher matcher
@Opt protected transient @Opt String nextArgToken
lookForArgToken()
, when such a token could be parsed,
and read by type-specific scanners parseInt()
, etc., and cleared again.protected transient boolean optTokenValid
nextName
or to nextAbbrev
. Invalidated after
its decoding and in parseInit(String, boolean)
.
For conveniece only. It always holds "(nextName!=null||nextAbbrev!=null) = optTokenValid"
and "!(nextName!=null&&nextAbbrev!=null)".@Opt protected transient @Opt String nextName
updateOptTokens()
@Opt protected transient @Opt String nextAbbrev
updateOptTokens()
protected boolean positionalsExplicit
protected boolean positionalsFound
protected boolean positionalPhase
protected static final Pattern p_hideblanks
protected static final Rational dummyRat
protected boolean boolresult
public abstract void usage()
public abstract void usage(String language)
protected abstract void checkActive()
protected void ERROR(String s)
protected void WARNING(String s)
protected void putprot(String s)
protected void putprot_option(String s)
public String getParsingProtocol()
public static String descriptionKeyForEnum(MetaClass cl)
public static String descriptionKeyForEnum(Class<?> cl)
public static String descriptionKeyForEnumItem(Class<?> cl, Object item)
public static String descriptionKeyForCommentField(String name)
public abstract Model makeDefaultInstance()
protected abstract void _finalCheck()
protected abstract void parseAbbrev(String s)
s
- the one-character option name, as parsed by this code.protected abstract void parseName(String s)
s
- the multi-character option name, as parsed by this code.protected abstract void parsePositionals()
protected void ARG_ERROR(String msg)
protected void ERROR_plus()
protected void T_ERROR(String msg)
Model.ExcWrongType
protected void updateOptTokens()
nextName
or nextAbbrev
.
Advance the input (as realized by matcher
and set optTokenValid flag.
Is only called (by getOptToken()
or skipToOption()
)
when match is known to succeed,protected void getOptToken()
nextName
or nextAbbrev
,
if this has not been done already.
Result is reflected in optTokenValid
, which is
cleared in parseInit(String, boolean)
.
Called only by main parsing loop, and by look-ahead for "cannot re-enter rep group"
criterion.protected void skipToOption()
Model.ExcFinish
- if no option token can be found.protected void lookForArgToken()
getNextArgToken()
,
and as look-ahead by canReenterRepetitionGroup()
.
The resulting variable nextArgToken
is re-set after successful decoding
in "parseprotected boolean canReenterRepetitionGroup()
protected void getNextArgToken()
public void parseOneString(String s, MessageReceiver mr)
public void parse(String[] args, MessageReceiver<SimpleMessage<?>> mr)
public void main(String[])
from some exec
system call.public String getInputString()
public String getMissingParams()
protected abstract String _getMissingParams()
protected void parseInit(String opt, boolean hasIt)
opt
- Name of option (both names, for error messages only)hasIt
- if this option has already occured in this parsing processprotected void ERROR_UNKNOWN_NAME()
protected void ERROR_UNKNOWN_ABBREV()
protected int parseInt()
protected int parseInt_16or10()
protected double parseFloat()
protected Rational parseRational()
protected boolean parseBool_X()
boolresult
.protected boolean parseBool_optional()
protected boolean parseBool()
protected String parseString()
protected String parseOneUri()
@Deprecated protected char parseChar()
protected <E extends Enum<E>> EnumSet<E> parseEnumSet(Class<E> enumclass)
public abstract String serialize()
protected static String serialize(int value)
protected static String serialize(double value)
protected static String serialize(char value)
protected String serialize(String value)
shellAdapter
is considered.protected static String serialize(boolean value)
see also the complete user documentation .