Skip to content

Commit 3fd3972

Browse files
committed
jparsec: migrate from jparsec.functors to java 8 API
1 parent 6e51145 commit 3fd3972

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+288
-239
lines changed

org.coreasm.engine/src/org/coreasm/engine/kernel/ExpressionParserFactory.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import java.util.HashMap;
1414
import java.util.Map;
1515
import java.util.Set;
16+
import java.util.function.BinaryOperator;
17+
import java.util.function.UnaryOperator;
1618

1719
import org.jparsec.OperatorTable;
1820
import org.jparsec.Parser;
19-
import org.jparsec.functors.Binary;
20-
import org.jparsec.functors.Unary;
2121
import org.coreasm.engine.ControlAPI;
2222
import org.coreasm.engine.EngineError;
2323
import org.coreasm.engine.interpreter.ASTNode;
@@ -303,7 +303,7 @@ private void addOperator(Map<String, Integer> oprs, OperatorRule oprRule) {
303303
}
304304

305305
/* Special unary map class */
306-
public static class UnaryMap implements Unary<Node> {
306+
public static class UnaryMap implements UnaryOperator<Node> {
307307

308308
//private String pluginNames;
309309
private String opr;
@@ -329,7 +329,8 @@ public UnaryMap(String opr, String pluginNames, OpType type, Object[] nodes) {
329329
/**
330330
* Creates a tree for this operator with an {@link ASTNode} as its root.
331331
*/
332-
public Node map(Node child) {
332+
@Override
333+
public Node apply(Node child) {
333334
Node node = null;
334335
if (type == OpType.POSTFIX) {
335336
node = new ASTNode(
@@ -364,14 +365,15 @@ public UnaryParseMap(String opr, String pluginName, OpType type) {
364365
this.type = type;
365366
}
366367

367-
public UnaryMap map(Object[] v) {
368+
@Override
369+
public UnaryMap apply(Object[] v) {
368370
return new UnaryMap(opr, pluginName, type, v);
369371
}
370372

371373
}
372374

373375
/* Special binary map class */
374-
public static class BinaryMap implements Binary<Node> {
376+
public static class BinaryMap implements BinaryOperator<Node> {
375377

376378
//private String pluginNames;
377379
private String opr;
@@ -397,7 +399,8 @@ public BinaryMap(String opr, String pluginNames, OpType type, Object[] cnodes) {
397399
/**
398400
* Creates a tree for this operator with an {@link ASTNode} as its root.
399401
*/
400-
public Node map(Node o1, Node o2) {
402+
@Override
403+
public Node apply(Node o1, Node o2) {
401404
Node node = new ASTNode(
402405
null, ASTNode.BINARY_OPERATOR_CLASS, "", ((Node)cnodes[1]).getToken(), o1.getScannerInfo());
403406
node.addChild(o1);
@@ -423,14 +426,15 @@ public BinaryParseMap(String opr, String pluginName, OpType type) {
423426
this.type = type;
424427
}
425428

426-
public BinaryMap map(Object[] v) {
429+
@Override
430+
public BinaryMap apply(Object[] v) {
427431
return new BinaryMap(opr, pluginName, type, v);
428432
}
429433

430434
}
431435

432436
/* Special index map class */
433-
public static class IndexMap implements Unary<Node> {
437+
public static class IndexMap implements UnaryOperator<Node> {
434438

435439
//private String pluginNames;
436440
private String opr1;
@@ -458,7 +462,8 @@ public IndexMap(String opr1, String opr2, String pluginNames, OpType type, Objec
458462
/**
459463
* Creates a tree for this operator with an {@link ASTNode} as its root.
460464
*/
461-
public Node map(Node child) {
465+
@Override
466+
public Node apply(Node child) {
462467
Node node = null;
463468
node = new ASTNode(
464469
null, ASTNode.INDEX_OPERATOR_CLASS, "", opr1 + OperatorRule.OPERATOR_DELIMITER + opr2, child.getScannerInfo());
@@ -484,7 +489,8 @@ public IndexParseMap(String opr1, String opr2, String pluginName, OpType type) {
484489
this.type = type;
485490
}
486491

487-
public IndexMap map(Object[] v) {
492+
@Override
493+
public IndexMap apply(Object[] v) {
488494
return new IndexMap(opr1, opr2, pluginName, type, v);
489495
}
490496

org.coreasm.engine/src/org/coreasm/engine/kernel/ImportRuleParseMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public ImportRuleParseMap() {
3131
super(Kernel.PLUGIN_NAME);
3232
}
3333

34-
public Node map(Object[] v) {
34+
@Override
35+
public Node apply(Object[] v) {
3536
Node node = new ASTNode(
3637
null,
3738
ASTNode.RULE_CLASS,

org.coreasm.engine/src/org/coreasm/engine/kernel/Kernel.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ public Map<String, GrammarRule> getParsers() {
314314
parserTools.getKeywParser("use", this.getName()),
315315
idParser,
316316
new ParseMap2(getName()) {
317-
318-
public Node map(Node a, Node b) {
317+
318+
@Override
319+
public Node apply(Node a, Node b) {
319320
Node node = new ASTNode(
320321
pluginName,
321322
ASTNode.DECLARATION_CLASS,
@@ -337,8 +338,9 @@ public Node map(Node a, Node b) {
337338
parserTools.getKeywParser("init", this.getName()),
338339
idParser,
339340
new ParseMap2(getName()) {
340-
341-
public Node map(Node a, Node b) {
341+
342+
@Override
343+
public Node apply(Node a, Node b) {
342344
Node node = new ASTNode(
343345
null,
344346
null,
@@ -448,7 +450,8 @@ private void createRuleParser(Map<String, GrammarRule> parsers) {
448450
// Rule : 'skip'
449451
Parser<Node> skipRuleParser = parserTools.getKeywParser("skip", PLUGIN_NAME).map(
450452
new ParseMap<Node, Node>(PLUGIN_NAME) {
451-
public Node map(Node v) {
453+
@Override
454+
public Node apply(Node v) {
452455
return new SkipRuleNode(v.getScannerInfo());
453456
}});
454457
parsers.put("SkipRule", new GrammarRule("SkipRule", "'skip'", skipRuleParser, PLUGIN_NAME));
@@ -471,7 +474,8 @@ public Node map(Node v) {
471474
Parser<Node> macroCallRule = Parsers.array(refFuncRuleTermParser.lazy()).map(
472475
new ParseMap<Object[], Node>(PLUGIN_NAME) {
473476

474-
public Node map(Object[] vals) {
477+
@Override
478+
public Node apply(Object[] vals) {
475479
Node node = new MacroCallRuleNode(((Node)vals[0]).getScannerInfo());
476480
node.addChild("alpha", (Node)vals[0]);
477481
return node;
@@ -613,7 +617,8 @@ private Parser<Node> createExpressionParser() {
613617
parserTools.getKeywParser("undef", PLUGIN_NAME),
614618
parserTools.getKeywParser("self", PLUGIN_NAME)).map(
615619
new ParseMap<Node, Node>(PLUGIN_NAME) {
616-
public Node map(Node v) {
620+
@Override
621+
public Node apply(Node v) {
617622
Node node = new ASTNode(
618623
pluginName,
619624
ASTNode.EXPRESSION_CLASS,
@@ -633,7 +638,8 @@ public Node map(Node v) {
633638
parserTools.getKeywParser("true", PLUGIN_NAME),
634639
parserTools.getKeywParser("false", PLUGIN_NAME)).map(
635640
new ParseMap<Node, Node>(PLUGIN_NAME) {
636-
public Node map(Node v) {
641+
@Override
642+
public Node apply(Node v) {
637643
Node node = new ASTNode(
638644
pluginName,
639645
ASTNode.EXPRESSION_CLASS,
@@ -659,7 +665,8 @@ public Node map(Node v) {
659665
parserTools.getOprParser(")")
660666
).map(new ParseMap<Object[], Node>(PLUGIN_NAME){
661667

662-
public Node map(Object[] v) {
668+
@Override
669+
public Node apply(Object[] v) {
663670
Node node = new EnclosedTermNode(((Node)v[0]).getScannerInfo());
664671
for (Object o:v) node.addChild((Node)o);
665672
return node;
@@ -739,7 +746,8 @@ private void createBasicTerm(Parser<Node> functionRuleTermParser) {
739746

740747
new ParseMap2(PLUGIN_NAME) {
741748

742-
public Node map(Node a, Node b) {
749+
@Override
750+
public Node apply(Node a, Node b) {
743751
Node node = new ASTNode(
744752
pluginName,
745753
ASTNode.EXPRESSION_CLASS,
@@ -764,7 +772,8 @@ public Node map(Node a, Node b) {
764772
idParser,
765773
new ParseMap2(PLUGIN_NAME) {
766774

767-
public Node map(Node a, Node d) {
775+
@Override
776+
public Node apply(Node a, Node d) {
768777
Node node = new RuleOrFuncElementNode(a.getScannerInfo());
769778
node.addChild(a);
770779
node.addChild("alpha", d);

org.coreasm.engine/src/org/coreasm/engine/kernel/TupleTermParseMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public class TupleTermParseMap extends ParseMap<Object[], Node> {
2828
public TupleTermParseMap() {
2929
super(Kernel.PLUGIN_NAME);
3030
}
31-
32-
public Node map(Object[] v) {
31+
32+
@Override
33+
public Node apply(Object[] v) {
3334
Node node = new ASTNode(
3435
null,
3536
"",

org.coreasm.engine/src/org/coreasm/engine/kernel/UpdateRuleParseMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public UpdateRuleParseMap() {
2828
super(Kernel.PLUGIN_NAME);
2929
}
3030

31-
public Node map(Object[] v) {
31+
@Override
32+
public Node apply(Object[] v) {
3233
Node node = new UpdateRuleNode(((Node)v[0]).getScannerInfo());
3334

3435
for (int i=0; i < v.length; i++) {

org.coreasm.engine/src/org/coreasm/engine/parser/ParseMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
import org.coreasm.engine.plugin.Plugin;
1717

18-
import org.jparsec.functors.Map;
18+
import java.util.function.Function;
1919

2020
/**
21-
* Specialized version of {@link Map} that gets a plug-in name as well.
21+
* Specialized version that gets a plug-in name as well.
2222
*
2323
* @author Roozbeh Farahbod
2424
*
2525
*/
2626

27-
public abstract class ParseMap<To, From> implements Map<To, From> {
27+
public abstract class ParseMap<To, From> implements Function<To, From> {
2828

2929
public final String pluginName;
3030

org.coreasm.engine/src/org/coreasm/engine/parser/ParseMap2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import org.coreasm.engine.interpreter.Node;
44
import org.coreasm.engine.plugin.Plugin;
55

6-
import org.jparsec.functors.Map2;
6+
import java.util.function.BiFunction;
77

88
/**
9-
* Specialized version of {@link Map3} that gets a plug-in name as well.
9+
* Specialized version that gets a plug-in name as well.
1010
*
1111
* @author Roozbeh Farahbod
1212
*
1313
*/
1414

15-
public abstract class ParseMap2 implements Map2<Node, Node, Node> {
15+
public abstract class ParseMap2 implements BiFunction<Node, Node, Node> {
1616

1717
public final String pluginName;
1818

0 commit comments

Comments
 (0)