summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/parse/libparse.hh
blob: 7781bb674c71beda289c666b7ca19c91bb72db01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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