modifying the compiler adding an alias for :=

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

modifying the compiler adding an alias for :=

Erik Itter
Hi,

I need to modify the compiler adding ":>" as an alias for ":=" for
assignment. I have been reading all over the Compiler package but do not
find where a tokenizer parses for the assignement operator or where it
is defined.

Any hint where to start or do it is appreciated.

best regards
Erik

Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

Thierry Goubier
Hi,

If you are using the OpalCompiler (Pharo4, sure, Pharo3, I'm not so sure), have a look at:

RBScanner>>scanSpecialCharacter

Thierry

2014-12-10 12:57 GMT+01:00 Erik Itter <[hidden email]>:
Hi,

I need to modify the compiler adding ":>" as an alias for ":=" for assignment. I have been reading all over the Compiler package but do not find where a tokenizer parses for the assignement operator or where it is defined.

Any hint where to start or do it is appreciated.

best regards
Erik


Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

Erik Itter
Thanks, tried

scanSpecialCharacter
    | character |
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $=
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $>
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $_ ifTrue: [
        self step. 
        ^ RBShortAssignmentToken start: tokenStart ].
   
    character := currentCharacter.
    self step.
    ^ RBSpecialCharacterToken value: character start: tokenStart

but while it does not seem to shred my image to pieces it also seems to have no effect at all. I guess the UI components still check differently and neither workplace nor SystemBrowser allow me to write code using the :> operator

Am 10.12.2014 um 13:11 schrieb Thierry Goubier:
Hi,

If you are using the OpalCompiler (Pharo4, sure, Pharo3, I'm not so sure), have a look at:

RBScanner>>scanSpecialCharacter

Thierry

2014-12-10 12:57 GMT+01:00 Erik Itter <[hidden email]>:
Hi,

I need to modify the compiler adding ":>" as an alias for ":=" for assignment. I have been reading all over the Compiler package but do not find where a tokenizer parses for the assignement operator or where it is defined.

Any hint where to start or do it is appreciated.

best regards
Erik



Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

Thierry Goubier
Hi Erik,

You need to make sure you are using the right compiler. In a Pharo3 image, you'll find two compilers: Opal and the old one.

In the old one, you need to change:

Scanner>>xColon

In RB/Opal, what you can try with your changes is to inspect:

RBParser parseExpression: 'a :> 5'

And, if you get a RBAssignmentNode, then it is working.

Thierry

2014-12-10 13:32 GMT+01:00 Erik Itter <[hidden email]>:
Thanks, tried

scanSpecialCharacter
    | character |
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $=
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $>
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $_ ifTrue: [
        self step. 
        ^ RBShortAssignmentToken start: tokenStart ].
   
    character := currentCharacter.
    self step.
    ^ RBSpecialCharacterToken value: character start: tokenStart

but while it does not seem to shred my image to pieces it also seems to have no effect at all. I guess the UI components still check differently and neither workplace nor SystemBrowser allow me to write code using the :> operator

Am 10.12.2014 um 13:11 schrieb Thierry Goubier:
Hi,

If you are using the OpalCompiler (Pharo4, sure, Pharo3, I'm not so sure), have a look at:

RBScanner>>scanSpecialCharacter

Thierry

2014-12-10 12:57 GMT+01:00 Erik Itter <[hidden email]>:
Hi,

I need to modify the compiler adding ":>" as an alias for ":=" for assignment. I have been reading all over the Compiler package but do not find where a tokenizer parses for the assignement operator or where it is defined.

Any hint where to start or do it is appreciated.

best regards
Erik




Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

Nicolai Hess
In reply to this post by Erik Itter
2014-12-10 13:32 GMT+01:00 Erik Itter <[hidden email]>:
Thanks, tried

scanSpecialCharacter
    | character |
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $=
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $:
        ifTrue: [
            self step.
            ^ currentCharacter = $>
                ifTrue: [
                    self step.
                    RBAssignmentToken start: tokenStart]
                ifFalse: [ RBSpecialCharacterToken value: $: start: tokenStart ]].
           
    currentCharacter = $_ ifTrue: [
        self step. 
        ^ RBShortAssignmentToken start: tokenStart ].
   
    character := currentCharacter.
    self step.
    ^ RBSpecialCharacterToken value: character start: tokenStart

but while it does not seem to shred my image to pieces it also seems to have no effect at all. I guess the UI components still check differently and neither workplace nor SystemBrowser allow me to write code using the :> operator

Am 10.12.2014 um 13:11 schrieb Thierry Goubier:
Hi,

If you are using the OpalCompiler (Pharo4, sure, Pharo3, I'm not so sure), have a look at:

RBScanner>>scanSpecialCharacter

Thierry

2014-12-10 12:57 GMT+01:00 Erik Itter <[hidden email]>:
Hi,

I need to modify the compiler adding ":>" as an alias for ":=" for assignment. I have been reading all over the Compiler package but do not find where a tokenizer parses for the assignement operator or where it is defined.

Any hint where to start or do it is appreciated.

best regards
Erik




Hi Erik

with Opal resp. RBScanner (in pharo3 and pharo4)
There is a special handling for
k:=1
and
k := 1
because "k" can be an identifier, or the start of a selector (keyword message) therefore you
have to change this too:

RBScanner>>#scanIdentifierOrKeyword

    (currentCharacter = $: and: [stream peek ~= $=])    "<---- add a test for $>"
        ifTrue: [^self scanKeyword].


and the browsers/editor source code panel uses SHParserST80 for the syntax highlighting:

SHParserST80>>#isAssignment
    ^ currentToken = ':='
        or: [currentToken = '_']   "<---- add atest for $> "



nicolai
Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

Erik Itter
THX, Nicolai and Thierry, that got me a few steps further and will try
to get the rest by myself (at least for a few hours...).

Reply | Threaded
Open this post in threaded view
|

Re: modifying the compiler adding an alias for :=

andreas
Hi,

and did you find your answer?