Parser class abstract
A base interface for all configuration parsers in Jetleaf.
Parsers are responsible for converting raw configuration sources
(strings, assets, or files) into a normalized Map<String, dynamic>
representation.
This abstraction allows Jetleaf to support multiple configuration
formats (JSON, YAML, XML, properties files, etc.) while providing
a unified API for accessing configuration values.
Core responsibilities:
- Parse raw string sources with parse.
- Parse from
Asset
s with parseAsset. - Parse into generic objects with parseAs.
- Optionally parse directly from files with parseFile.
Example implementation (JSON parser):
class JsonParser extends Parser {
@override
Map<String, dynamic> parse(String source) {
return jsonDecode(source) as Map<String, dynamic>;
}
@override
Map<String, dynamic> parseFile(String path) {
final fileContent = File(path).readAsStringSync();
return parse(fileContent);
}
}
void main() {
final parser = JsonParser();
final config = parser.parse('{"host": "localhost", "port": 8080}');
print(config['host']); // Output: localhost
}
- Implementers
Constructors
- Parser()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parse(
String source) → Map< String, dynamic> -
Parses the given
source
string into aMap<String, dynamic>
. -
parseAs(
Asset asset) → Object -
Parses the given
Asset
and returns it as a generic Object. -
parseAsset(
Asset asset) → Map< String, dynamic> -
Parses a Jetleaf
Asset
into aMap<String, dynamic>
. -
parseFile(
String path) → Map< String, dynamic> -
Optionally parses configuration directly from a file located at
path
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited