google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.09k stars 168 forks source link

Import Functionality [Feature Request] #62

Open gachteme opened 4 years ago

gachteme commented 4 years ago

Breakout from #18 to better discuss and judge interest.

Often it is useful to have two states that are very similar, with a few different expressions. Since Continue and state transitions are disallowed due to possible infinite loop issues, a way of reducing development time and redundant SLOC would be to allow a state to import another state which would be evaluated as a setup time macro.

E.g:

Start
  \<some expressions\>
  $$IMPORT ToImportState
  \<some expressions\>

ToImportState
  \<some expressions\>
  ^\S -> Start

Questions:

  1. is there interest in this feature?
  2. is there interest in a separate import feature that does not allow the imported statements to initiate a state transition?
  3. What might the syntax look like? Currently the $$IMPORT is a placeholder.

Potential issues:

  1. Cyclical dependencies. This would be solved by not importing anything which has already been imported into a state. Another option would be only to allow immediate imports.
  2. Debug output statements would become slightly more complex. A current suggestion is to provide a back trace like: line: 10.102.50 where line 50 is the error, but was imported by line 102, which was in turn imported from line 10, which is your current state.
  3. This would likely add complexity to the visual debugger #48 .
  4. Unless using only immediate imports as a simple copy-paste macro, or forgoing a reasonable debug output, this feature would add a decent amount of complexity to multiple parts of the code.

Personally, when I was writing/editing/maintaining templates this feature probably would have saved me a few hours a month in development time. Which is to say it would have been nice but clearly wasn't a deal-breaker.