diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 19:59:48 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 19:59:48 -0400 |
| commit | f4c758dc79b704865ac5ae96c6e48aac6ab1d097 (patch) | |
| tree | 1e3b3022626a2468969a9daf607f65e6c885a15d /BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java | |
| parent | 903249252ac188be1f90038e3f1a70b15314b6a7 (diff) | |
Added parser for component descriptions
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java new file mode 100644 index 0000000..bf0f0bd --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -0,0 +1,54 @@ +package bjc.utils.components; + +import java.io.InputStream; + +import bjc.utils.funcutils.ListUtils; +import bjc.utils.parserutils.RuleBasedConfigReader; + +/** + * Read a component description from a file + * + * @author ben + * + */ +public class ComponentDescriptionFileParser { + private static RuleBasedConfigReader<ComponentDescriptionState> reader; + + static { + // This reader works entirely off of pragmas, so no need to handle + // rules + reader = new RuleBasedConfigReader<>((fst, par) -> { + }, (fst, stat) -> { + }, (stat) -> { + }); + + reader.addPragma("name", (fst, stat) -> { + stat.setName(ListUtils.collapseTokens(fst.toList((s) -> s))); + }); + + reader.addPragma("author", (fst, stat) -> { + stat.setAuthor(ListUtils.collapseTokens(fst.toList((s) -> s))); + }); + + reader.addPragma("description", (fst, stat) -> { + stat.setDescription( + ListUtils.collapseTokens(fst.toList((s) -> s))); + }); + + reader.addPragma("version", (fst, stat) -> { + stat.setVersion(Integer.parseInt(fst.nextToken())); + }); + } + + /** + * Parse a component description from a stream + * + * @param is + * The stream to parse from + * @return The description parsed from the stream + */ + public ComponentDescription fromStream(InputStream is) { + return reader.fromStream(is, new ComponentDescriptionState()) + .toDescription(); + } +} |
