author | sr |
Wed, 14 Sep 2011 11:25:43 +0200 | |
changeset 13693 | 16c890248840 |
parent 13425 | 352177aa4eb1 |
child 13819 | 095f081028fc |
permissions | -rw-r--r-- |
13425 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
11964 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
Object subclass:#ProgrammingLanguage |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'LanguageQuerySignal' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Languages' |
|
19 |
! |
|
20 |
||
21 |
ProgrammingLanguage class instanceVariableNames:'Instance' |
|
22 |
||
23 |
" |
|
24 |
No other class instance variables are inherited by this class. |
|
25 |
" |
|
26 |
! |
|
27 |
||
12101 | 28 |
!ProgrammingLanguage class methodsFor:'documentation'! |
29 |
||
13425 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
12101 | 44 |
documentation |
45 |
" |
|
46 |
provide info about which tools are to be used for code in |
|
47 |
a programming language |
|
48 |
" |
|
49 |
! ! |
|
11964 | 50 |
|
51 |
!ProgrammingLanguage class methodsFor:'initialization'! |
|
52 |
||
53 |
initialize |
|
54 |
||
55 |
LanguageQuerySignal := |
|
56 |
QuerySignal new |
|
57 |
nameClass:self message:#languageQuerySignal; |
|
58 |
notifierString:'asking for current language'; |
|
59 |
handlerBlock:[:ex | ex proceedWith:SmalltalkLanguage instance]. |
|
60 |
||
61 |
"Created: / 12-08-2009 / 14:56:11 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
62 |
"Modified: / 16-08-2009 / 10:36:11 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
63 |
! ! |
|
64 |
||
65 |
!ProgrammingLanguage class methodsFor:'instance creation'! |
|
66 |
||
67 |
forFile: aFilename |
|
12099 | 68 |
"Answers a language for given source file. If none is found, |
11964 | 69 |
SmalltalkLanguage is returned (to provide backward compatibility)" |
70 |
||
71 |
^ self instancesDetect: [:each | each canReadSourceFile: aFilename ] |
|
72 |
ifNone: [ SmalltalkLanguage instance ] |
|
73 |
||
74 |
"Created: / 16-08-2009 / 10:08:44 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
75 |
! |
|
76 |
||
77 |
forStream: aStream |
|
12099 | 78 |
"Answers a language for given source stream. If none is found, |
11964 | 79 |
SmalltalkLanguage is returned (to provide backward compatibility)" |
80 |
||
81 |
aStream isFileStream ifFalse: [ ^ SmalltalkLanguage instance ]. |
|
82 |
^ self forFile: aStream fileName |
|
83 |
||
84 |
"Created: / 16-08-2009 / 10:56:26 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
85 |
! |
|
86 |
||
87 |
named: aString |
|
12990 | 88 |
^ self named:aString ifNone:[ self error: 'No language named ' , aString ]. |
11964 | 89 |
|
90 |
" |
|
12989 | 91 |
ProgrammingLanguage named: 'Smalltalk' |
92 |
ProgrammingLanguage named: 'JavaScript' |
|
93 |
ProgrammingLanguage named: 'Ruby' |
|
94 |
" |
|
11964 | 95 |
|
96 |
"Created: / 15-08-2009 / 22:40:26 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
97 |
"Modified: / 16-08-2009 / 10:58:01 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
12990 | 98 |
"Modified: / 04-08-2010 / 12:06:38 / cg" |
11964 | 99 |
! |
100 |
||
101 |
named: aString ifNone: aBlock |
|
102 |
^ self |
|
103 |
instancesDetect:[:each | each name = aString ] |
|
104 |
ifNone: aBlock |
|
105 |
||
106 |
"Created: / 21-08-2009 / 13:07:10 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
107 |
! ! |
|
108 |
||
109 |
!ProgrammingLanguage class methodsFor:'Signal constants'! |
|
110 |
||
111 |
languageQuerySignal |
|
112 |
||
113 |
^LanguageQuerySignal |
|
114 |
||
115 |
"Created: / 12-08-2009 / 14:57:07 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
116 |
! ! |
|
117 |
||
118 |
!ProgrammingLanguage class methodsFor:'accessing'! |
|
119 |
||
120 |
all |
|
121 |
" |
|
122 |
Anwers a collection of all available languages |
|
123 |
" |
|
124 |
||
125 |
^self allSubclasses collect:[:each|each instance] |
|
126 |
||
127 |
||
128 |
" |
|
12099 | 129 |
ProgrammingLanguage all |
11964 | 130 |
" |
131 |
||
132 |
"Created: / 16-08-2009 / 13:43:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
133 |
! |
|
134 |
||
135 |
current |
|
136 |
||
137 |
" |
|
12099 | 138 |
ProgrammingLanguage current |
11964 | 139 |
" |
140 |
||
141 |
||
142 |
^LanguageQuerySignal query |
|
143 |
||
144 |
"Created: / 12-08-2009 / 15:02:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
145 |
! |
|
146 |
||
147 |
instance |
|
12099 | 148 |
"return this languages singleton" |
11964 | 149 |
|
150 |
Instance ifNil:[Instance := self new]. |
|
151 |
^Instance |
|
152 |
||
153 |
"Created: / 16-08-2009 / 10:36:37 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
154 |
! ! |
|
155 |
||
156 |
!ProgrammingLanguage class methodsFor:'enumerating'! |
|
157 |
||
12590 | 158 |
allDetect:aBlock ifNone:exceptionValue |
159 |
self allDo:[:each | (aBlock value:each) ifTrue:[^ each]]. |
|
160 |
^ exceptionValue value |
|
161 |
! |
|
11964 | 162 |
|
12590 | 163 |
allDo: aBlock |
164 |
^ self allSubclassesDo: [:each | aBlock value: each instance] |
|
11964 | 165 |
|
166 |
"Created: / 16-08-2009 / 14:07:40 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
167 |
! ! |
|
168 |
||
169 |
!ProgrammingLanguage class methodsFor:'private'! |
|
170 |
||
171 |
instancesDetect: detectBlock ifNone: failBlock |
|
172 |
||
173 |
||
174 |
self allSubclasses |
|
175 |
do:[:cls|(detectBlock value: cls instance) ifTrue:[^cls instance]]. |
|
176 |
^failBlock value |
|
177 |
||
178 |
"Created: / 16-08-2009 / 10:57:32 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
179 |
! ! |
|
180 |
||
181 |
!ProgrammingLanguage class methodsFor:'testing'! |
|
182 |
||
183 |
isAvailable: langName |
|
184 |
||
185 |
self instancesDetect: [:lang|lang name = langName] ifNone: [^false]. |
|
186 |
^true |
|
187 |
||
188 |
" |
|
189 |
ProgrammingLanguage isAvailable: 'Smalltalk' |
|
190 |
ProgrammingLanguage isAvailable: 'Ruby' |
|
191 |
ProgrammingLanguage isAvailable: 'Haskell' |
|
192 |
" |
|
193 |
||
194 |
"Created: / 21-08-2009 / 12:56:32 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
195 |
! ! |
|
196 |
||
197 |
!ProgrammingLanguage methodsFor:'accessing'! |
|
198 |
||
13425 | 199 |
id |
200 |
||
201 |
"Return an unique integer id of this language. |
|
202 |
id must be < 32. |
|
203 |
This id is used as index to various structures used by runtime" |
|
204 |
||
205 |
^self subclassResponsibility |
|
206 |
||
207 |
"Created: / 17-03-2011 / 10:51:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
208 |
! |
|
209 |
||
210 |
imports |
|
211 |
||
212 |
"To make it polymorph with NameSpace for |
|
213 |
selector-namespace enabled systems" |
|
214 |
||
215 |
^self class all reject:[:lang|lang == self] |
|
216 |
||
217 |
"Created: / 20-05-2010 / 14:17:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
218 |
"Modified: / 19-07-2010 / 12:14:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
219 |
! |
|
220 |
||
221 |
lookup |
|
222 |
||
223 |
^self lookupClass instance |
|
224 |
||
225 |
"Created: / 17-03-2011 / 10:57:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
226 |
! |
|
227 |
||
11964 | 228 |
name |
12099 | 229 |
"Answers a human-readable name of myself: |
11964 | 230 |
'Smalltalk' for SmalltalkLanguage, |
12099 | 231 |
'Ruby' for RubyLanguage |
232 |
... |
|
11964 | 233 |
" |
234 |
||
235 |
^ self subclassResponsibility |
|
236 |
||
237 |
"Created: / 15-08-2009 / 22:38:16 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
238 |
"Modified: / 16-08-2009 / 10:47:21 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
239 |
! |
|
240 |
||
241 |
sourceFileSuffix |
|
12099 | 242 |
"Answers a default suffix for source files, i.e. 'st' for Smalltalk, |
243 |
'js' for JavaScript or 'rb' for Ruby', etc." |
|
11964 | 244 |
|
245 |
^self subclassResponsibility |
|
246 |
||
247 |
"Created: / 16-08-2009 / 10:42:40 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
248 |
! ! |
|
249 |
||
250 |
!ProgrammingLanguage methodsFor:'accessing - classes'! |
|
251 |
||
13250 | 252 |
codeGeneratorClass |
253 |
"Answer a class suitable for generating code (such as getters, setters, etc.) |
|
254 |
It is ok to return nil, which means that no code can be generated automagically" |
|
255 |
||
256 |
^ nil |
|
257 |
! |
|
258 |
||
11964 | 259 |
compilerClass |
12099 | 260 |
"Answer a class suitable for compiling a source code in 'my' language" |
11964 | 261 |
|
262 |
^self subclassResponsibility |
|
263 |
||
264 |
"Created: / 21-08-2009 / 13:00:50 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
265 |
! |
|
266 |
||
12099 | 267 |
evaluatorClass |
268 |
"Answer a class suitable for evaluating a doIt in 'my' language" |
|
269 |
||
270 |
^ self compilerClass |
|
271 |
! |
|
11964 | 272 |
|
12099 | 273 |
explainerClass |
274 |
"Answers a class used by browser and debugger to |
|
275 |
show some hints about the code. It is OK to return |
|
276 |
nil, which means that there is no explainer for given |
|
277 |
language." |
|
11964 | 278 |
|
279 |
"return nil by default" |
|
280 |
^nil |
|
281 |
||
282 |
"Created: / 21-08-2009 / 08:49:13 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
283 |
! |
|
284 |
||
12099 | 285 |
formatterClass |
286 |
"Answer a class suitable for prettyPrinting (indenting) code in 'my' language. |
|
287 |
It is ok to return nil, which means that the browser will not be able to prettyprint." |
|
288 |
||
289 |
^ nil |
|
290 |
! |
|
291 |
||
13425 | 292 |
lookupClass |
293 |
||
294 |
^BuiltinLookup |
|
295 |
||
296 |
"Created: / 17-03-2011 / 10:56:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
297 |
! |
|
298 |
||
13256 | 299 |
metaClass |
300 |
"will be used for new classes (in the class wizard); |
|
301 |
a fallback here" |
|
302 |
||
303 |
^ Metaclass |
|
304 |
||
305 |
"Created: / 30-01-2011 / 10:05:03 / cg" |
|
306 |
! |
|
307 |
||
11964 | 308 |
parserClass |
12099 | 309 |
"Answer a class suitable for parsing a source code in 'my' language" |
11964 | 310 |
|
311 |
^self subclassResponsibility |
|
312 |
||
313 |
"Created: / 21-08-2009 / 13:00:30 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
314 |
! |
|
315 |
||
316 |
sourceFileReaderClass |
|
12099 | 317 |
"Answers a class that can be used for reading & compiling source files" |
11964 | 318 |
|
319 |
^self subclassResponsibility |
|
320 |
||
321 |
"Created: / 16-08-2009 / 09:00:23 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
322 |
! |
|
323 |
||
324 |
sourceFileWriterClass |
|
12099 | 325 |
"Answers a class is used for source file writing (i.e. file-out)" |
11964 | 326 |
|
327 |
^self subclassResponsibility |
|
328 |
||
329 |
"Created: / 16-08-2009 / 09:40:19 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
12099 | 330 |
! |
331 |
||
332 |
syntaxHighlighterClass |
|
333 |
"Answers a class used by browser and debugger to colorze code. |
|
334 |
It is OK to return nil, which means that the code is shown as-is" |
|
335 |
||
336 |
"return nil by default" |
|
337 |
^nil |
|
11964 | 338 |
! ! |
339 |
||
340 |
!ProgrammingLanguage methodsFor:'printing & storing'! |
|
341 |
||
13425 | 342 |
printOn:aStream |
343 |
"append a printed representation if the receiver to the argument, aStream" |
|
344 |
||
345 |
self class printOn: aStream. |
|
346 |
aStream nextPutAll: ' instance' |
|
347 |
||
348 |
"Modified: / 19-06-2010 / 09:54:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
349 |
! |
|
350 |
||
11964 | 351 |
storeOn:aStream |
352 |
||
353 |
self class == ProgrammingLanguage |
|
354 |
ifTrue: |
|
355 |
[super storeOn:aStream] |
|
356 |
ifFalse: |
|
357 |
[aStream |
|
358 |
nextPutAll:'ProgrammingLanguage'; |
|
359 |
nextPutAll:' named: '; |
|
360 |
nextPutAll:self name storeString]. |
|
361 |
||
362 |
" |
|
363 |
ProgrammingLanguage instance storeString |
|
364 |
||
365 |
SmalltalkLanguage instance storeString |
|
366 |
" |
|
367 |
||
368 |
"Created: / 16-08-2009 / 10:52:28 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
369 |
! ! |
|
370 |
||
371 |
!ProgrammingLanguage methodsFor:'queries'! |
|
372 |
||
373 |
canReadSourceFile: aFilename |
|
12099 | 374 |
"Answers true iff file contains source code in 'my' language" |
11964 | 375 |
|
12099 | 376 |
"Trivial implementation here, to be overriden by subclasses" |
11964 | 377 |
|
378 |
^aFilename suffix = self sourceFileSuffix |
|
379 |
||
380 |
"Created: / 16-08-2009 / 10:10:33 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
13425 | 381 |
! |
382 |
||
383 |
supportsExtensionMethods |
|
384 |
||
385 |
"Answer true iff this language supports extension methods" |
|
386 |
||
387 |
^true |
|
388 |
||
389 |
"Created: / 19-03-2011 / 10:02:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11964 | 390 |
! ! |
391 |
||
392 |
!ProgrammingLanguage methodsFor:'testing'! |
|
393 |
||
13425 | 394 |
isJava |
395 |
"true iff this is the Java language" |
|
396 |
||
397 |
^ false |
|
398 |
||
399 |
"Created: / 17-03-2011 / 10:16:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
400 |
! |
|
401 |
||
402 |
isProgrammingLanguage |
|
403 |
||
404 |
^true |
|
405 |
||
406 |
"Created: / 21-07-2010 / 15:14:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
407 |
! |
|
408 |
||
12151
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
409 |
isRuby |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
410 |
"true iff this is the ruby language" |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
411 |
|
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
412 |
^ false |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
413 |
! |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
414 |
|
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
415 |
isSTXJavaScript |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
416 |
"true iff this is the ST/X-javascript language" |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
417 |
|
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
418 |
^ false |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
419 |
! |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
420 |
|
11964 | 421 |
isSmalltalk |
12106 | 422 |
"true iff this is the smalltalk language" |
11964 | 423 |
|
12106 | 424 |
^ false |
11964 | 425 |
|
426 |
"Created: / 16-08-2009 / 09:01:27 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
427 |
! ! |
|
428 |
||
429 |
!ProgrammingLanguage methodsFor:'utilities - file in/file out'! |
|
430 |
||
431 |
fileIn: aFilename |
|
432 |
||
433 |
^self sourceFileReaderClass fileIn: aFilename |
|
434 |
||
435 |
"Created: / 16-08-2009 / 13:28:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
436 |
! |
|
437 |
||
438 |
fileInStream: aStream |
|
439 |
||
440 |
^self sourceFileReaderClass fileInStream: aStream |
|
441 |
||
442 |
"Created: / 16-08-2009 / 11:05:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
443 |
! ! |
|
444 |
||
445 |
!ProgrammingLanguage methodsFor:'utilities - source code'! |
|
446 |
||
12151
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
447 |
methodTemplate |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
448 |
"return a method definition template string (or nil)" |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
449 |
|
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
450 |
^ nil |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
451 |
! |
6f4f339cfa56
more stuff via programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12106
diff
changeset
|
452 |
|
12106 | 453 |
writeComment:aStringOrStringCollection on:aStream |
12099 | 454 |
"Utility method - writes a comment to a stream, |
455 |
using proper syntax" |
|
11964 | 456 |
|
12099 | 457 |
^ self sourceFileWriterClass new |
458 |
fileOutComment: aStringOrStringCollection |
|
11964 | 459 |
on: aStream |
460 |
||
461 |
"Created: / 21-08-2009 / 09:35:07 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
462 |
! ! |
|
463 |
||
464 |
!ProgrammingLanguage class methodsFor:'documentation'! |
|
465 |
||
12048 | 466 |
version_CVS |
13425 | 467 |
^ '$Header: /cvs/stx/stx/libbasic/ProgrammingLanguage.st,v 1.15 2011-06-28 18:17:38 vrany Exp $' |
12048 | 468 |
! |
469 |
||
470 |
version_SVN |
|
13425 | 471 |
^ ' Id: ProgrammingLanguage.st 10643 2011-06-08 21:53:07Z vranyj1 ' |
11964 | 472 |
! ! |
473 |
||
474 |
ProgrammingLanguage initialize! |