diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-22 17:10:50 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-22 17:10:50 -0400 |
| commit | 9d06ef82f53e156334ba86fbfedbdf02eb93552f (patch) | |
| tree | c4d4d9c13a4c75580aa21974ebc80df26dd8cae3 /RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java | |
| parent | 3cd931c1317ebe49cf109673640e0b2d916f884d (diff) | |
Reimplement more old features
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java')
| -rw-r--r-- | RGens/src/main/java/bjc/rgens/newparser/RGrammarParser.java | 37 |
1 files changed, 37 insertions, 0 deletions
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 { |
