Skip to content

Commit

Permalink
Properly indent multi-line init and after actions (#242)
Browse files Browse the repository at this point in the history
Previously, only the first line got indented in the generated code,
making it hard to write multi-line actions.
  • Loading branch information
akosthekiss authored Oct 28, 2024
1 parent b10b085 commit 35417bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class {{ graph.name }}({{ graph.superclass }}):
with {{ rule.type }}Context(self, '{{ rule.name }}', parent) as rule:
current = rule.current
{% if rule.init %}
{{ resolveVarRefs(rule.init) }}
{{ resolveVarRefs(rule.init) | indent | indent | indent }}
{% endif %}
{% for edge in rule.out_edges %}
{{ processNode(edge.dst, edge) | indent | indent | indent -}}
{% endfor %}
{% if rule.after %}
{{ resolveVarRefs(rule.after) }}
{{ resolveVarRefs(rule.after) | indent | indent | indent }}
{% endif %}
{% for _, k, _ in rule.returns %}
current.{{ k }} = local_ctx['{{ k }}']
Expand Down
2 changes: 2 additions & 0 deletions tests/grammars/InitAfter.g4
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ start : r=wrapped_rule {assert $r.testValue == 'endValue', $r.testValue} ;
wrapped_rule returns [testValue]
@init {
$testValue = 'startValue'
pass # no-op, only to ensure that multi-line actions are properly handled
}
@after {
$testValue = 'endValue'
pass # no-op, only to ensure that multi-line actions are properly handled
}
: {assert $testValue == 'startValue', $testValue} A ;
A : 'a' ;

0 comments on commit 35417bc

Please sign in to comment.