Login  Register

AST: Adding RBComment to a node

Posted by Mehrdad on Apr 23, 2020; 9:13am
URL: https://forum.world.st/AST-Adding-RBComment-to-a-node-tp5115431.html

Hello,

How can I make a comment on a node dynamically?

- Here is a code i've tried:

b:= RBParser parseMethod: 'foo self x: 2. x:=0. y:=8.'.
node := b body statements at: 1.
node comments: { RBComment with: 'comment' at: node stop + 1 }.
b formattedCode.

- The result:

foo
    self x: 2.    . x:=0. y
    x := 0.
    y := 8

- I expect:

foo
    self x: 2.    "comment"
    x := 0.
    y := 8