From 42a897dae1bfa58ab665f5012c2ac160316bcb75 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 24 Mar 2017 18:28:34 -0400 Subject: Update Pratt Parser --- .../pratt/commands/InitialInterleaveCommand.java | 29 +++++++++++++++++++++ .../pratt/commands/InterleaveSpecifier.java | 30 ++++++++++++++++++++++ .../parserutils/splitter/TwoLevelSplitter.java | 14 ++++++++++ 3 files changed, 73 insertions(+) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java create mode 100644 BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java (limited to 'BJC-Utils2/src/main/java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java new file mode 100644 index 0000000..554cf30 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java @@ -0,0 +1,29 @@ +package bjc.utils.parserutils.pratt.commands; + +import bjc.utils.data.ITree; +import bjc.utils.parserutils.ParserException; +import bjc.utils.parserutils.pratt.ParserContext; +import bjc.utils.parserutils.pratt.Token; + +/** + * Represents a configurable initial command. + * + * @author EVE + * + * @param + * The token key type. + * + * @param + * The token value type. + * + * @param + * The parser state type. + */ +public class InitialInterleaveCommand extends AbstractInitialCommand { + @Override + protected ITree> intNullDenotation(Token operator, ParserContext ctx) + throws ParserException { + return null; + } + +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java new file mode 100644 index 0000000..fa2c592 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java @@ -0,0 +1,30 @@ +package bjc.utils.parserutils.pratt.commands; + +/** + * The specifier for what to do for each element of a command. + * + * @author EVE + * + */ +public class InterleaveSpecifier { + /** + * The type of this specifier. + * + * @author EVE + * + */ + public static enum Type { + /** + * Parse an expression with the given priority. + */ + EXPRESSION, + /** + * Parse a statement with the given priority. + */ + STATEMENT, + /** + * Expect a token of a certain type to be present. + */ + EXPECT, LITERAL; + } +} \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/splitter/TwoLevelSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/splitter/TwoLevelSplitter.java index 38f303d..d65b06a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/splitter/TwoLevelSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/splitter/TwoLevelSplitter.java @@ -99,6 +99,20 @@ public class TwoLevelSplitter implements TokenSplitter { } } + /** + * Exclude strings matching a regex from both splits. + * + * @param exclusions + * The regexes to exclude matches for. + */ + public void exclude(String... exclusions) { + for(String exclusion : exclusions) { + high.addNonMatcher(exclusion); + + low.addNonMatcher(exclusion); + } + } + /** * Ready the splitter for use. */ -- cgit v1.2.3