author | Claus Gittinger <cg@exept.de> |
Fri, 21 Feb 2020 20:48:14 +0100 | |
changeset 1231 | b7d945ef967a |
parent 1221 | 59cedf8553ec |
permissions | -rw-r--r-- |
1221 | 1 |
"{ Encoding: utf8 }" |
2 |
||
3 |
" |
|
4 |
COPYRIGHT (c) 2018 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
668 | 14 |
"{ Package: 'stx:libjavascript' }" |
15 |
||
1221 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
668 | 18 |
JavaScriptParseNodeVisitor subclass:#JavaScriptParseNodeValidator |
19 |
instanceVariableNames:'stack source' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Languages-JavaScript-Compiling & Parsing' |
|
23 |
! |
|
24 |
||
1221 | 25 |
!JavaScriptParseNodeValidator class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2018 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! ! |
|
668 | 40 |
|
41 |
!JavaScriptParseNodeValidator class methodsFor:'validation'! |
|
42 |
||
43 |
validate: aParseNode source: source |
|
44 |
||
45 |
^self basicNew validate: aParseNode source: source |
|
46 |
||
47 |
"Created: / 27-07-2011 / 13:43:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 |
! ! |
|
49 |
||
50 |
!JavaScriptParseNodeValidator methodsFor:'validation'! |
|
51 |
||
52 |
validate: tree source: src |
|
53 |
||
54 |
tree isNil ifTrue:[^self]. |
|
55 |
||
56 |
source := src. |
|
57 |
stack := Stack with: nil. |
|
58 |
||
59 |
^self visit: tree |
|
60 |
||
61 |
"Created: / 27-07-2011 / 13:43:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 |
! |
|
63 |
||
64 |
validateNode:node |
|
65 |
||
66 |
self assert: node startPosition isInteger. |
|
67 |
self assert: node endPosition isInteger. |
|
684
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
68 |
node startPosition == -1 ifTrue:[ |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
69 |
self assert: node endPosition == -1. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
70 |
] ifFalse:[ |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
71 |
node endPosition == -1 ifTrue:[ |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
72 |
self assert: node startPosition == -1. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
73 |
]. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
74 |
]. |
668 | 75 |
self assert: node parent == stack top |
76 |
||
684
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
77 |
"Modified: / 23-09-2013 / 11:31:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
668 | 78 |
! ! |
79 |
||
80 |
!JavaScriptParseNodeValidator methodsFor:'visiting'! |
|
81 |
||
82 |
visit:anObject |
|
83 |
|accept stmt| |
|
84 |
||
85 |
accept := |
|
86 |
[:node | |
|
87 |
stack push:node. |
|
88 |
node acceptVisitor:self. |
|
89 |
stack pop. |
|
90 |
self validateNode:node. ]. |
|
91 |
^ anObject isStatementNode |
|
92 |
ifTrue: |
|
93 |
[ stmt := anObject. |
|
94 |
[ stmt isNil ] whileFalse: |
|
95 |
[ accept value:stmt. |
|
96 |
stmt := stmt nextStatement. ] ] |
|
97 |
ifFalse:[ accept value:anObject. ] |
|
98 |
||
99 |
"Created: / 25-07-2011 / 23:14:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 |
! |
|
101 |
||
684
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
102 |
visitBreakStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
103 |
self assert: (source copyFrom: anObject startPosition to: anObject startPosition + 'break' size - 1) = 'break'. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
104 |
super visitBreakStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
105 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
106 |
"Created: / 23-09-2013 / 11:30:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
107 |
! |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
108 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
109 |
visitContinueStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
110 |
self assert: (source copyFrom: anObject startPosition to: anObject startPosition + 'continue' size - 1) = 'continue'. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
111 |
super visitContinueStatementNode: anObject. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
112 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
113 |
"Created: / 23-09-2013 / 11:29:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
114 |
! |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
115 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
116 |
visitForStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
117 |
self assert: (source copyFrom: anObject startPosition to: anObject startPosition + 2) = 'for'. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
118 |
super visitForStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
119 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
120 |
"Created: / 23-09-2013 / 11:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
121 |
! |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
122 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
123 |
visitIfStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
124 |
self assert: (source copyFrom: anObject startPosition to: anObject startPosition + 1) = 'if'. |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
125 |
super visitIfStatementNode: anObject |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
126 |
|
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
127 |
"Created: / 23-09-2013 / 11:28:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
128 |
! |
2f0c836ab310
Fixes for recording node positions (part II)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
676
diff
changeset
|
129 |
|
668 | 130 |
visitVariableNode:anObject |
131 |
||
132 |
| s e | |
|
133 |
s := anObject startPosition. |
|
134 |
e := anObject endPosition. |
|
676
6413f5b78426
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
668
diff
changeset
|
135 |
|
6413f5b78426
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
668
diff
changeset
|
136 |
(s notNil and:[e notNil and:[s ~~ -1 and:[e ~~ -1 and:[ |
6413f5b78426
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
668
diff
changeset
|
137 |
#(MethodVariable InstanceVariable) includes: anObject type]]]]) ifTrue:[ |
668 | 138 |
self assert: anObject name = |
139 |
(source copyFrom: anObject startPosition to: anObject endPosition). |
|
140 |
]. |
|
141 |
||
142 |
super visitVariableNode: anObject. |
|
143 |
||
144 |
"Created: / 20-08-2011 / 23:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
145 |
"Modified: / 21-08-2011 / 13:51:55 / cg" |
|
676
6413f5b78426
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
668
diff
changeset
|
146 |
"Modified: / 20-09-2013 / 14:09:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
668 | 147 |
! ! |
148 |
||
149 |
!JavaScriptParseNodeValidator class methodsFor:'documentation'! |
|
150 |
||
151 |
version |
|
152 |
^ '$Header$' |
|
153 |
! |
|
154 |
||
155 |
version_CVS |
|
156 |
^ '$Header$' |
|
157 |
! ! |
|
158 |