summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/parse/libparse.hh
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/parse/libparse.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/parse/libparse.hh')
-rw-r--r--tiger-compiler/src/parse/libparse.hh76
1 files changed, 76 insertions, 0 deletions
diff --git a/tiger-compiler/src/parse/libparse.hh b/tiger-compiler/src/parse/libparse.hh
new file mode 100644
index 0000000..7781bb6
--- /dev/null
+++ b/tiger-compiler/src/parse/libparse.hh
@@ -0,0 +1,76 @@
+/**
+ ** \file parse/libparse.hh
+ ** \brief Declare functions and variables exported by parse module.
+ */
+
+#pragma once
+
+#include <set>
+#include <string>
+#include <utility>
+
+#include <ast/fwd.hh>
+#include <misc/error.hh>
+#include <misc/file-library.hh>
+#include <parse/fwd.hh>
+
+/// Parsing the input, delivering an ast::Ast.
+namespace parse
+{
+ /// \brief Parse a Tiger file, return the corresponding abstract syntax tree.
+ ///
+ /// \param prelude name of the prelude file.
+ /// \param fname path and name of the tiger file.
+ /// \param library library for managing search path.
+ /// \param scan_trace_p display information on scan step.
+ /// \param parse_trace_p display information on parse step.
+ /// \param enable_object_extensions_p enable object constructions
+ ///
+ /// \return a pair composed of a pointer to an abstract parse tree
+ /// (set to `nullptr' upon failure) and an error status.
+ /// This function is the only interface available between
+ /// the scanner/parser and the rest of the program.
+
+#ifdef SWIG
+ %newobject parse;
+#endif
+
+ /**
+ * \brief Parse the default prelude and return it.
+ * Return null if no-prelude is set.
+ * \return an AST representing the EPITA Tiger default prelude
+ */
+ ast::ChunkList* parse_prelude();
+
+ std::pair<ast::ChunkList*, misc::error>
+ parse(const std::string& prelude,
+ const std::string& fname,
+ misc::file_library& library,
+ bool scan_trace_p,
+ bool parse_trace_p,
+ bool enable_object_extensions_p = false,
+ bool enable_assert_extensions_p = false);
+
+ /// \brief Parse a Tweast.
+ ///
+ /// Extensions are enabled. Raises an exception on errors.
+ ast_type parse(Tweast& input);
+
+ /// Parse a std::string. Used for unit tests.
+ ast::Exp* parse(const std::string& str,
+ bool enable_object_extensions_p = false);
+
+ /// Parse a std::string. Used for unit tests.
+ /// The declaration of the _main function is automatically added.
+ ast::ChunkList* parse_unit(const std::string& str,
+ bool enable_object_extensions_p = false);
+
+ /// \brief Parse a set of declarations.
+ ///
+ /// Wrapper around parse::parse to return the single ast::ChunkInterface
+ /// to be found in the input (expected to contain ChunkList).
+ ///
+ /// Used by desugar::BoundsCheckingVisitor and object::ObjectDesugarVisitor.
+ ast::ChunkInterface* parse_chunks(Tweast& in);
+
+} // namespace parse