JavaScriptFunction.st
author Claus Gittinger <cg@exept.de>
Fri, 21 Feb 2020 20:48:14 +0100
changeset 1231 b7d945ef967a
parent 1155 1cae699994c3
permissions -rw-r--r--
#REFACTORING by exept class: JavaScriptParser changed: #forStatement class: JavaScriptParser class added: #forOfAllowed comment/format in: #forInAllowed

"
 COPYRIGHT (c) 2005 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libjavascript' }"

"{ NameSpace: Smalltalk }"

Method variableSubclass:#JavaScriptFunction
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-JavaScript-Compiling & Parsing'
!

!JavaScriptFunction class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2005 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
! !

!JavaScriptFunction methodsFor:'compiler interface'!

mclass:aClass
    mclass := aClass
!

programmingLanguage
    ^  STXJavaScriptLanguage instance
! !

!JavaScriptFunction methodsFor:'printing & storing'!

selectorPrintStringInBrowserFor:selector
    ^ selector upTo:$:
!

selectorPrintStringInBrowserFor:selector class:aClass
    |nsPart selPart idx ns as|

    selector isNameSpaceSelector ifFalse:[
        idx := selector indexOf:$: startingAt:2.
        idx == 0 ifTrue:[ idx := selector size+1 ].
        as := (1 to:self numArgs collect:[:i | 'a%1' bindWith:i]) asStringWith:', '.
        ^ (selector copyTo:idx-1) allBold,'(',as,')'           
    ].

    idx := selector indexOf:$: startingAt:3.
    selPart := selector copyFrom:idx+2.
    nsPart := selector copyFrom:2 to:idx-1.
    ns := Smalltalk at:nsPart asSymbol.
    ^ selPart allBold,'(',')', ' {',nsPart,'}'.
! !

!JavaScriptFunction methodsFor:'queries'!

methodArgAndVarNames
    "return a collection with the method's argument and variable names.
     Uses Parser to parse the method's source and extract the names.
     Returns an empty collection if the source is not available, or some other
     syntax/parse error occurred.
     For methods with no args and no vars, an empty collection is returned."

    "/ redefined in case a private function was defined before the actual
    "/ selector function.

    |parserClass parser sourceStream sourceString argNames varNames|

    parserClass := self parserClass.
    sourceString := self source.
    (parserClass notNil and:[sourceString notNil]) ifTrue:[
        sourceStream := sourceString readStream.
        [
            parser := parserClass parseMethodArgAndVarSpecificationSilent:sourceStream.
            (parser isNil or:[parser == #Error]) ifTrue:[^ #()].
        ] doUntil:[parser smalltalkSelector == self selector].
        argNames := parser methodArgs.
        varNames := parser methodVars.
        argNames isNil ifTrue:[^ varNames ? #()].
        varNames isNil ifTrue:[^ argNames ? #()].
        ^ (argNames , varNames)
    ].
    ^ #()

    "
     (Method compiledMethodAt:#printOn:) methodArgAndVarNames
    "

    "Modified (comment): / 21-11-2017 / 13:04:33 / cg"
! !

!JavaScriptFunction class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !