Genivia / RE-flex

A high-performance C++ regex library and lexical analyzer generator with Unicode support. Extends Flex++ with Unicode support, indent/dedent anchors, lazy quantifiers, functions for lex and syntax error reporting and more. Seamlessly integrates with Bison and other parsers.
https://www.genivia.com/doc/reflex/html
BSD 3-Clause "New" or "Revised" License
504 stars 85 forks source link

Fix incorrect location tracking when using bison-complete and bison-locations #160

Closed BridgeTheMasterBuilder closed 1 year ago

BridgeTheMasterBuilder commented 1 year ago

The following information comes straight from the Bison documentation:

10.1.5.2 C++ location

...

Method on location: void initialize (filename_type* file = nullptr, counter_type line = 1, counter_type col = 1)

    Reset the location to an empty range at the given values. 

Instance Variable of location: position begin
Instance Variable of location: position end

    The first, inclusive, position of the range, and the first beyond. 

In other words, the indexing of column numbers is not zero-based and the location type represents an exclusive range. That means that using the reflex's match range directly via matcher().columno() and matcher().columno_end() gives a location the starting position of which is off by one column and also one column too short.

genivia-inc commented 1 year ago

That is good to know. It was an oversight.