Parser.st
changeset 1440 7084ae99ced7
parent 1439 0fddfcdca37b
child 1441 7ebe4e486524
equal deleted inserted replaced
1439:0fddfcdca37b 1440:7084ae99ced7
   932     homeContext := aContext methodHome.
   932     homeContext := aContext methodHome.
   933     sel := homeContext selector.
   933     sel := homeContext selector.
   934     method := homeContext method.
   934     method := homeContext method.
   935 
   935 
   936     "/ #doIt needs special handling below
   936     "/ #doIt needs special handling below
   937     isDoIt := (sel == #doIt) or:[sel == #doIt:].
   937     isDoIt := (sel == #'doIt') or:[sel == #'doIt:'].
   938     aContext isBlockContext ifFalse:[
   938     aContext isBlockContext ifFalse:[
   939         isDoIt ifTrue:[
   939         isDoIt ifTrue:[
   940             method notNil ifTrue:[
   940             method notNil ifTrue:[
   941                 "/ special for #doIt
   941                 "/ special for #doIt
   942                 m := nil.
   942                 m := nil.
  2121             how := how , #( MethodVariable ).
  2121             how := how , #( MethodVariable ).
  2122         ].
  2122         ].
  2123         (classToCompileFor notNil
  2123         (classToCompileFor notNil
  2124         and:[classToCompileFor isMeta not
  2124         and:[classToCompileFor isMeta not
  2125         and:[classToCompileFor isBuiltInClass not 
  2125         and:[classToCompileFor isBuiltInClass not 
  2126         and:[selector notNil and:[selector ~~ #doIt]]]]) ifTrue:[
  2126         and:[(self isDoIt not)]]]) ifTrue:[
  2127             l := l copyWith:'Instance Variable'.
  2127             l := l copyWith:'Instance Variable'.
  2128             how := how copyWith: #InstanceVariable.
  2128             how := how copyWith: #InstanceVariable.
  2129         ].
  2129         ].
  2130     ] ifFalse:[
  2130     ] ifFalse:[
  2131         l := l , #( 'New Class' 'Global' 'NameSpace' ).
  2131         l := l , #( 'New Class' 'Global' 'NameSpace' ).
  2132         how := how , #( NewClass GlobalVariable NameSpace ).
  2132         how := how , #( NewClass GlobalVariable NameSpace ).
  2133 
  2133 
  2134         (classToCompileFor notNil
  2134         (classToCompileFor notNil
  2135         and:[classToCompileFor isBuiltInClass not
  2135         and:[classToCompileFor isBuiltInClass not
  2136         and:[selector notNil and:[selector ~~ #doIt]]]) ifTrue:[
  2136         and:[self isDoIt not]]) ifTrue:[
  2137             classToCompileFor isMeta ifTrue:[
  2137             classToCompileFor isMeta ifTrue:[
  2138                 l := l , #('Class Instance Variable').
  2138                 l := l , #('Class Instance Variable').
  2139                 how := how , #( ClassInstanceVariable).
  2139                 how := how , #( ClassInstanceVariable).
  2140             ].
  2140             ].
  2141             l := l , #('Class Variable' ).
  2141             l := l , #('Class Variable' ).
  2142             how := how , #( ClassVariable).
  2142             how := how , #( ClassVariable).
  2143         ]
  2143         ]
  2144     ].
  2144     ].
  2145     (selector isNil or:[selector == #doIt]) ifTrue:[
  2145     self isDoIt ifTrue:[
  2146         l size > 0 ifTrue:[
  2146         l size > 0 ifTrue:[
  2147             l := l ,  #( '-' ).
  2147             l := l ,  #( '-' ).
  2148             how := how , #( nil ).
  2148             how := how , #( nil ).
  2149         ].
  2149         ].
  2150         l := l , #( 'Workspace Variable' 'DoIt Temporary').
  2150         l := l , #( 'Workspace Variable' 'DoIt Temporary').
  2881 selectorCheck:aSelectorString for:receiver positions:posVector
  2881 selectorCheck:aSelectorString for:receiver positions:posVector
  2882     "just a quick check: if a selector is totally unknown as a symbol, 
  2882     "just a quick check: if a selector is totally unknown as a symbol, 
  2883      has the same name as a variable, cannot be understood or is obsolete.
  2883      has the same name as a variable, cannot be understood or is obsolete.
  2884      Simple, but catches many typos"
  2884      Simple, but catches many typos"
  2885 
  2885 
  2886     |err sym rec names recType selClass newSelector nm nowhereImplemented pos1 pos2|
  2886     |err sym rec names recType selClass newSelector nm nowhereImplemented pos1 pos2 canDefine|
       
  2887 
       
  2888     canDefine := false.
  2887 
  2889 
  2888     pos1 := posVector first start.
  2890     pos1 := posVector first start.
  2889     pos2 := posVector last stop.
  2891     pos2 := posVector last stop.
  2890 
  2892 
  2891     "
  2893     "
  2986                     ].   
  2988                     ].   
  2987                     subErr notNil ifTrue:[
  2989                     subErr notNil ifTrue:[
  2988                         err := subErr, ' in this class, superclass chain or all subclasses'
  2990                         err := subErr, ' in this class, superclass chain or all subclasses'
  2989                     ] ifFalse:[
  2991                     ] ifFalse:[
  2990                         err := err, ' in this class or superclass chain'.
  2992                         err := err, ' in this class or superclass chain'.
  2991                     ].    
  2993                     ].
       
  2994                     canDefine := true.
  2992                 ].
  2995                 ].
  2993             ] ifFalse:[(receiver isUnaryMessage
  2996             ] ifFalse:[(receiver isUnaryMessage
  2994                         and:[receiver selector == #class
  2997                         and:[receiver selector == #class
  2995                         and:[receiver receiver isSelf]]) ifTrue:[
  2998                         and:[receiver receiver isSelf]]) ifTrue:[
  2996                 "its a message to self class - can check this too ..."
  2999                 "its a message to self class - can check this too ..."
  3069         self isSyntaxHighlighter ifTrue:[
  3072         self isSyntaxHighlighter ifTrue:[
  3070             posVector do:[:p |
  3073             posVector do:[:p |
  3071                 self markUnknownIdentifierFrom:(p start) to:(p stop).
  3074                 self markUnknownIdentifierFrom:(p start) to:(p stop).
  3072             ].
  3075             ].
  3073         ].
  3076         ].
  3074         err := err , '\\This is a warning from the compiler - the code has not yet been executed/compiled'.
  3077         err := err , '\\This is a warning from the compiler - the code has not yet been executed/compiled.'.
  3075         newSelector := self correctSelector:aSelectorString 
  3078         newSelector := self correctSelector:aSelectorString 
  3076                             message:err withCRs positions:posVector in:selClass for:receiver.
  3079                             message:err withCRs positions:posVector in:selClass for:receiver.
  3077 "/        self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2.
  3080 "/        self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2.
  3078         ^ newSelector.
  3081         ^ newSelector.
  3079     ].
  3082     ].
  3528                     method checked:true.
  3531                     method checked:true.
  3529 
  3532 
  3530                     value := method 
  3533                     value := method 
  3531                                 valueWithReceiver:anObject 
  3534                                 valueWithReceiver:anObject 
  3532                                 arguments:nil  "/ (Array with:m) 
  3535                                 arguments:nil  "/ (Array with:m) 
  3533                                 selector:(requestor isNil ifTrue:#doItX ifFalse:#doIt) "/ #doIt: 
  3536                                 selector:(requestor isNil ifTrue:#'doItX' ifFalse:#'doIt') "/ #doIt: 
  3534                                 search:nil
  3537                                 search:nil
  3535                                 sender:nil.
  3538                                 sender:nil.
  3536                 ] ifFalse:[
  3539                 ] ifFalse:[
  3537                     self evalExitBlock:[:value | self release. ^ value].
  3540                     self evalExitBlock:[:value | self release. ^ value].
  3538                     value := tree evaluate.
  3541                     value := tree evaluate.
  5522     pos1 := tokenPosition.
  5525     pos1 := tokenPosition.
  5523     pos2 := tokenPosition + tokenName size - 1.
  5526     pos2 := tokenPosition + tokenName size - 1.
  5524 
  5527 
  5525     varName := tokenName.
  5528     varName := tokenName.
  5526 
  5529 
  5527     ((selector isNil or:[selector == #doIt]) 
  5530     (self isDoIt 
  5528     and:[currentBlock isNil
  5531     and:[currentBlock isNil
  5529     and:[(requestor askFor:#isWorkspace)
  5532     and:[(requestor askFor:#isWorkspace)
  5530     and:[(autoHow := requestor autoDefineVariables) notNil]]]) ifTrue:[
  5533     and:[(autoHow := requestor autoDefineVariables) notNil]]]) ifTrue:[
  5531         var := self variableOrError:varName.
  5534         var := self variableOrError:varName.
  5532         self nextToken.
  5535         self nextToken.
  6343     (requestor notNil and:[requestor isStream not]) ifTrue:[
  6346     (requestor notNil and:[requestor isStream not]) ifTrue:[
  6344         "/ when parsing doits, this is done twice;
  6347         "/ when parsing doits, this is done twice;
  6345         "/ first, for the parse, then as a block-code
  6348         "/ first, for the parse, then as a block-code
  6346         "/ for the code.
  6349         "/ for the code.
  6347         "/ We only care for WorkspaceVars in doIts
  6350         "/ We only care for WorkspaceVars in doIts
  6348         (selector isNil or:[selector == #doIt]) ifTrue:[
  6351         (self isDoIt) ifTrue:[
  6349             (Workspace notNil 
  6352             (Workspace notNil 
  6350             and:[(holder := Workspace workspaceVariableAt:varName) notNil])
  6353             and:[(holder := Workspace workspaceVariableAt:varName) notNil])
  6351             ifTrue:[
  6354             ifTrue:[
  6352                 ^ VariableNode type:#WorkspaceVariable holder:holder name:varName
  6355                 ^ VariableNode type:#WorkspaceVariable holder:holder name:varName
  6353             ]
  6356             ]
  6359         "/ when parsing doits, this is done twice;
  6362         "/ when parsing doits, this is done twice;
  6360         "/ first, for the parse, then as a block-code
  6363         "/ first, for the parse, then as a block-code
  6361         "/ for the code.
  6364         "/ for the code.
  6362         "/ We only care for WorkspaceVars in doIts
  6365         "/ We only care for WorkspaceVars in doIts
  6363 
  6366 
  6364         (selector isNil or:[selector == #doIt]) ifTrue:[
  6367         (self isDoIt) ifTrue:[
  6365             (doItTemporaries notNil 
  6368             (doItTemporaries notNil 
  6366             and:[(holder := doItTemporaries at:varName asSymbol ifAbsent:nil) notNil]) 
  6369             and:[(holder := doItTemporaries at:varName asSymbol ifAbsent:nil) notNil]) 
  6367             ifTrue:[
  6370             ifTrue:[
  6368                 ^ VariableNode type:#DoItTemporary holder:holder name:varName
  6371                 ^ VariableNode type:#DoItTemporary holder:holder name:varName
  6369             ]
  6372             ]
  7020     "return true if there was any ST/X style primitive code (valid after parsing)"
  7023     "return true if there was any ST/X style primitive code (valid after parsing)"
  7021 
  7024 
  7022     ^ hasPrimitiveCode
  7025     ^ hasPrimitiveCode
  7023 !
  7026 !
  7024 
  7027 
       
  7028 isDoIt
       
  7029     ^ (selector isNil or:[selector == #'doIt' or:[selector == #'doIt:']])
       
  7030 !
       
  7031 
  7025 isSyntaxHighlighter
  7032 isSyntaxHighlighter
  7026     ^ false
  7033     ^ false
  7027 !
  7034 !
  7028 
  7035 
  7029 lineNumberInfo
  7036 lineNumberInfo
  7433 ! !
  7440 ! !
  7434 
  7441 
  7435 !Parser class methodsFor:'documentation'!
  7442 !Parser class methodsFor:'documentation'!
  7436 
  7443 
  7437 version
  7444 version
  7438     ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.400 2003-07-02 10:48:09 cg Exp $'
  7445     ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.401 2003-07-14 07:42:45 cg Exp $'
  7439 ! !
  7446 ! !
  7440 
  7447 
  7441 Parser initialize!
  7448 Parser initialize!