From 5028ad9a1faad0e363d017f18363e8062ba59871 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Thu, 15 Feb 2018 15:25:09 -0500 Subject: Formatting and things --- .../bjc/pratt/examples/lang/AssignCommand.java | 2 +- .../bjc/pratt/examples/lang/PrattParserTest.java | 42 ++++++++++++---------- .../java/bjc/pratt/examples/lang/Tokenizer.java | 4 +-- .../java/bjc/pratt/examples/lang/VarCommand.java | 2 +- .../java/bjc/pratt/examples/lang/ast/LangAST.java | 2 +- .../bjc/pratt/examples/lang/ast/LiteralAST.java | 2 +- .../lang/evaluator/EvaluatorException.java | 20 +++++++++++ 7 files changed, 49 insertions(+), 25 deletions(-) (limited to 'JPratt/src/examples') diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java index 8b96850..1800043 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java @@ -19,7 +19,7 @@ class AssignCommand extends NonBinaryCommand { throws ParserException { final Token name = operand.getHead(); - switch (name.getKey()) { + switch(name.getKey()) { case "(literal)": case "(vref)": break; diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java index 2d04440..cf5e521 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java @@ -53,7 +53,7 @@ public class PrattParserTest { * Main method. * * @param args - * Unused CLI arguments. + * Unused CLI arguments. */ public static void main(final String[] args) { /* @@ -124,8 +124,9 @@ public class PrattParserTest { System.out.print("Enter a command (blank line to exit): "); String ln = scn.nextLine(); - while (!ln.trim().equals("")) { - final Iterator> tokens = preprocessInput(ops, filtered, ln, reserved, ctx); + while(!ln.trim().equals("")) { + final Iterator> tokens = preprocessInput(ops, filtered, ln, reserved, + ctx); try { final StringTokenStream tokenStream = new StringTokenStream(tokens); @@ -135,18 +136,20 @@ public class PrattParserTest { */ tokenStream.next(); - final ITree> rawTree = parser.parseExpression(0, tokenStream, ctx, true); + final ITree> rawTree = parser.parseExpression(0, tokenStream, ctx, + true); - if (!tokenStream.headIs("(end)")) { + if(!tokenStream.headIs("(end)")) { System.out.println("\nMultiple expressions on line"); } System.out.printf("\nParsed expression:\n%s", rawTree); - final ITree tokenTree = rawTree.rebuildTree(LangAST::fromToken, LangAST::fromToken); + final ITree tokenTree = rawTree.rebuildTree(LangAST::fromToken, + LangAST::fromToken); System.out.printf("\nAST-ized expression:\n%s", tokenTree); - } catch (ParserException pex) { + } catch(ParserException pex) { pex.printStackTrace(); } @@ -166,20 +169,19 @@ public class PrattParserTest { final List splitTokens = new LinkedList<>(); - for (final String raw : rawTokens) { - if (raw.equals("")) - continue; + for(final String raw : rawTokens) { + if(raw.equals("")) continue; boolean doSplit = false; - for (final String op : ops) { - if (raw.contains(op)) { + for(final String op : ops) { + if(raw.contains(op)) { doSplit = true; break; } } - if (doSplit) { + if(doSplit) { IList splitStrangs = split.split(raw); splitStrangs.removeMatching(""); @@ -242,7 +244,8 @@ public class PrattParserTest { /* * Inline conditional. */ - final NonInitialCommand ifElse = ternary(6, 0, "else", litToken("cond"), false); + final NonInitialCommand ifElse = ternary(6, 0, "else", litToken("cond"), + false); parser.addNonInitialCommand("if", ifElse); /* @@ -316,7 +319,8 @@ public class PrattParserTest { /* * Array indexing. */ - final NonInitialCommand arrayIdx = postCircumfix(60, 0, "]", litToken("idx")); + final NonInitialCommand arrayIdx = postCircumfix(60, 0, "]", + litToken("idx")); parser.addNonInitialCommand("[", arrayIdx); /* @@ -342,15 +346,15 @@ public class PrattParserTest { /* * Array literals. */ - final InitialCommand arrayLiteral = delimited(0, ",", "]", litToken("array"), - idfun, idfun, idfun, false); + final InitialCommand arrayLiteral = delimited(0, ",", "]", + litToken("array"), idfun, idfun, idfun, false); parser.addInitialCommand("[", arrayLiteral); /* * JSON literals. */ - final InitialCommand jsonLiteral = delimited(0, ",", "}", litToken("json"), idfun, - idfun, idfun, false); + final InitialCommand jsonLiteral = delimited(0, ",", "}", litToken("json"), + idfun, idfun, idfun, false); parser.addInitialCommand("{", jsonLiteral); /* diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java index f84dd7d..052c521 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java @@ -23,9 +23,9 @@ final class Tokenizer implements Function> { @Override public Token apply(final String strang) { - if (ops.contains(strang) || reserved.contains(strang)) + if(ops.contains(strang) || reserved.contains(strang)) return litToken(strang); - else if (strang.matches("(?:[\\u00B2\\u00B3\\u00B9\\u2070]|[\\u2074-\\u2079])+")) { + else if(strang.matches("(?:[\\u00B2\\u00B3\\u00B9\\u2070]|[\\u2074-\\u2079])+")) { /* * This regular expression matches series of unicode * super - scripts 1 - 9. diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java index 0ca72cf..4b212b8 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java @@ -15,7 +15,7 @@ class VarCommand extends AbstractInitialCommand { final ParserContext ctx) throws ParserException { final Token name = ctx.tokens.current(); - switch (name.getKey()) { + switch(name.getKey()) { case "(literal)": case "(vref)": ctx.tokens.next(); diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java index 753276a..4fa84b8 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java @@ -11,7 +11,7 @@ public interface LangAST { static LangAST fromToken(Token token) throws EvaluatorException { String key = token.getKey(); - switch (key) { + switch(key) { case "(literal)": return LiteralAST.fromToken(token); default: diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java index cf12fe9..d9a7ad2 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java @@ -7,7 +7,7 @@ public interface LiteralAST extends LangAST { static LiteralAST fromToken(Token tok) { return null; } - + @Override default TopDownTransformResult getEvaluationStrategy() { return TopDownTransformResult.TRANSFORM; diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java index 56fc719..ae53d4f 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java @@ -1,12 +1,32 @@ package bjc.pratt.examples.lang.evaluator; +/** + * Exception thrown when evaluation goes wrong. + * + * @author EVE + * + */ public class EvaluatorException extends RuntimeException { private static final long serialVersionUID = -8610585421069729811L; + /** + * Create a new evaluator exception with a message and a cause. + * + * @param message + * The message for the exception. + * @param cause + * The cause of the exception. + */ public EvaluatorException(String message, Throwable cause) { super(message, cause); } + /** + * Create a new evaluator exception with a message. + * + * @param message + * The message for the exception. + */ public EvaluatorException(String message) { super(message); } -- cgit v1.2.3