@@ -448,6 +448,9 @@ struct SemanticValues : protected std::vector<any>
448
448
return std::string (s_, n_);
449
449
}
450
450
451
+ // Definition name
452
+ const std::string& name () const { return name_; }
453
+
451
454
// Line number and column at which the matched string is
452
455
std::pair<size_t , size_t > line_info () const {
453
456
return peg::line_info (ss, s_);
@@ -512,6 +515,7 @@ struct SemanticValues : protected std::vector<any>
512
515
size_t n_;
513
516
size_t choice_count_;
514
517
size_t choice_;
518
+ std::string name_;
515
519
516
520
template <typename F>
517
521
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
2212
2216
if (success (len)) {
2213
2217
chldsv.s_ = s;
2214
2218
chldsv.n_ = len;
2219
+ chldsv.name_ = outer_->name ;
2215
2220
2216
2221
if (!IsPrioritizedChoice::is_prioritized_choice (*ope_)) {
2217
2222
chldsv.choice_count_ = 0 ;
@@ -2915,12 +2920,15 @@ template <typename Annotation>
2915
2920
struct AstBase : public Annotation
2916
2921
{
2917
2922
AstBase (const char * a_path, size_t a_line, size_t a_column,
2918
- const char * a_name, size_t a_choice_count, size_t a_choice,
2923
+ const char * a_name, size_t a_position, size_t a_length,
2924
+ size_t a_choice_count, size_t a_choice,
2919
2925
const std::vector<std::shared_ptr<AstBase>>& a_nodes)
2920
2926
: path(a_path ? a_path : " " )
2921
2927
, line(a_line)
2922
2928
, column(a_column)
2923
2929
, name(a_name)
2930
+ , position(a_position)
2931
+ , length(a_length)
2924
2932
, choice_count(a_choice_count)
2925
2933
, choice(a_choice)
2926
2934
, original_name(a_name)
@@ -2935,12 +2943,15 @@ struct AstBase : public Annotation
2935
2943
{}
2936
2944
2937
2945
AstBase (const char * a_path, size_t a_line, size_t a_column,
2938
- const char * a_name, size_t a_choice_count, size_t a_choice,
2946
+ const char * a_name, size_t a_position, size_t a_length,
2947
+ size_t a_choice_count, size_t a_choice,
2939
2948
const std::string& a_token)
2940
2949
: path(a_path ? a_path : " " )
2941
2950
, line(a_line)
2942
2951
, column(a_column)
2943
2952
, name(a_name)
2953
+ , position(a_position)
2954
+ , length(a_length)
2944
2955
, choice_count(a_choice_count)
2945
2956
, choice(a_choice)
2946
2957
, original_name(a_name)
@@ -2955,11 +2966,14 @@ struct AstBase : public Annotation
2955
2966
{}
2956
2967
2957
2968
AstBase (const AstBase& ast, const char * a_original_name,
2969
+ size_t a_position, size_t a_length,
2958
2970
size_t a_original_choice_count, size_t a_original_choise)
2959
2971
: path(ast.path)
2960
2972
, line(ast.line)
2961
2973
, column(ast.column)
2962
2974
, name(ast.name)
2975
+ , position(a_position)
2976
+ , length(a_length)
2963
2977
, choice_count(ast.choice_count)
2964
2978
, choice(ast.choice)
2965
2979
, original_name(a_original_name)
@@ -2980,6 +2994,8 @@ struct AstBase : public Annotation
2980
2994
const size_t column;
2981
2995
2982
2996
const std::string name;
2997
+ size_t position;
2998
+ size_t length;
2983
2999
const size_t choice_count;
2984
3000
const size_t choice;
2985
3001
const std::string original_name;
@@ -3245,13 +3261,13 @@ class parser
3245
3261
if (rule.is_token ()) {
3246
3262
return std::make_shared<T>(
3247
3263
sv.path , line.first , line.second ,
3248
- name.c_str (), sv.choice_count (), sv.choice (),
3264
+ name.c_str (), std::distance (sv. ss , sv. c_str ()), sv. length (), sv.choice_count (), sv.choice (),
3249
3265
sv.token ());
3250
3266
}
3251
3267
3252
3268
auto ast = std::make_shared<T>(
3253
3269
sv.path , line.first , line.second ,
3254
- name.c_str (), sv.choice_count (), sv.choice (),
3270
+ name.c_str (), std::distance (sv. ss , sv. c_str ()), sv. length (), sv.choice_count (), sv.choice (),
3255
3271
sv.transform <std::shared_ptr<T>>());
3256
3272
3257
3273
for (auto node: ast->nodes ) {
0 commit comments