- All Known Implementing Classes:
ExpressionParser
,ObjectParser.SourceParser
null
.
In one use case, the caller will maintain a list of parsers
and call appliesTo(String)
to determine
if a parser in the list should be used. If so, the caller
will then call matches(String)
to check for
syntax errors and then call parse(String)
to obtain the value. parse(String)
may
throw an exception of the string cannot be parsed (for example,
when the return value is an Integer
whose
value is below Integer.MIN_VALUE
or above
Integer.MAX_VALUE
).
This interface was created to support the class
JSUtilities.YAML
and is public because it may have other
uses.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Exception class for ObjectParser errors.static class
Object to encapsulate ESP source code.static class
Object parser that tags a string as being one that is likely to be an ESP expression or statement. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectParser<? super Boolean>
A parser for booleans.static final ObjectParser<? super Double>
A parser for double-precision numbers.static final ObjectParser<? super Integer>
A parser for integers.static final ObjectParser<? super Number>
A parser for integers or longs.static final ObjectParser<? super Long>
A parser for long integers.static final ObjectParser<Object>
A parser for 'null'.static final ObjectParser<? super Number>
A parser for numbers.static final ObjectParser<? super String>
A parser for strings. -
Method Summary
-
Field Details
-
STRING
A parser for strings. This merely returns the string. -
NULL
A parser for 'null'. The allowed value is just 'null', and the parsed value is null. -
BOOLEAN
A parser for booleans. The allowable values aretrue
andfalse
, and are case sensitive. -
LONG
A parser for long integers. -
INTEGER
A parser for integers. -
INTLONG
A parser for integers or longs. An Integer will be returned unless the value cannot be represented as an Integer, in which case a Long will be returned. -
DOUBLE
A parser for double-precision numbers. -
NUMBER
A parser for numbers. The number that theparse(String)
method returns will be a subclass ofNumber
: either anInteger
, aLong
, or aDouble
, whichever is the most specific class that will represent the number provided.
-
-
Method Details
-
appliesTo
Determine this parser applies to a given string.The default implementation simply calls
matches(String)
and returns the results of calling that method. This method should be overridden when less restrictive criteria can be used. For example, a parser that provides aColor
might accept strings that start with 'rgb(', 'rgba(', etc. Then a syntax error can be reported ifmatches(String)
returns false.- Parameters:
s
- a string to parse- Returns:
- true if this string should be used with this parser; false otherwise
-
matches
Determine if a string is syntactically valid.- Parameters:
s
- the string- Returns:
- true if the test succeeds; false if it fails
-
parse
Parse a string and return the corresponding object.- Parameters:
s
- the string- Returns:
- the corresponding object
- Throws:
ObjectParser.Exception
- if the string could not be successfully parsed or the object could not be created
-