Search code examples
locationrascal

Rascal MPL how to extract additional loc segments?


According to Location, the loc format is | Uri | ( O, L, < BL, BC > , < EL,EC > ).

Say we have loc l = |java+compilationUnit:///test/src/main.java|(0,123,<1,0>,<7,1>);

How to retrieve e.g. only < BL, BC >?

As an aside, how to convert loc values to a string? toString(l) does not work.


Solution

  • Towards the bottom of Location, below the list items marked with **, there it is:

    l.offset, l.length, l.begin, l.end. Some useful examples:

    • l.uri will return str: "java+compilationUnit:///test/src/main.java"
    • l.path will return str: "/test/src/main.java"
    • l.begin will return tuple[int line,int column]: <1,0>