-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathdriver.cpp
More file actions
77 lines (66 loc) · 1.93 KB
/
driver.cpp
File metadata and controls
77 lines (66 loc) · 1.93 KB
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
77
/*
* Copyright (C) 2016-2017, Egor Pugin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "driver.h"
#include <algorithm>
#include <fstream>
#include <sstream>
// Prevent using <unistd.h> because of bug in flex.
#define YY_NO_UNISTD_H 1
#define YY_DECL 1
#include <bazel/lexer.h>
extern yy_bazel::parser::symbol_type ll_bazellex(yyscan_t yyscanner, yy_bazel::location &loc);
BazelParserDriver::BazelParserDriver()
{
}
yy_bazel::parser::symbol_type BazelParserDriver::lex()
{
auto ret = ll_bazellex(scanner, location);
return ret;
}
int BazelParserDriver::parse(const std::string &s)
{
parseMode = Mode::String;
ll_bazellex_init(&scanner);
ll_bazel_scan_string(s.c_str(), scanner);
auto res = parse();
ll_bazellex_destroy(scanner);
return res;
}
int BazelParserDriver::parse()
{
yy_bazel::parser parser(*this);
parser.set_debug_level(debug);
int res = parser.parse();
return res;
}
void BazelParserDriver::error(const yy_bazel::location &l, const std::string &m)
{
std::ostringstream ss;
ss << l << " " << m << "\n";
if (!can_throw)
std::cerr << ss.str();
else
throw std::runtime_error("Error during bazel parse: " + ss.str());
}
void BazelParserDriver::error(const std::string& m)
{
std::ostringstream ss;
ss << m << "\n";
if (!can_throw)
std::cerr << ss.str();
else
throw std::runtime_error("Error during bazel parse: " + ss.str());
}