melt-umn / copper

An integrated context-aware scanner and parser generator
http://melt.cs.umn.edu/copper
GNU Lesser General Public License v3.0
17 stars 4 forks source link

index and endIndex in ableC #20

Closed remexre closed 6 years ago

remexre commented 6 years ago

I'm trying to get byte indices within a C file after parsing with ableC, using the Message.index and Message.endIndex attributes; however, it appears that they are relative to the preprocessed source, not the file's source. The line and column numbers are updated in edu/umn/cs/melt/ableC/concretesyntax/cppTags/CPPTags.sv, in an action block. Is it possible to update index and endIndex in the same way, or is that not possible/would cause breakage?

@ericvanwyk is sitting here and he doesn't know either

schwerdf commented 6 years ago

Virtual locations in Copper (which were put in specifically to support this use case) include only line and column, so the character index you are using is indeed coming from the "real" location in the preprocessed file.

If I recall correctly, this is unavoidable when using location metadata from the C preprocessor, which includes only the filename and line number, not the byte or character index. (Edit: If it is possible to get the necessary information from the C preprocessor, it would be fairly simple to add a character index to the virtual location object to support it.)

remexre commented 6 years ago

Closing this, since it's not possible. (cpp only gives a line number)