--- a/Parser.st Mon Feb 02 17:15:46 2015 +0100
+++ b/Parser.st Mon Feb 02 17:16:46 2015 +0100
@@ -121,6 +121,13 @@
privateIn:Parser
!
+Object subclass:#ParsedAnnotation
+ instanceVariableNames:'key arguments startPostion endPosition'
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:Parser
+!
+
Query subclass:#PossibleCorrectionsQuery
instanceVariableNames:'parser message'
classVariableNames:''
@@ -8827,6 +8834,14 @@
!Parser methodsFor:'parsing-primitives & pragmas'!
+addAnnotationWithKey:key andArguments:arguments
+ |annot|
+
+ "/ was: annot := { key . arguments}.
+ annot := ParsedAnnotation key:key arguments:arguments.
+ annotations := annotations copyWith:annot.
+!
+
checkForClosingAngle
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifTrue:[
self nextToken.
@@ -9008,7 +9023,7 @@
].
].
- annotations := annotations copyWith:{ pragmaType asSymbol . { tokenValue }}.
+ self addAnnotationWithKey:pragmaType asSymbol andArguments:{ tokenValue }.
self nextToken.
"Modified: / 19-11-2009 / 11:10:04 / Jan Travnicek <travnja3@fel.cvut.cz>"
@@ -9050,8 +9065,7 @@
cStream := cString readStream.
(#( 'apicall:' 'cdecl:' 'stdcall:' 'virtual' ) includes:callType) ifTrue:[
"/ squeak/dolphin/stx external function definition
- annotations := annotations
- copyWith:(Array with:callType asSymbol with:cString).
+ self addAnnotationWithKey:callType asSymbol andArguments:cString.
self
parseSTXOrSqueakOrDolphinExternalFunctionDeclarationFrom:cStream
definitionType:callType
@@ -9061,8 +9075,7 @@
].
callType = 'c:' ifTrue:[
"/ VW external function definition
- annotations := annotations
- copyWith:(Array with:callType asSymbol with:cString).
+ self addAnnotationWithKey:callType asSymbol andArguments:cString.
self
parseVWTypeOrExternalFunctionDeclarationFrom:cStream
definitionType:callType
@@ -9072,8 +9085,7 @@
].
(callType = 'api:' or:[ callType = 'ole:' ]) ifTrue:[
"/ ST/V external function definition
- annotations := annotations
- copyWith:(Array with:callType asSymbol with:cString).
+ self addAnnotationWithKey:callType asSymbol andArguments:cString.
self
parseSTVExternalFunctionDeclarationFrom:cStream
definitionType:callType
@@ -9081,8 +9093,7 @@
lineNr:lineNr.
^ -1
].
- self
- ignorableParseError:'unsupported external function call type: ' , callType.
+ self ignorableParseError:'unsupported external function call type: ' , callType.
^ -1
"
@@ -9119,7 +9130,7 @@
value := true.
self nextToken.
((tokenType == #BinaryOperator) and:[ tokenName = '>' ]) ifTrue:[
- annotations := annotations copyWith:(Array with:key asSymbol with:value).
+ self addAnnotationWithKey:key asSymbol andArguments:value.
self nextToken.
^ nil.
].
@@ -9128,8 +9139,7 @@
^ #Error.
].
((tokenType == #BinaryOperator) and:[ tokenName = '>' ]) ifTrue:[
- annotations := annotations
- copyWith:(Array with:key asSymbol with:(Array with:value)).
+ self addAnnotationWithKey:key asSymbol andArguments:{ value }.
self nextToken.
^ nil.
].
@@ -9146,8 +9156,7 @@
].
values add:value.
].
- annotations := annotations
- copyWith:(Array with:key asSymbol with:(values asArray)).
+ self addAnnotationWithKey:key asSymbol andArguments:values asArray.
"JV@2012-04-09: Check for GNU Smalltalk-style external function declaration"
key = #'cCall:returning:args:' ifTrue:[
@@ -9258,20 +9267,20 @@
].
(tokenName = 'primitive:') ifTrue:[
tmp := self parseTraditionalPrimitive.
- annotations := annotations copyWith:(Array with:'primitive:' asSymbol with:tmp).
+ self addAnnotationWithKey:#'primitive:' andArguments:tmp.
^ tmp.
].
(tokenName = 'sysprim:') ifTrue:[
parserFlags allowVisualAgePrimitives ifTrue:[
tmp := self parseTraditionalPrimitive.
- annotations := annotations copyWith:(Array with:'sysprim:' asSymbol with:tmp).
+ self addAnnotationWithKey:#'sysprim:' andArguments:tmp.
^ tmp.
].
].
(tokenName = 'primitive') ifTrue:[
self nextToken.
self checkForClosingAngle.
- annotations := annotations copyWith:(Array with:'primitive' asSymbol with:0).
+ self addAnnotationWithKey:#'primitive' andArguments:0.
^ 0
"/ no primitive number
.
@@ -9390,12 +9399,9 @@
primitiveResource at:(resource asSymbol) put:resourceValue.
self checkForClosingAngle.
(resourceValue isBoolean and:[ resourceValue ]) ifTrue:[
- annotations := annotations
- copyWith:(Array with:#resource: asSymbol with:(Array with:resource)).
+ self addAnnotationWithKey:#'resource:' andArguments:{ resource }.
] ifFalse:[
- annotations := annotations
- copyWith:(Array with:#resource:values: asSymbol
- with:(Array with:resource with:resourceValue)).
+ self addAnnotationWithKey:#'resource:values:' andArguments:{resource . resourceValue}.
]
"Modified: / 19-11-2009 / 11:11:26 / Jan Travnicek <travnja3@fel.cvut.cz>"
@@ -10060,13 +10066,22 @@
!Parser methodsFor:'queries'!
-annotations
- "return the annotations - if any (valid after parsing)"
+annotationInfo
+ "return the annotations - if any - in a format usable for source analysis
+ (i.e. with start and stop positions)
+ valid only after parsing"
^ annotations
-
- "Created: / 03-11-2009 / 17:09:45 / Jan Travnicek <travnja3@fel.cvut.cz>"
- "Modified: / 15-12-2009 / 14:07:24 / Jan Travnicek <travnja3@fel.cvut.cz>"
+!
+
+annotations
+ "return the annotations - if any - in the format stored in a method
+ (i.e. as an array or 2-element key-argument arrays).
+ valid only after parsing"
+
+ annotations isNil ifTrue:[^ nil].
+ "/ present them in the old format (arrays)
+ ^ annotations collect:[:each | Array with:each key with:each arguments ].
!
classToLookForClassVars
@@ -11507,6 +11522,76 @@
^ aCompiler requestor currentSourceCode.
! !
+!Parser::ParsedAnnotation class methodsFor:'instance creation'!
+
+key:key arguments:arguments
+ ^ self new key:key arguments:arguments
+! !
+
+!Parser::ParsedAnnotation methodsFor:'accessing'!
+
+arguments
+ ^ arguments
+!
+
+arguments:something
+ arguments := something.
+!
+
+endPosition
+ ^ endPosition
+!
+
+endPosition:something
+ endPosition := something.
+!
+
+key
+ ^ key
+!
+
+key:something
+ key := something.
+!
+
+key:keyArg arguments:argumentsArg
+ key := keyArg.
+ arguments := argumentsArg.
+!
+
+startPostion
+ ^ startPostion
+!
+
+startPostion:something
+ startPostion := something.
+!
+
+startPostion:startPostionArg endPosition:endPositionArg
+ startPostion := startPostionArg.
+ endPosition := endPositionArg.
+! !
+
+!Parser::ParsedAnnotation methodsFor:'backward compatibility'!
+
+at:index
+ "in older parser, annotations where kept as little 2-element arrays,
+ holding the key at slot 1 and the arguments at slot 2.
+ For backward compatibility, still provide this interface,
+ but spit out a warning on the transcript.
+ Users should rewrite their code."
+
+ index == 1 ifTrue:[
+ Transcript showCR:'Parser: old style use of parsed annotations. Please rewrite to use #key'.
+ ^ key.
+ ].
+ index == 2 ifTrue:[
+ Transcript showCR:'Parser: old style use of parsed annotations. Please rewrite to use #arguments'.
+ ^ arguments.
+ ].
+ self error:'invalid index.'.
+! !
+
!Parser::PossibleCorrectionsQuery class methodsFor:'documentation'!
documentation
@@ -12090,11 +12175,11 @@
!Parser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.857 2015-02-02 15:15:52 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.858 2015-02-02 16:16:46 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.857 2015-02-02 15:15:52 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.858 2015-02-02 16:16:46 cg Exp $'
!
version_SVN