parsers.h File Reference

Contains the example and model file parser. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "../types/examples.h"
#include "../types/model.h"
#include "../types/string-type.h"
#include "../app/output.h"
Include dependency graph for parsers.h:

Go to the source code of this file.

Data Structures

struct  StringVector
 Stores an array of C string. More...
 

Macros

#define PARSED_EXAMPLE   1
 Value representing an example in the example file.
 
#define PARSED_COUNTEREXAMPLE   2
 Value representing a counter-example in the example file.
 

Functions

char * getIncludeFile (char const *pathname, size_t *pos)
 Get the pathname to the config file included at the begening of an example file. More...
 
ExamplesloadExampleFile (char const *pathname, Model *model, size_t startPos)
 Loads the example file given and generate the Example object that represents its content. More...
 
unsigned int getNextExample (FILE *f)
 Get the type of the next example (example or counter-example). Stop reading at the end of the example name, on the last character. More...
 
int parseExample (FILE *fp, char **error, Example *ex, Model *m)
 Parse an example or a counterexample. More...
 
int parseExampleObject (FILE *fp, char **error, Object *o, Model *m, struct StringVector *seenObjects)
 Parse an object (only its properties. The name must already be known) More...
 
int getAttributePosition (const char *attr, Model *m)
 Returns the position at which can be found an attribute (by name) More...
 
int getRelationPosition (const char *rel, Model *m)
 Returns the position at which can be found a relation (by name) More...
 
void parseAttrValue (FILE *fp, char **error, Model *m, attrType type, Attribute *attr, unsigned int position, struct StringVector *seenObjects)
 Parse the attribute's value and populate the Attribute object accordingly. More...
 
ModelloadConfigFile (char const *pathname)
 Loads the config file given anf the generate the Model object that represents its content. More...
 
int parseConfigLine (FILE *fp, char **error, Model *out)
 Tries to parse the line as a config file attribute definition. If the line is empty, continues to read until it finds a line. More...
 
char * parseAttrName (FILE *fp, char **error)
 Tries to parse the attribute name at the current position in the file (spaces & tabs are ommited) More...
 
ModelTypeparseAttrType (FILE *fp, char **error)
 Tries to parse the attribute's value definition at the current position in the file (may read more than one line in case of trees) More...
 
IntervalparseAttrTypeInterval (FILE *fp, char **error)
 Tries to parse an interval. More...
 
EnumparseAttrTypeEnum (FILE *fp, char **error)
 Tries to parse an enumeration. More...
 
TreeparseAttrTypeTree (FILE *fp, char **error, int *index, int indent)
 Tries to parse a tree. More...
 
int isValidAttrChar (char c, unsigned int first)
 Check whether the character is allowed in an attribute name or not. More...
 
void readFileSpaces (FILE *fp, char const *set)
 Reads a file from the current position and reads while characters are in the set. Stops on the last one. More...
 
void readTil (FILE *fp, char const *set)
 Reads a file from the current position and reads until it finds a character in the set. Stops on the last character not in the set. More...
 

Detailed Description

Contains the example and model file parser.

Author
Bastien Philip (ebatsin)
Gaël Foppolo (gaelfoppolo)

Function Documentation

int getAttributePosition ( const char *  attr,
Model m 
)

Returns the position at which can be found an attribute (by name)

Parameters
attrthe attribute to search for
mThe model in which to find the order
Returns
the index of the attribute (or -1 in case the attributes is not in the model)

Here is the caller graph for this function:

char* getIncludeFile ( char const *  pathname,
size_t *  pos 
)

Get the pathname to the config file included at the begening of an example file.

Parameters
pathnameThe path to the example file
posWill contain the position of the character after the last character of the include (basically, a " ", "\t" or "\n")
Returns
If the file to include is found, the file name. NULL otherwise
Author
Bastien Philip (ebatsin)
Gaël Foppolo (gaelfoppolo)

Here is the call graph for this function:

unsigned int getNextExample ( FILE *  f)

Get the type of the next example (example or counter-example). Stop reading at the end of the example name, on the last character.

Parameters
fThe file to be read
Returns
0 in case of error, PARSED_EXAMPLE if the line is an example, PARSED_COUNTEREXAMPLE if the line is a counter-example

Here is the call graph for this function:

Here is the caller graph for this function:

int getRelationPosition ( const char *  rel,
Model m 
)

Returns the position at which can be found a relation (by name)

Parameters
relthe relation to search for
mThe model in which to find the order
Returns
the index of the attribute (or -1 in case the attributes is not in the model)

Here is the caller graph for this function:

int isValidAttrChar ( char  c,
unsigned int  first 
)

Check whether the character is allowed in an attribute name or not.

Parameters
cThe character to Check
firstwhether the character is the first to be read or not
Returns
Returns 1 if the character is valid. 0 otherwise

Here is the caller graph for this function:

Model* loadConfigFile ( char const *  pathname)

Loads the config file given anf the generate the Model object that represents its content.

Parameters
pathnameThe path tp the config file to be read
Returns
A newly created Model object

Here is the call graph for this function:

Examples* loadExampleFile ( char const *  pathname,
Model model,
size_t  startPos 
)

Loads the example file given and generate the Example object that represents its content.

Parameters
pathnameThe path to the example file to be read
modelThe Model object generated from the config file
startPosThe position at which to start parsing the file
Returns
A newly created Examples object

Here is the call graph for this function:

char* parseAttrName ( FILE *  fp,
char **  error 
)

Tries to parse the attribute name at the current position in the file (spaces & tabs are ommited)

Parameters
fpTher file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
Returns
Returns a new string that contains the attribute name or NULL in case of error

Here is the call graph for this function:

Here is the caller graph for this function:

ModelType* parseAttrType ( FILE *  fp,
char **  error 
)

Tries to parse the attribute's value definition at the current position in the file (may read more than one line in case of trees)

Parameters
fpTher file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
Returns
Returns the ModelType built from the file definition or NULL in case of error

Here is the call graph for this function:

Here is the caller graph for this function:

Enum* parseAttrTypeEnum ( FILE *  fp,
char **  error 
)

Tries to parse an enumeration.

Parameters
fpTher file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
Returns
The parsed value or NULL in case of error

Here is the call graph for this function:

Here is the caller graph for this function:

Interval* parseAttrTypeInterval ( FILE *  fp,
char **  error 
)

Tries to parse an interval.

Parameters
fpTher file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
Returns
The parsed value or NULL in case of error

Here is the call graph for this function:

Here is the caller graph for this function:

Tree* parseAttrTypeTree ( FILE *  fp,
char **  error,
int *  index,
int  indent 
)

Tries to parse a tree.

Parameters
fpTher file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
indexPointer to the counter of nodes (id)
indentNumber of tab to print
Returns
The parsed value or NULL in case of error

Here is the call graph for this function:

Here is the caller graph for this function:

void parseAttrValue ( FILE *  fp,
char **  error,
Model m,
attrType  type,
Attribute attr,
unsigned int  position,
struct StringVector seenObjects 
)

Parse the attribute's value and populate the Attribute object accordingly.

Parameters
fpThe file in which to read
errorIn case of error, contains a description of the error. NULL if no error happened. Must be an uninitialized variable or data loss may occur.
mThe model to use for the parsing
typeThe expected type of the attribute
attrA pointer to the attribute to populate
positionThe position of the attribute in the model
seenObjectsThe names of the objects that have already been seen

Here is the call graph for this function:

Here is the caller graph for this function:

int parseConfigLine ( FILE *  fp,
char **  error,
Model out 
)

Tries to parse the line as a config file attribute definition. If the line is empty, continues to read until it finds a line.

Parameters
fpThe file in which to read
errorIn case of error, contains a description of the error. NULL if no error append. Must be an uninitialized variable or data loss may happen
outA pointer to the Model object to populate
Returns
A boolean. 1 for success. 0 for failure.

Here is the call graph for this function:

Here is the caller graph for this function:

int parseExample ( FILE *  fp,
char **  error,
Example ex,
Model m 
)

Parse an example or a counterexample.

Parameters
fpThe file in which to read
errorIn case of error, contains a description of the error. NULL if no error happened. Must be an uninitialized variable or data loss may occur.
exA pointer to the example object to populate
mThe Model object generated from the config file
Returns
A boolean. 1 for success. 0 for failure.

Here is the call graph for this function:

Here is the caller graph for this function:

int parseExampleObject ( FILE *  fp,
char **  error,
Object o,
Model m,
struct StringVector seenObjects 
)

Parse an object (only its properties. The name must already be known)

Parameters
fpThe file in which to read
errorIn case of error, contains a description of the error. NULL if no error happened. Must be an uninitialized variable or data loss may occur.
oA pointer to the object Object to populate
mThe Model object generated from the config file
seenObjectsThe names of the objects that have already been seen
Returns
A boolean. 1 for success. 0 for failure

Here is the call graph for this function:

Here is the caller graph for this function:

void readFileSpaces ( FILE *  fp,
char const *  set 
)

Reads a file from the current position and reads while characters are in the set. Stops on the last one.

Parameters
fpThe file to be read
setA nul terminated array of char that contains the set of characters

Here is the caller graph for this function:

void readTil ( FILE *  fp,
char const *  set 
)

Reads a file from the current position and reads until it finds a character in the set. Stops on the last character not in the set.

Parameters
fpThe file to be read
setA nul terminated array of char that contains the set of characters to reach

Here is the caller graph for this function: