qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
172 stars 25 forks source link

Eliminate `NodeStyle` in Loyc trees? #80

Open qwertie opened 5 years ago

qwertie commented 5 years ago

Using NodeStyle (holds 8 bits of formatting info) has two genuine advantages:

  1. It's "free" - it uses no memory as it is hidden away in the top 8 bits of a node's 32-bit length field.
  2. It's mutable - as it is intended to affect output formatting, not semantics, it's the only part of LNode that is allowed to change. Eliminating it would preclude certain timesaving tricks that might come in handy in a compiler.

Instead of NodeStyle we could use the flyweight pattern to store the styles as a normal attribute list.

Any thoughts @jonathanvdc?

qwertie commented 4 years ago

Hmm, getting rid of NodeStyle isn't that easy... it's not just LNode that uses it, but also Token, and Token has a stronger case for actually needing it. It's sometimes convienient for a parser to copy the NodeStyle over from the token unchanged; transforming it automatically is not trivial since NodeStyle values are ambiguous (e.g. 6 is used for both TQStringLiteral and HexLiteral.)