eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ParseTreeSourceRewriter':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ParseTreeSourceRewriter


Inheritance:

   Object
   |
   +--RBProgramNodeVisitor
      |
      +--ParseTreeSearcher
         |
         +--ParseTreeRewriter
            |
            +--ParseTreeSourceRewriter

Package:
stx:goodies/refactoryBrowser/parser
Category:
Refactory-ParseTree Matching
Version:
rev: 1.25 date: 2023/09/07 21:04:17
user: stefan
file: ParseTreeSourceRewriter.st directory: goodies/refactoryBrowser/parser
module: stx stc-classLibrary: parser
Author:
Claus Gittinger

Description:


This is a parse tree rewriter which does NOT generate new code from scratch
(i.e. it does not generate its source by recursively walking along the formattedCode methods),
but instead inserts the new nodes code right into the original source code.
This has two advantages:
    it does not destroy the user's formatting, indentation etc.
    it does not forget comments.
I added this, because I constantly got mad at the rewriter reformatting my code for every tiny
little variable rewrite operation.

Caveats: 
    needs more intelligence when rewriting non-trivial code, such as keyword message sends.
    For now, it seems to only behave reasonable for very simple stuff, such as replacing a variable
    by another or by a simple unary send.


Related information:

    ParseTreeRewriter

Instance protocol:

accessing
o  addReplacement: aReplacement

o  alwaysPerformAllSearches
please read the comment in the inherited alwaysPerformAllSearches

o  alwaysPerformAllSearches: aBoolean
please read the comment in the inherited alwaysPerformAllSearches

o  executeTree: aParseTree in: optionalClassBeingProcessed
Performs rewrites on given tree;
but instead of creating new source code by pretty printing the rewritten tree,
this one applies the replacements to the original source;
thus preserving indentation, comments and line breaks (empty lines).
This does not work all the time; then a pretty printed version is returned - as before.
(which is bad, because the original RB code had severe trouble in handling comments,
at times even forgetting one)

o  forgetReplacements

o  replacements

queries
o  isRewritingOriginalSource

replacing
o  executeReplacementsInSource: aSourceString
execute all replacements in a sourceString.
Invoked after we have collected all replacements.

o  replaceLiteral: oldLiteral with: newLiteral

o  replaceLiteral: oldLiteral with: newLiteral when: condition

o  replaceVariable: variable with: newVariable
Transcript showCR:'replacing variable ',variable,' by ',newVariable.


Private classes:

    NodesOverlapError


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:32:52 GMT