Skip to content

Commit 3519a3b

Browse files
committed
Finish clean up and enable sorbet on CI
1 parent 8858c98 commit 3519a3b

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ jobs:
5050
- name: RBS Inline
5151
run: bundle exec rake rbs_inline
5252

53-
# - name: Sorbet
54-
# run: bundle exec srb tc
53+
- name: Sorbet
54+
run: bundle exec srb tc
5555

5656
- name: Run C tests
5757
run: ./run_herb_tests

templates/lib/herb/ast/nodes.rb.erb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ module Herb
22
module AST
33
<%- nodes.each do |node| -%>
44
class <%= node.name -%> < Node
5+
#: type serialized_<%= node.human %> = {
56
<%- node.fields.each do |field| -%>
6-
attr_reader :<%= field.name %> #: <%= field.ruby_type %>
7+
#| <%= field.name %>: <%= field.ruby_type %>,
8+
<%- end -%>
9+
#| }
10+
11+
<%- node.fields.each do |field| -%>
12+
#: <%= field.ruby_type %>
13+
attr_reader :<%= field.name %>
714
<%- end -%>
815

916
#: (<%= ["String", "Location", "Array[Herb::Errors::Error]", *node.fields.map(&:ruby_type)].join(", ") %>) -> void
@@ -24,7 +31,7 @@ module Herb
2431
<%- node.fields.each do |field| -%>
2532
<%= field.name %>: <%= field.name %>,
2633
<%- end -%>
27-
}) #: Herb::serialized_<%= node.human %>
34+
})
2835
end
2936

3037
#: (Visitor) -> void
@@ -73,7 +80,7 @@ module Herb
7380
output += %(<%= name %>#{<%= field.name %>.inspect}\n)
7481
<%- when Herb::Template::TokenField -%>
7582
output += "<%= name %>"
76-
output += <%= field.name %> ? <%= field.name %>.tree_inspect : "∅"
83+
output += <%= field.name %>.tree_inspect
7784
output += "\n"
7885
<%- when Herb::Template::BooleanField -%>
7986
output += "<%= name %>"
@@ -87,18 +94,14 @@ module Herb
8794
# no-op for <%= field.name %>
8895
<%- when Herb::Template::NodeField -%>
8996
output += "<%= name %>"
90-
if <%= field.name %>
91-
<%- prefix = (node.fields.last == field) ? " " : "│ " -%>
92-
output += "\n"
93-
<%- if (node.fields.last == field) -%>
94-
output += " └── "
95-
<%- else -%>
96-
output += "│ └── "
97-
<%- end -%>
98-
output += <%= field.name %>.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "<%= prefix %>").delete_prefix("<%= prefix %>")
99-
else
100-
output += "∅\n"
101-
end
97+
<%- prefix = (node.fields.last == field) ? " " : "│ " -%>
98+
output += "\n"
99+
<%- if (node.fields.last == field) -%>
100+
output += " └── "
101+
<%- else -%>
102+
output += "│ └── "
103+
<%- end -%>
104+
output += <%= field.name %>.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "<%= prefix %>").delete_prefix("<%= prefix %>")
102105
<%- when Herb::Template::ArrayField -%>
103106
output += "<%= name %>"
104107
output += inspect_array(<%= field.name %>, prefix: "<%= (node.fields.last == field) ? " " : "│ " %>")

templates/lib/herb/errors.rb.erb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ module Herb
4747

4848
<%- errors.each do |error| -%>
4949
class <%= error.name -%> < Error
50+
#: type serialized_<%= error.human %> = {
5051
<%- error.fields.each do |field| -%>
51-
attr_reader :<%= field.name %> #: <%= field.ruby_type %>
52+
#| <%= field.name %>: <%= field.ruby_type %>,
53+
<%- end -%>
54+
#| }
55+
56+
<%- error.fields.each do |field| -%>
57+
#: <%= field.ruby_type %>
58+
attr_reader :<%= field.name %>
5259
<%- end -%>
5360

5461
#: (<%= [*base_arguments.map(&:last), *error.fields.map(&:ruby_type)].join(", ") %>) -> void
@@ -86,9 +93,9 @@ module Herb
8693
<%- name = "#{symbol} #{field.name}: " -%>
8794
<%- case field -%>
8895
<%- when Herb::Template::PositionField -%>
89-
output += %(<%= name %>#{<%= field.name %> ? <%= field.name %>.tree_inspect : "∅"}\n)
96+
output += %(<%= name %>#{<%= field.name %>.tree_inspect}\n)
9097
<%- when Herb::Template::TokenField -%>
91-
output += %(<%= name %>#{<%= field.name %> ? <%= field.name %>.tree_inspect : "∅"}\n)
98+
output += %(<%= name %>#{<%= field.name %>.tree_inspect}\n)
9299
<%- when Herb::Template::TokenTypeField -%>
93100
output += %(<%= name %>#{<%= field.name %>.inspect}\n)
94101
<%- when Herb::Template::StringField -%>

0 commit comments

Comments
 (0)