4
4
5
5
module CodeRay
6
6
module Scanners
7
-
7
+
8
8
class AppleScript < Scanner
9
9
10
10
register_for :applescript
11
-
11
+
12
12
RESERVED_WORDS = [
13
13
'#include' , 'for' , 'foreach' , 'if' , 'elseif' , 'else' , 'while' , 'do' , 'dowhile' , 'end' ,
14
14
'switch' , 'case' , 'return' , 'break' , 'continue' , 'in' , 'to' , 'of' , 'repeat' , 'tell' , 'then' , 'as'
@@ -100,9 +100,9 @@ class AppleScript < Scanner
100
100
'UTC' , 'valueOf' , 'variable' , 'version' , 'Video' , 'visible' , 'void' , 'watch' , 'width' ,
101
101
'with' , 'wordwrap' , 'XML' , 'xmlDecl' , 'XMLNode' , 'XMLSocket'
102
102
]
103
-
103
+
104
104
PREDEFINED_TYPES = [
105
- 'boolean' , 'small integer' , 'integer' , 'double integer' ,
105
+ 'boolean' , 'small integer' , 'integer' , 'double integer' ,
106
106
'small real' , 'real' , 'date' , 'list' , 'record' , 'string' , 'class'
107
107
]
108
108
@@ -118,21 +118,21 @@ class AppleScript < Scanner
118
118
'all caps' , 'all lowercase' , 'bold' , 'condensed' , 'expanded' , 'hidden' , 'italic' , 'outline' , 'plain' , 'shadow' , 'small caps' , 'strikethrough' , 'subscript' , 'superscript' , 'underline' ,
119
119
'version'
120
120
]
121
-
121
+
122
122
PLAIN_STRING_CONTENT = {
123
123
"'" => /[^'\n ]+/ ,
124
124
'"' => /[^"\n ]+/ ,
125
125
}
126
-
127
-
126
+
127
+
128
128
IDENT_KIND = CaseIgnoringWordList . new ( :ident ) .
129
129
add ( RESERVED_WORDS , :reserved ) .
130
130
add ( KEYWORD_OPERATOR , :operator ) .
131
131
add ( DIRECTIVES , :directive ) .
132
132
add ( PREDEFINED_TYPES , :pre_type ) .
133
133
add ( PREDEFINED_CONSTANTS , :pre_constant )
134
-
135
-
134
+
135
+
136
136
137
137
def scan_tokens tokens , options
138
138
@@ -145,70 +145,70 @@ def scan_tokens tokens, options
145
145
match = nil
146
146
147
147
if state == :initial
148
-
148
+
149
149
if scan ( /\s +/x )
150
150
kind = :space
151
-
151
+
152
152
elsif scan ( %r! \{ \$ [^}]* \} ? | \( \* \$ (?: .*? \* \) | .* ) !mx )
153
153
kind = :preprocessor
154
-
155
- elsif scan ( /^[\s \t ]*--.*/x )
154
+
155
+ elsif scan ( /^[\s ]*--.*/x )
156
156
kind = :comment
157
157
elsif scan ( /\( \* (?: .*? \* \) $ | .* )/mx )
158
158
kind = :comment
159
-
159
+
160
160
elsif scan ( / [-+*\/ =<>:;,.@\^ |\( \) \[ \] ]+ /x )
161
161
kind = :operator
162
-
162
+
163
163
elsif match = scan ( / [A-Za-z_][A-Za-z_0-9]* /x )
164
164
kind = IDENT_KIND [ match ]
165
-
165
+
166
166
elsif match = scan ( / ' ( [^\n ']|'' ) (?:'|$) /x )
167
167
tokens << [ :open , :char ]
168
168
tokens << [ "'" , :delimiter ]
169
169
tokens << [ self [ 1 ] , :content ]
170
170
tokens << [ "'" , :delimiter ]
171
171
tokens << [ :close , :char ]
172
172
next
173
-
173
+
174
174
elsif match = scan ( /["']/ )
175
175
tokens << [ :open , :string ]
176
176
state = :string
177
177
plain_string_content = PLAIN_STRING_CONTENT [ match ]
178
178
kind = :delimiter
179
-
179
+
180
180
else
181
181
kind = :plain
182
182
getch
183
183
184
184
end
185
-
186
- elsif state == :string
187
- if scan ( plain_string_content )
188
- kind = :content
189
- elsif scan ( /['"]/ )
190
- tokens << [ matched , :delimiter ]
191
- tokens << [ :close , :string ]
192
- state = :initial
193
- next
194
- elsif scan ( / \\ | $ /x )
195
- tokens << [ :close , :string ]
196
- kind = :error
197
- state = :initial
198
- end
199
185
200
- else
201
- raise_inspect "else case \" reached; %p not handled." % peek ( 1 ) , tokens
186
+ elsif state == :string
187
+ if scan ( plain_string_content )
188
+ kind = :content
189
+ elsif scan ( /['"]/ )
190
+ tokens << [ matched , :delimiter ]
191
+ tokens << [ :close , :string ]
192
+ state = :initial
193
+ next
194
+ elsif scan ( / \\ | $ /x )
195
+ tokens << [ :close , :string ]
196
+ kind = :error
197
+ state = :initial
202
198
end
203
-
199
+
200
+ else
201
+ raise_inspect "else case \" reached; %p not handled." % peek ( 1 ) , tokens
202
+ end
203
+
204
204
match ||= matched
205
205
if $DEBUG and not kind
206
206
raise_inspect 'Error token %p in line %d' %
207
207
[ [ match , kind ] , line ] , tokens
208
208
end
209
209
raise_inspect 'Empty token' , tokens unless match
210
210
tokens << [ match , kind ]
211
-
211
+
212
212
end
213
213
tokens
214
214
end
0 commit comments