aboutsummaryrefslogtreecommitdiff
path: root/build/parser
blob: c48701590e46093f5045abb3bb33819b5c8fc962 (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
// file      : build/parser -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_PARSER
#define BUILD_PARSER

#include <string>
#include <vector>
#include <iosfwd>
#include <exception>

#include <build/path>

namespace build
{
  class token;
  enum class token_type;
  class lexer;

  // The handler must assume the diagnostics has already been issued.
  //
  struct parser_error: std::exception {};

  class parser
  {
  public:
    parser (std::ostream& diag): diag_ (diag) {}

    void
    parse (std::istream&, const path&);

    // Recursive descent parser.
    //
  private:
    typedef std::vector<std::string> names;

    void
    parse_clause (token&, token_type&);

    names
    parse_names (token& t, token_type& tt)
    {
      names ns;
      parse_names (t, tt, ns);
      return ns;
    }

    void
    parse_names (token&, token_type&, names&);

    // Utilities.
    //
  private:
    token_type
    next (token&, token_type&);

    std::ostream&
    error (const token&);

  private:
    std::ostream& diag_;

    lexer* lexer_;
    const path* path_;
  };
}

#endif // BUILD_PARSER