Next: , Previous: C++ Semantic Values, Up: C++ Parsers


10.1.3 C++ Location Values

When the directive %locations is used, the C++ parser supports location tracking, see Locations Overview. Two auxiliary classes define a position, a single point in a file, and a location, a range composed of a pair of positions (possibly spanning several files).

— Method on position: std::string* file

The name of the file. It will always be handled as a pointer, the parser will never duplicate nor deallocate it. As an experimental feature you may change it to ‘type*’ using ‘%define filename_type "type"’.

— Method on position: unsigned int line

The line, starting at 1.

— Method on position: unsigned int lines (int height = 1)

Advance by height lines, resetting the column number.

— Method on position: unsigned int column

The column, starting at 0.

— Method on position: unsigned int columns (int width = 1)

Advance by width columns, without changing the line number.

— Method on position: position& operator+= (position& pos, int width)
— Method on position: position operator+ (const position& pos, int width)
— Method on position: position& operator-= (const position& pos, int width)
— Method on position: position operator- (position& pos, int width)

Various forms of syntactic sugar for columns.

— Method on position: position operator<< (std::ostream o, const position& p)

Report p on o like this: ‘file:line.column’, or ‘line.column’ if file is null.

— Method on location: position begin
— Method on location: position end

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

— Method on location: unsigned int columns (int width = 1)
— Method on location: unsigned int lines (int height = 1)

Advance the end position.

— Method on location: location operator+ (const location& begin, const location& end)
— Method on location: location operator+ (const location& begin, int width)
— Method on location: location operator+= (const location& loc, int width)

Various forms of syntactic sugar.

— Method on location: void step ()

Move begin onto end.