mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Added name
in SemanticValues
This commit is contained in:
parent
2dcdafe3cb
commit
b330799cd6
24
peglib.h
24
peglib.h
@ -448,6 +448,9 @@ struct SemanticValues : protected std::vector<any>
|
|||||||
return std::string(s_, n_);
|
return std::string(s_, n_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Definition name
|
||||||
|
const std::string& name() const { return name_; }
|
||||||
|
|
||||||
// Line number and column at which the matched string is
|
// Line number and column at which the matched string is
|
||||||
std::pair<size_t, size_t> line_info() const {
|
std::pair<size_t, size_t> line_info() const {
|
||||||
return peg::line_info(ss, s_);
|
return peg::line_info(ss, s_);
|
||||||
@ -512,6 +515,7 @@ private:
|
|||||||
size_t n_;
|
size_t n_;
|
||||||
size_t choice_count_;
|
size_t choice_count_;
|
||||||
size_t choice_;
|
size_t choice_;
|
||||||
|
std::string name_;
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
auto transform(F f) const -> vector<typename std::remove_const<decltype(f(any()))>::type> {
|
auto transform(F f) const -> vector<typename std::remove_const<decltype(f(any()))>::type> {
|
||||||
@ -2212,6 +2216,7 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
|
|||||||
if (success(len)) {
|
if (success(len)) {
|
||||||
chldsv.s_ = s;
|
chldsv.s_ = s;
|
||||||
chldsv.n_ = len;
|
chldsv.n_ = len;
|
||||||
|
chldsv.name_ = outer_->name;
|
||||||
|
|
||||||
if (!IsPrioritizedChoice::is_prioritized_choice(*ope_)) {
|
if (!IsPrioritizedChoice::is_prioritized_choice(*ope_)) {
|
||||||
chldsv.choice_count_ = 0;
|
chldsv.choice_count_ = 0;
|
||||||
@ -2915,12 +2920,15 @@ template <typename Annotation>
|
|||||||
struct AstBase : public Annotation
|
struct AstBase : public Annotation
|
||||||
{
|
{
|
||||||
AstBase(const char* a_path, size_t a_line, size_t a_column,
|
AstBase(const char* a_path, size_t a_line, size_t a_column,
|
||||||
const char* a_name, size_t a_choice_count, size_t a_choice,
|
const char* a_name, size_t a_position, size_t a_length,
|
||||||
|
size_t a_choice_count, size_t a_choice,
|
||||||
const std::vector<std::shared_ptr<AstBase>>& a_nodes)
|
const std::vector<std::shared_ptr<AstBase>>& a_nodes)
|
||||||
: path(a_path ? a_path : "")
|
: path(a_path ? a_path : "")
|
||||||
, line(a_line)
|
, line(a_line)
|
||||||
, column(a_column)
|
, column(a_column)
|
||||||
, name(a_name)
|
, name(a_name)
|
||||||
|
, position(a_position)
|
||||||
|
, length(a_length)
|
||||||
, choice_count(a_choice_count)
|
, choice_count(a_choice_count)
|
||||||
, choice(a_choice)
|
, choice(a_choice)
|
||||||
, original_name(a_name)
|
, original_name(a_name)
|
||||||
@ -2935,12 +2943,15 @@ struct AstBase : public Annotation
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
AstBase(const char* a_path, size_t a_line, size_t a_column,
|
AstBase(const char* a_path, size_t a_line, size_t a_column,
|
||||||
const char* a_name, size_t a_choice_count, size_t a_choice,
|
const char* a_name, size_t a_position, size_t a_length,
|
||||||
|
size_t a_choice_count, size_t a_choice,
|
||||||
const std::string& a_token)
|
const std::string& a_token)
|
||||||
: path(a_path ? a_path : "")
|
: path(a_path ? a_path : "")
|
||||||
, line(a_line)
|
, line(a_line)
|
||||||
, column(a_column)
|
, column(a_column)
|
||||||
, name(a_name)
|
, name(a_name)
|
||||||
|
, position(a_position)
|
||||||
|
, length(a_length)
|
||||||
, choice_count(a_choice_count)
|
, choice_count(a_choice_count)
|
||||||
, choice(a_choice)
|
, choice(a_choice)
|
||||||
, original_name(a_name)
|
, original_name(a_name)
|
||||||
@ -2955,11 +2966,14 @@ struct AstBase : public Annotation
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
AstBase(const AstBase& ast, const char* a_original_name,
|
AstBase(const AstBase& ast, const char* a_original_name,
|
||||||
|
size_t a_position, size_t a_length,
|
||||||
size_t a_original_choice_count, size_t a_original_choise)
|
size_t a_original_choice_count, size_t a_original_choise)
|
||||||
: path(ast.path)
|
: path(ast.path)
|
||||||
, line(ast.line)
|
, line(ast.line)
|
||||||
, column(ast.column)
|
, column(ast.column)
|
||||||
, name(ast.name)
|
, name(ast.name)
|
||||||
|
, position(a_position)
|
||||||
|
, length(a_length)
|
||||||
, choice_count(ast.choice_count)
|
, choice_count(ast.choice_count)
|
||||||
, choice(ast.choice)
|
, choice(ast.choice)
|
||||||
, original_name(a_original_name)
|
, original_name(a_original_name)
|
||||||
@ -2980,6 +2994,8 @@ struct AstBase : public Annotation
|
|||||||
const size_t column;
|
const size_t column;
|
||||||
|
|
||||||
const std::string name;
|
const std::string name;
|
||||||
|
size_t position;
|
||||||
|
size_t length;
|
||||||
const size_t choice_count;
|
const size_t choice_count;
|
||||||
const size_t choice;
|
const size_t choice;
|
||||||
const std::string original_name;
|
const std::string original_name;
|
||||||
@ -3245,13 +3261,13 @@ public:
|
|||||||
if (rule.is_token()) {
|
if (rule.is_token()) {
|
||||||
return std::make_shared<T>(
|
return std::make_shared<T>(
|
||||||
sv.path, line.first, line.second,
|
sv.path, line.first, line.second,
|
||||||
name.c_str(), sv.choice_count(), sv.choice(),
|
name.c_str(), std::distance(sv.ss, sv.c_str()), sv.length(), sv.choice_count(), sv.choice(),
|
||||||
sv.token());
|
sv.token());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ast = std::make_shared<T>(
|
auto ast = std::make_shared<T>(
|
||||||
sv.path, line.first, line.second,
|
sv.path, line.first, line.second,
|
||||||
name.c_str(), sv.choice_count(), sv.choice(),
|
name.c_str(), std::distance(sv.ss, sv.c_str()), sv.length(), sv.choice_count(), sv.choice(),
|
||||||
sv.transform<std::shared_ptr<T>>());
|
sv.transform<std::shared_ptr<T>>());
|
||||||
|
|
||||||
for (auto node: ast->nodes) {
|
for (auto node: ast->nodes) {
|
||||||
|
Loading…
Reference in New Issue
Block a user