Commit a2e6f24
authored
Parser: Expose Prism Nodes in Herb Syntax Tree (#1350)
This pull request updates the parser to be able expose the Prism Nodes
as part of the Herb Syntax Tree. We now expose three new parser options
that control the way the parser exposes the Prism Nodes it sees:
`prism_nodes`, `prism_nodes_deep`, and `prism_program`.
* `prism_nodes` exposes the Prism nodes for each individual `ERB*` node
on the node itself
* `prism_nodes_deep` does the same thing as `prism_nodes`, but it also
includes all nodes of all children inside of itself. For `<%= tag.div do
%><%= user.name %><% end %>` the `tag.div` ERB block node will also have
the `user.name` nodes as part of the `prism_node` field on itself.
* `prism_program` extracts the Ruby from the whole file and passes that
to Prism. It then exposes the whole template on the `DocumentNode` on
the `prism_node` field.
For example for a template like:
```html+erb
<h1><%= @post.title %></h1>
```
The parser will now produces the following using `prism_nodes: true`:
```js
@ DocumentNode (location: (1:0)-(1:27))
└── children: (1 item)
└── @ HTMLElementNode (location: (1:0)-(1:27))
├── open_tag:
│ └── @ HTMLOpenTagNode (location: (1:0)-(1:4))
│ ├── tag_opening: "<" (location: (1:0)-(1:1))
│ ├── tag_name: "h1" (location: (1:1)-(1:3))
│ ├── tag_closing: ">" (location: (1:3)-(1:4))
│ ├── children: []
│ └── is_void: false
│
├── tag_name: "h1" (location: (1:1)-(1:3))
├── body: (1 item)
│ └── @ ERBContentNode (location: (1:4)-(1:22))
│ ├── tag_opening: "<%=" (location: (1:4)-(1:7))
│ ├── content: " @post.title " (location: (1:7)-(1:20))
│ ├── tag_closing: "%>" (location: (1:20)-(1:22))
│ ├── parsed: true
│ ├── valid: true
│ └── prism_node:
│ └── @ CallNode (location: (1:8)-(1:19))
│ ├── receiver:
│ │ └── @ InstanceVariableReadNode (location: (1:8)-(1:13))
│ │ └── name: "@post"
│ ├── callOperatorLoc: (location: (1:13)-(1:14))
│ ├── name: "title"
│ ├── messageLoc: (location: (1:14)-(1:19))
│ ├── openingLoc: ∅
│ ├── arguments_: ∅
│ ├── closingLoc: ∅
│ ├── equalLoc: ∅
│ └── block: ∅
│
├── close_tag:
│ └── @ HTMLCloseTagNode (location: (1:22)-(1:27))
│ ├── tag_opening: "</" (location: (1:22)-(1:24))
│ ├── tag_name: "h1" (location: (1:24)-(1:26))
│ ├── children: []
│ └── tag_closing: ">" (location: (1:26)-(1:27))
│
├── is_void: false
└── element_source: "HTML"
```
Resolves #1036
Resolves #11211 parent 2ec7dc8 commit a2e6f24
File tree
184 files changed
+10350
-151
lines changed- ext/herb
- javascript/packages
- core
- src
- prism
- linter/test
- node
- extension
- java
- org/herb
- ast
- lib/herb
- playground
- src
- controllers
- rust
- src
- tests
- snapshots
- sig/herb
- ast
- src
- analyze
- include
- analyze
- templates
- ext/herb
- javascript/packages
- core/src
- node/extension
- java
- org/herb/ast
- lib/herb/ast
- rust/src
- ast
- src
- include
- wasm
- test
- parser/prism
- snapshots/parser/prism
- prism_nodes_deep_test
- prism_nodes_test
- prism_program_test
- wasm
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
184 files changed
+10350
-151
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| 89 | + | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| |||
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| 105 | + | |
101 | 106 | | |
102 | 107 | | |
103 | 108 | | |
| |||
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
124 | | - | |
125 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
126 | 133 | | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
130 | 137 | | |
131 | 138 | | |
| 139 | + | |
132 | 140 | | |
133 | 141 | | |
134 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
372 | 378 | | |
373 | 379 | | |
374 | 380 | | |
| |||
643 | 649 | | |
644 | 650 | | |
645 | 651 | | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
646 | 655 | | |
647 | 656 | | |
648 | 657 | | |
| |||
686 | 695 | | |
687 | 696 | | |
688 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
689 | 701 | | |
690 | 702 | | |
691 | 703 | | |
| |||
717 | 729 | | |
718 | 730 | | |
719 | 731 | | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
720 | 735 | | |
721 | 736 | | |
722 | 737 | | |
| |||
765 | 780 | | |
766 | 781 | | |
767 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
768 | 786 | | |
769 | 787 | | |
770 | 788 | | |
| |||
795 | 813 | | |
796 | 814 | | |
797 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
798 | 819 | | |
799 | 820 | | |
800 | 821 | | |
| |||
821 | 842 | | |
822 | 843 | | |
823 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
824 | 848 | | |
825 | 849 | | |
826 | 850 | | |
| |||
843 | 867 | | |
844 | 868 | | |
845 | 869 | | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
846 | 873 | | |
847 | 874 | | |
848 | 875 | | |
| |||
868 | 895 | | |
869 | 896 | | |
870 | 897 | | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
871 | 901 | | |
872 | 902 | | |
873 | 903 | | |
| |||
928 | 958 | | |
929 | 959 | | |
930 | 960 | | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
931 | 964 | | |
932 | 965 | | |
933 | 966 | | |
| |||
965 | 998 | | |
966 | 999 | | |
967 | 1000 | | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
968 | 1004 | | |
969 | 1005 | | |
970 | 1006 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
139 | 151 | | |
140 | 152 | | |
141 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
71 | 95 | | |
72 | 96 | | |
73 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
105 | 150 | | |
106 | 151 | | |
107 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
47 | 77 | | |
48 | 78 | | |
49 | 79 | | |
| |||
0 commit comments