Skip to content

Draft: regenerate script in the same format as originally parsed script (continued)

finesse importer requested to merge feature/regenerator into develop

Continuing work on this branch having merged the state of the work already last month (see !77 (merged)).

To-do:

  • Implement merge methods in finesse.script.generator
  • Sort the parsed components after compilation (see #293 (closed))
  • Implement regeneration of variadic arguments
  • Implement regeneration of link commands
    • Should probably define a priority for unparsing, such that the link adapter runs before space and can yield a link command that represents N Space objects whereupon the space adapter will not handle those N Space objects
    • The parsed KatGraph probably needs to be modified to store the Space objects implicitly created by link
  • Implement regeneration for singular=False commands; may need changes to KatGraph stored from original parse to track a unique (directive, lineno) key
  • Implement expression regeneration
    • Need to determine which operations need to use parentheses to prevent disrupting parse order.
    • Maybe implement an ExpressionGroup class in Finesse that represents (some expression) - this would make unparsing easier
  • Identify and regenerate expressions eagerly evaluated during parsing
  • Fix various Finesse class init signatures for compatibility with the unparser
    • Remove intrix if it's no longer needed (if it stays, it will also need to have its signature fixed)
  • Implement some way to dump only two of R, T and L and Rc or Rcx and Rcy where appropriate
    • See #451.
    • Perhaps the adapter for Mirror and Beamsplitter should yield an RTLGroup object that has special handling in the generator.
  • Decide how to handle errors during unparsing of a component - keep going, just skipping the line? Or immediately halt? Print the originally parsed instruction (if one exists) as a comment instead? Related: #393 (closed).
  • Decide sensible default dump behaviours such as whether to dump default values, use long-form or short-form names, etc.
  • Decide where certain dump behaviours can be overridden by the user: the user's config file? Signature of unparse()? Both (with signature overriding user config)?
  • Look into issues with floating point precision when regenerating, such as with Gauss in tests/functional/script/katscript/unparse/elements/test_gauss.py
  • Add unparse tests for most (ideally all) KatScript directives
  • Add unparse-then-reparse tests for some (all?) KatScript directives
  • Update developer docs, describe how unparser works
  • Fix #370 (closed).

Major changes:

  • Refactored adapter interface so there is now a lot more control over how individual instructions get parsed and unparsed. Most use the same set of classes for this but it's now possible to implement custom ones for special behaviours. For instance, most commands have bespoke classes.

Minor changes:

  • Syntax suggestions now show correct use of delimiters: laser name{ P=1}{ f=0}, modes({modes=none}{, maxtem=none}) etc.
Edited by finesse importer

Merge request reports