From 8d4129edece776a27ea55bd547b7d49413f55346 Mon Sep 17 00:00:00 2001 From: romildo Date: Sat, 8 Oct 2016 14:59:20 -0300 Subject: [PATCH] Add range locations Range locations contains the left and right poistions in the source code where something is found. --- src/main/java/parse/Loc.java | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/parse/Loc.java diff --git a/src/main/java/parse/Loc.java b/src/main/java/parse/Loc.java new file mode 100644 index 0000000..5100171 --- /dev/null +++ b/src/main/java/parse/Loc.java @@ -0,0 +1,46 @@ +package parse; + +import java_cup.runtime.ComplexSymbolFactory.Location; + +public class Loc { + + public final Location left; + public final Location right; + + private Loc(Location left, Location right) { + this.left = left; + this.right = right; + } + + public static Loc loc() { + return loc(new Location(-1, -1)); + } + + public static Loc loc(Location left) { + return loc(left, left); + } + + public static Loc loc(Location left, Location right) { + return new Loc(left, right); + } + + @Override + public String toString() { + if (left.getUnit().equals("unknown") && right.getUnit().equals("unknown")) + return String.format("%d/%d-%d/%d", + left.getLine(), left.getColumn(), + right.getLine(), right.getColumn()); + else if (left.getUnit().equals(right.getUnit())) + return String.format("%s:%d/%d-%d/%d", + left.getUnit(), + left.getLine(), left.getColumn(), + right.getLine(), right.getColumn()); + else + return String.format("%s:%d/%d-%s:%d/%d", + left.getUnit(), + left.getLine(), left.getColumn(), + right.getUnit(), + right.getLine(), right.getColumn()); + } + +}