From 275a627719fc2231b16caea41130ff09f0f2b6a1 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 8 Apr 2016 13:28:09 -0400 Subject: Switch functional data to use interfaces --- .../utils/parserutils/RuleBasedConfigReader.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java index b6162e5..999503c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java @@ -8,6 +8,7 @@ import java.util.Scanner; import java.util.function.BiConsumer; import java.util.function.Consumer; +import bjc.utils.data.IPair; import bjc.utils.data.Pair; import bjc.utils.exceptions.UnknownPragmaException; import bjc.utils.funcdata.FunctionalStringTokenizer; @@ -20,9 +21,10 @@ import bjc.utils.funcdata.FunctionalStringTokenizer; * * @param * The type of the state object to use + * */ public class RuleBasedConfigReader { - private BiConsumer> startRule; + private BiConsumer> startRule; private BiConsumer continueRule; private Consumer endRule; @@ -39,7 +41,7 @@ public class RuleBasedConfigReader { * The action to fire when ending a rule */ public RuleBasedConfigReader( - BiConsumer> startRule, + BiConsumer> startRule, BiConsumer continueRule, Consumer endRule) { this.startRule = startRule; @@ -90,20 +92,26 @@ public class RuleBasedConfigReader { state = initialState; boolean ruleOpen = false; + while (inputSource.hasNextLine()) { String line = inputSource.nextLine(); - if (line.equals("")) { + if (line.startsWith("#") || line.startsWith("//")) { + // It's a comment + continue; + } else if (line.equals("")) { if (ruleOpen == false) { // Ignore blank line without an open rule - } - - if (endRule == null) { - // Nothing happens on rule end } else { - endRule.accept(state); - } + if (endRule == null) { + // Nothing happens on rule end + ruleOpen = false; + } else { + endRule.accept(state); + } + ruleOpen = false; + } continue; } else if (line.startsWith("\t")) { if (ruleOpen == false) { @@ -125,9 +133,7 @@ public class RuleBasedConfigReader { String nextToken = tokenizer.nextToken(); - if (nextToken.equals("#") || nextToken.equals("//")) { - // Do nothing, this is a comment - } else if (nextToken.equals("pragma")) { + if (nextToken.equals("pragma")) { String token = tokenizer.nextToken(); pragmas.getOrDefault(token, (tokenzer, stat) -> { @@ -181,7 +187,7 @@ public class RuleBasedConfigReader { * The action to execute on starting of a rule */ public void setStartRule( - BiConsumer> startRule) { + BiConsumer> startRule) { if (startRule == null) { throw new NullPointerException( "Action on rule start must be non-null"); -- cgit v1.2.3