Skip to content

Commit f603f20

Browse files
authored
Print information about type, flags on AST templated code (#1380)
This commit adds the node type and the node flags as comments to the AST templated code.
1 parent 4ee9d46 commit f603f20

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

templates/include/yarp/ast.h.erb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ typedef struct yp_node {
7070
// existed in the original grammar and ripper, but it's not a 1:1 mapping.
7171
yp_node_type_t type;
7272

73-
// This represents any flags on the node. Currently, this is only a newline
74-
// flag
73+
// This represents any flags on the node
7574
yp_node_flags_t flags;
7675

7776
// This is the location of the node in the source. It's a range of bytes
@@ -81,6 +80,15 @@ typedef struct yp_node {
8180
<%- nodes.each do |node| -%>
8281

8382
// <%= node.name %>
83+
//
84+
// Type: <%= node.type %>
85+
<%- if (node_flags = node.fields.find { |field| field.is_a? YARP::FlagsField }) -%>
86+
// Flags:
87+
<%- found = flags.find { |flag| flag.name == node_flags.kind }.tap { |found| raise "Expected to find #{field.kind}" unless found } -%>
88+
<%- found.values.each do |value| -%>
89+
// YP_<%= found.human.upcase %>_<%= value.name %>
90+
<%- end -%>
91+
<%- end -%>
8492
typedef struct yp_<%= node.human %> {
8593
yp_node_t base;
8694
<%- node.fields.grep_v(YARP::FlagsField).each do |field| -%>

0 commit comments

Comments
 (0)