From 9d06ef82f53e156334ba86fbfedbdf02eb93552f Mon Sep 17 00:00:00 2001 From: bjculkin Date: Wed, 22 Mar 2017 17:10:50 -0400 Subject: Reimplement more old features --- .../java/bjc/rgens/newparser/RGrammarParser.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java') diff --git a/RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java b/RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java index dac397e..80e1c2f 100644 --- a/RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java +++ b/RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java @@ -57,6 +57,42 @@ public class RGrammarParser { build.addExport(export); } }); + + pragmas.put("suffix-with", (body, build, level) -> { + String[] parts = body.trim().split(" "); + + if(parts.length != 2) { + throw new GrammarException("Suffix-with pragma takes two arguments," + + " the name of the rule to suffix, then what to suffix it with"); + } else { + String name = parts[0]; + String suffix = parts[1]; + + if(name.equals("")) { + throw new GrammarException("The empty string is not a valid rule name"); + } + + build.suffixWith(name, suffix); + } + }); + + pragmas.put("prefix-with", (body, build, level) -> { + String[] parts = body.trim().split(" "); + + if(parts.length != 2) { + throw new GrammarException("Prefix-with pragma takes two arguments," + + " the name of the rule to prefix, then what to prefix it with"); + } else { + String name = parts[0]; + String prefix = parts[1]; + + if(name.equals("")) { + throw new GrammarException("The empty string is not a valid rule name"); + } + + build.prefixWith(name, prefix); + } + }); } /** @@ -294,6 +330,7 @@ public class RGrammarParser { /* * Handle a where block (a block with local rules). */ + @SuppressWarnings("unused") private void handleWhereBlock(String block, RGrammarBuilder build, int level) throws GrammarException { try(BlockReader whereReader = new BlockReader("", new StringReader(block))) { try { -- cgit v1.2.3