satyr  0.28
Data Structures | Functions
location.h File Reference

Parser location in input file. More...

#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  sr_location
 A location of a parser in the input stream. More...
 

Functions

void sr_location_init (struct sr_location *location)
 
int sr_location_cmp (struct sr_location *location1, struct sr_location *location2, bool compare_messages)
 
char * sr_location_to_string (struct sr_location *location)
 
void sr_location_add (struct sr_location *location, int add_line, int add_column)
 
void sr_location_add_ext (int *line, int *column, int add_line, int add_column)
 
void sr_location_eat_char (struct sr_location *location, char c)
 
void sr_location_eat_char_ext (int *line, int *column, char c)
 

Detailed Description

Parser location in input file.

Definition in file location.h.

Function Documentation

◆ sr_location_add()

void sr_location_add ( struct sr_location location,
int  add_line,
int  add_column 
)

Adds a line and a column to specific location.

Note
If the line is not 1 (meaning the first line), the column in the location structure is overwritten by the provided add_column value. Otherwise the add_column value is added to the column member of the location structure.
Parameters
locationThe structure to be modified. It must be a valid pointer.
add_lineStarts from 1. It means that if add_line is 1, the line member of the location structure is not changed.
add_columnStarts from 0.

◆ sr_location_add_ext()

void sr_location_add_ext ( int *  line,
int *  column,
int  add_line,
int  add_column 
)

Adds a line column pair to another line column pair.

Note
If the add_line is not 1 (meaning the frist line), the column is overwritten by the provided add_column value. Otherwise the add_column value is added to the column.
Parameters
add_lineStarts from 1. It means that if add_line is 1, the line is not changed.
add_columnStarts from 0.

◆ sr_location_cmp()

int sr_location_cmp ( struct sr_location location1,
struct sr_location location2,
bool  compare_messages 
)

Compare two locations.

Parameters
location1It must be non-NULL pointer. It's not modified by calling this function.
location2It must be non-NULL pointer. It's not modified by calling this function.
compare_messagesIndicates whether to compare messages in the locations as well.
Returns
Returns 0 if the locations are same. Returns negative number if location1 is found to be 'less' than location2. Returns positive number if location1 is found to be 'greater' than location2.

'Less' and 'greater' take lines into account first. If a location1 line is lower than location2 line, location1 is considered 'less' than location2. If the lines are the same, columns are compared. When compare_messages is true and lines and columns are equal, the locations' messages are compared according to the lexicographical order.

◆ sr_location_eat_char()

void sr_location_eat_char ( struct sr_location location,
char  c 
)

Updates the line and column of the location by moving "after" the char c. If c is a newline character, the line number is increased and the column is set to 0. Otherwise the column is increased by 1.

◆ sr_location_eat_char_ext()

void sr_location_eat_char_ext ( int *  line,
int *  column,
char  c 
)

Updates the line and the column by moving "after" the char c. If c is a newline character, the line number is increased and the column is set to 0. Otherwise the column is increased.

Parameters
lineMust be a valid pointer.
columnMust be a valid pointer.

◆ sr_location_init()

void sr_location_init ( struct sr_location location)

Initializes all members of the location struct to their default values. No memory is allocated or released by this function.

◆ sr_location_to_string()

char* sr_location_to_string ( struct sr_location location)

Creates a string representation of location. User must delete the returned string using free().