polystat / odin

Object Dependency Inspector
10 stars 2 forks source link

Introducing locator functionality to AST #28

Closed nikololiahim closed 2 years ago

nikololiahim commented 2 years ago

Initially, this pull request was intended to introduce identifiers with locators (^.^.^.apple, $.self). However several other things have to be done before this:

  1. In order to test and debug the implementation, we need a working pretty-printer.
  2. Existing pretty-printer had some issues that needed to be fixed.
  3. In order to correctly pretty print some AST arrangements, parser needs to recognize single-line abstractions.

What was done:

  1. Explicit locator chains are parsed into EOSimpleAppWithLocator. For example, EO code ^.^.^.a gets parsed into:
    EOSimpleAppWithLocator("a", 3)

    Previously, such expressions were parsed as:

    EODot(EODot(EODot(EOSimpleApp("^"), "^"), "^"), "a")
  2. We created an algorithm for replacing plain EOSimpleApps with EOSimpleAppWithLocators. The following code without locators:
    
    [] > obj
    [self] > method
    self > @
    [method] > shadowedMethod
    method > @
    [] > notShadowedMethod
    method > @

[] > notShadowedObj obj > @

[] > shadowedObj [obj] > method [] > innerMethod obj > @ obj > @

[] > outer [] > self 256 > magic [] > dummy [outer] > dummyMethod outer > @ outer.self > @ self "yahoo" > @ [self] > method self.magic > @

gets turned into the following code with locators:

[] > obj [self] > method $.self > @ [method] > shadowedMethod $.method > @ [] > notShadowedMethod ^.method > @ [] > notShadowedObj ^.obj > @ [] > shadowedObj [obj] > method [] > innerMethod ^.obj > @ $.obj > @ [] > outer [] > self 256 > magic [] > dummy [outer] > dummyMethod $.outer > @ ^.^.^.outer.self > @ ^.self > @ "yahoo" [self] > method $.self.magic > @

3. Existing tests were adapted and extended. The most prominent one is that the property:

ast->toEO == ast->toEO->parsed->toEO


now holds for both the parsed and pretty-printer.
nikololiahim commented 2 years ago

@fizruk I have updated this PR's message.