Parsing¶
This section contains definitions declared in the chpl::parsing namespace.
-
namespace chpl::parsing¶
-
Functions
-
const FileContents &fileText(Context *context, UniqueString path)¶
This query returns the contents of a file as the string field in the FileContents. In case there is an error reading the file, the error is stored in the error field of the FileContents.
-
void setFileText(Context *context, UniqueString path, FileContents result)¶
This function sets the FileContents that will be returned by the fileText query above.
-
void setFileText(Context *context, UniqueString path, std::string text)¶
This function sets the string that will be returned by the fileText query above. The FileContents stored will have an empty ErrorMessage field.
-
const uast::BuilderResult &parseFile(Context *context, UniqueString path)¶
This query reads a file (with the fileText query) and then parses it.
-
const Location &locateId(Context *context, ID id)¶
This query returns the Location where a particular ID appeared. It cannot be used for Comments because Comments don’t have IDs set. If Locations for Comments are needed, use the locations field from the result of parseFile.
-
const Location &locateAst(Context *context, const uast::ASTNode *ast)¶
This function just runs locateId on ast->id(). Similarly to locateID, it cannot be used to get a Location for a Comment.
-
const ModuleVec &parse(Context *context, UniqueString path)¶
This query returns a vector of parsed modules given a file path.
-
const uast::Module *getToplevelModule(Context *context, UniqueString name)¶
This query parses a toplevel module by name. Returns nullptr if no such toplevel module can be found.
-
class FileContents¶
- #include <FileContents.h>
This class represents the result of reading a file.
Public Functions
-
inline FileContents()¶
Construct a FileContents containing empty text and no error
-
inline FileContents(std::string text)¶
Construct a FileContents containing the passed text and no error
-
inline FileContents(std::string text, ErrorMessage error)¶
Construct a FileContents containing the passed text and error
-
inline const std::string &text() const¶
Return a reference to the contents of this file
-
inline const ErrorMessage &error() const¶
Return a reference to an error encountered when reading this file
-
inline bool operator==(const FileContents &other) const¶
-
inline bool operator!=(const FileContents &other) const¶
-
inline void swap(FileContents &other)¶
-
inline FileContents()¶
-
class Parser¶
- #include <Parser.h>
A class for parsing
Public Functions
-
~Parser() = default¶
-
uast::BuilderResult parseFile(const char *path)¶
Parse a file at a particular path.
-
uast::BuilderResult parseString(const char *path, const char *str)¶
Parse source code in a string. ‘path’ is only used for certain errors.
-
~Parser() = default¶
-
const FileContents &fileText(Context *context, UniqueString path)¶