-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Range locations contains the left and right poistions in the source code where something is found.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |