RBParser message nodes and targeting the receiver and the argument?

unom

Trying to get some of my old code up and running in Pharo. Some method names are different but after some hardship I managed to find equivalents that work.

I am parsing my code and I'd like to check if the receiver or any of the arguments is aSymbol in an effort to match them to supported alternatives. I've managed to do this to selectors, by analysing RBMessageNode s

aNode selector == aSymbol ifTrue: [ aNode selector: replacementSymbol ].

How can this be done to arguments and receivers? Is there a comprehensive guide on RBParser somewhere?

Uko

By direct manipulation

Assuming that you are looking for cases like this:

aSymbol message: aSymbol message: aSymbol

For receiver you should do:

(aNode isMessage and: [
aNode receiver isVariable and: [ 
aNode receiver name = 'aSymbol' ]]) ifTrue: [
   "do your job here" ]

Here is another example on how to replace #aSymbol arguments with #newSymbol:

messageNode arguments: (messageNode arguments collect: [ :arg |
    (arg isLiteralNode and: [ arg value = #aSymbol ])
        ifFalse: [ arg ]
        ifTrue: [ | newNode |
            newNode := #aNewSymbol asLiteralNode.
            arg replaceSourceWith: newNode.
            newNode ] ]).

methodClass compile: ast newSource

The replaceSourceWith: makes sure that just a source will be replaced, but for newSource to actually return a new source you also need to swap the nodes themselves, that's why I'm doing a collect on arguments and return the new ones where needed.

You can view help about RBParser in Word Menu > Help > Help Browser > Refactoring Framework.

You can also play around by inspecting

RBParser parseExpression: 'aSymbol message: aSymbol message: aSymbol'

and looking at its contents

By Parse Tree Transformation

You can use pattern code to match and replace certain code. For example to change the symbol argument of a perform: message you can do this:

ast := yourMethod parseTree.

rewriter := RBParseTreeRewriter new 
        replace: '`receiver perform: #aSymbol'
        with: '`receiver perform: #newSelector'.

(rewriter executeTree: ast) ifTrue: [
    yourMethod class compile: ast newSource ]

You can learn more about the pattern matching syntax in the help topic Word Menu > Help > Help Browser > Refactoring Framework > Refactoring Engine > RBPatternParser …. I thing that MatchTool from pharo catalog can greatly help you in testing the match expressions (it also has a dedicated help topic about the matching syntax) while RewriteTool can help you to preview how your code will be transformed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

targeting XML data via DOM child nodes

From Dev

JMS message receiver filtering by message text

From Dev

Receiver has no segue with identifier error message

From Dev

Receiver type 'xxx' for instance message is a forward declaration

From Dev

Custom Error Message for Event Receiver in SharePoint 2010

From Dev

Broadcast Receiver not correctly grabbing text message contents

From Dev

broadcast receiver doesn't respond to broadcast message

From Dev

Git Alias for Message with Argument

From Dev

Bytes message argument error

From Dev

Passing intent extras from a google cloud message receiver to activity is null

From Dev

JMS - How to correctly implement message receiver with explicit acknowledge?

From Dev

The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher

From Dev

Hash Based Message Authentication Codes (MAC) does not match at receiver end

From Dev

Spark Streaming : Custom Receiver : Data source : Websphere Message Queue

From Dev

Sending an one-message email to a receiver by batch script file(windows)

From Dev

how to my receiver is typing a message and show on my browser

From Dev

The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher

From Dev

Box iOS SDK - Receiver 'BoxSearchRequestBuilder' for class message is a forward declaration

From Dev

Sending an one-message email to a receiver by batch script file(windows)

From Dev

URI() is not the usual Ruby receiver.message format, what is it?

From Dev

Calling web service from Java "The message with Action '' cannot be processed at the receiver"

From Dev

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher.

From Dev

how to my receiver is typing a message and show on my browser

From Dev

Query database for most current message per receiver_id

From Dev

how to implement soap receiver for saop envelope message c#

From Dev

g:message multiple argument passing

From Dev

g:message multiple argument passing

From Dev

command line argument with usage message

From Dev

Where is the argument's message displayed?

Related Related

  1. 1

    targeting XML data via DOM child nodes

  2. 2

    JMS message receiver filtering by message text

  3. 3

    Receiver has no segue with identifier error message

  4. 4

    Receiver type 'xxx' for instance message is a forward declaration

  5. 5

    Custom Error Message for Event Receiver in SharePoint 2010

  6. 6

    Broadcast Receiver not correctly grabbing text message contents

  7. 7

    broadcast receiver doesn't respond to broadcast message

  8. 8

    Git Alias for Message with Argument

  9. 9

    Bytes message argument error

  10. 10

    Passing intent extras from a google cloud message receiver to activity is null

  11. 11

    JMS - How to correctly implement message receiver with explicit acknowledge?

  12. 12

    The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher

  13. 13

    Hash Based Message Authentication Codes (MAC) does not match at receiver end

  14. 14

    Spark Streaming : Custom Receiver : Data source : Websphere Message Queue

  15. 15

    Sending an one-message email to a receiver by batch script file(windows)

  16. 16

    how to my receiver is typing a message and show on my browser

  17. 17

    The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher

  18. 18

    Box iOS SDK - Receiver 'BoxSearchRequestBuilder' for class message is a forward declaration

  19. 19

    Sending an one-message email to a receiver by batch script file(windows)

  20. 20

    URI() is not the usual Ruby receiver.message format, what is it?

  21. 21

    Calling web service from Java "The message with Action '' cannot be processed at the receiver"

  22. 22

    The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher.

  23. 23

    how to my receiver is typing a message and show on my browser

  24. 24

    Query database for most current message per receiver_id

  25. 25

    how to implement soap receiver for saop envelope message c#

  26. 26

    g:message multiple argument passing

  27. 27

    g:message multiple argument passing

  28. 28

    command line argument with usage message

  29. 29

    Where is the argument's message displayed?

HotTag

Archive