1
|
1 |
"{ Package: 'stx:goodies/smaCC' }"
|
|
2 |
|
|
3 |
"{ NameSpace: SmaCC }"
|
|
4 |
|
|
5 |
Object subclass:#SmaCCRegularExpressionNode
|
|
6 |
instanceVariableNames:'action position'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'SmaCC-Scanner Generator'
|
|
10 |
!
|
|
11 |
|
|
12 |
SmaCCRegularExpressionNode comment:'SmaCCRegularExpressionNode represents a regular expression. The scanner is represented by a regular expression. These are the initial objects created in producing the scanner. From these nodes, we create a directed graph and then we compile the graph.
|
|
13 |
|
|
14 |
Subclasses must implement the following messages:
|
|
15 |
accessing
|
|
16 |
possibleMatchesSize
|
|
17 |
private
|
|
18 |
asNFAStartingWith:
|
|
19 |
possibleMatchesDo:on:
|
|
20 |
|
|
21 |
Instance Variables:
|
|
22 |
action <SequenceableCollection> the actions to be performed when we find a match
|
|
23 |
position <Integer> the position of the RE in the scanner. If we have multiple matches, we prefer the ones listed first.'
|
|
24 |
!
|
|
25 |
|
|
26 |
|
|
27 |
!SmaCCRegularExpressionNode class methodsFor:'instance creation'!
|
|
28 |
|
|
29 |
new
|
|
30 |
^(super new)
|
|
31 |
initialize;
|
|
32 |
yourself
|
|
33 |
! !
|
|
34 |
|
|
35 |
!SmaCCRegularExpressionNode methodsFor:'accessing'!
|
|
36 |
|
|
37 |
, aScannerNode
|
|
38 |
^SmaCCSequenceRENode nodes: (OrderedCollection with: self with: aScannerNode)
|
|
39 |
!
|
|
40 |
|
|
41 |
position
|
|
42 |
^position
|
|
43 |
!
|
|
44 |
|
|
45 |
position: anInteger
|
|
46 |
position := anInteger
|
|
47 |
!
|
|
48 |
|
|
49 |
possibleMatches
|
|
50 |
| matches |
|
|
51 |
matches := OrderedCollection new.
|
|
52 |
self possibleMatchesDo: [:each | matches add: each].
|
|
53 |
^matches
|
|
54 |
!
|
|
55 |
|
|
56 |
possibleMatchesDo: aBlock
|
|
57 |
| stream |
|
|
58 |
stream := WriteStream on: String new.
|
|
59 |
self possibleMatchesDo: [aBlock value: stream contents] on: stream
|
|
60 |
!
|
|
61 |
|
|
62 |
possibleMatchesSize
|
|
63 |
^self subclassResponsibility
|
|
64 |
!
|
|
65 |
|
|
66 |
repeat
|
|
67 |
^SmaCCRepeatingRENode component: self
|
|
68 |
!
|
|
69 |
|
|
70 |
repeatFor: minimum to: maximum
|
|
71 |
^SmaCCRepeatingRENode
|
|
72 |
component: self
|
|
73 |
minimum: minimum
|
|
74 |
maximum: maximum
|
|
75 |
!
|
|
76 |
|
|
77 |
repeatForAtLeast: minimum
|
|
78 |
^SmaCCRepeatingRENode component: self minimum: minimum
|
|
79 |
!
|
|
80 |
|
|
81 |
| aScannerNode
|
|
82 |
^SmaCCOrRENode nodes: (OrderedCollection with: self with: aScannerNode)
|
|
83 |
! !
|
|
84 |
|
|
85 |
!SmaCCRegularExpressionNode methodsFor:'converting'!
|
|
86 |
|
|
87 |
asDFA
|
|
88 |
| startNode |
|
|
89 |
startNode := SmaCCNode new.
|
|
90 |
self asNFAStartingWith: startNode.
|
|
91 |
^startNode asNFAWithoutEpsilonTransitions asDFA
|
|
92 |
! !
|
|
93 |
|
|
94 |
!SmaCCRegularExpressionNode methodsFor:'initialize-release'!
|
|
95 |
|
|
96 |
action
|
|
97 |
^action
|
|
98 |
!
|
|
99 |
|
|
100 |
action: aString
|
|
101 |
action := aString
|
|
102 |
!
|
|
103 |
|
|
104 |
initialize
|
|
105 |
! !
|
|
106 |
|
|
107 |
!SmaCCRegularExpressionNode methodsFor:'private'!
|
|
108 |
|
|
109 |
asNFAStartingWith: startNode
|
|
110 |
^self subclassResponsibility
|
|
111 |
!
|
|
112 |
|
|
113 |
possibleMatchesDo: aBlock on: aStream
|
|
114 |
self subclassResponsibility
|
|
115 |
! !
|
|
116 |
|
|
117 |
!SmaCCRegularExpressionNode methodsFor:'public'!
|
|
118 |
|
|
119 |
isKeywordLiteral
|
|
120 |
self possibleMatchesSize < 50 ifFalse: [^false].
|
|
121 |
self possibleMatchesDo:
|
|
122 |
[:each |
|
|
123 |
(each allSatisfy: [:char | char isAlphaNumeric or: [char == $_]])
|
|
124 |
ifFalse: [^false]].
|
|
125 |
^true
|
|
126 |
! !
|
|
127 |
|
|
128 |
!SmaCCRegularExpressionNode class methodsFor:'documentation'!
|
|
129 |
|
|
130 |
version
|
|
131 |
^ '$Header: /opt/data/cvs/stx/goodies/smaCC/SmaCC__SmaCCRegularExpressionNode.st,v 1.1 2006-02-09 21:15:38 vranyj1 Exp $'
|
15
|
132 |
!
|
|
133 |
|
|
134 |
version_SVN
|
|
135 |
^ '$Id$'
|
1
|
136 |
! !
|