Skip to content

Allow annotations on individual topology connections - #1190

Merged
bocchino merged 7 commits into
nasa:mainfrom
Shakhtar-Sankur:connection-annotations
Dec 4, 2026
Merged

bocchino merged 7 commits into
nasa:mainfrom
Shakhtar-Sankur:connection-annotations

Conversation

@Shakhtar-Sankur

Copy link
Copy Markdown
Contributor

Fixes #664

This follows the design in #664:

  1. Ast.SpecConnectionGraph.Direct.connections is now a List[Annotated[SpecConnectionGraph.Connection]], and the parser reads the connections of a direct graph with annotatedElementSequence, as for enum constants and struct members.
  2. Connection has a new last field, astOpt: Option[Ast.Annotated[Ast.SpecConnectionGraph.Connection]] = None.
  3. Connection.fromAst takes the annotated AST connection and fills in astOpt.

The rest follows from the AST change: template expansion keeps the annotations, BasicUseAnalyzer and TypeExpressionAnalyzer visit the connection inside the annotation, the XML import gives each connection empty annotations, and AstWriter and FppWriter write the annotations, so fpp-syntax -a and fpp-to-fpp show them:

connections C {
  @ Connection
  i1.p[0] -> i2.p[1] @< Connection
  unmatched i1.p1[0] -> i2.p2[0]
}

Two things to check:

  • Analysis JSON. AnalysisJsonEncoder derives the Connection encoder automatically, so astOpt would have put the whole annotated AST of every connection into the analysis output. Since the annotation does not need to go into generated output, I gave Connection an explicit encoder that leaves astOpt out, and the analysis JSON is unchanged. I can remove that encoder if you would rather have astOpt in the analysis output.
  • AST JSON. In the AST output of fpp-to-json, each direct connection is now [pre, connection, post], like the other annotated elements. The node IDs after a connection list also change: annotatedElementSequence tries an element with a separator, then with a post-annotation, then without a terminator, and each attempt creates new nodes, as it already does for other annotated lists. That is why the five fpp-to-json reference files change so much; most of it is nesting and renumbered IDs.

Tests: syntax.fpp (fpp-syntax) has an annotated connection, with its AST reference outputs updated, and topology.fpp (fpp-to-fpp) round-trips one. Built with Java 25 as in CI: sbt test passes (716 tests). In compiler/test, everything passed except eight reference files (three more outputs of syntax.fpp, which now show the annotations, and the five fpp-to-json files), which I regenerated with the branch; the fpp-syntax, fpp-to-fpp and fpp-to-json tests pass after that.

AI disclosure, per the F´ AI policy: I used Claude as an assistant to work through the parser and the places that use connections, and to draft the code changes, the tests and this description. I've reviewed all of it against the code myself, ran the builds and tests above, and I'll handle the review.

Shakhtar-Sankur and others added 4 commits November 12, 2026 02:02
Parse the connections of a direct connection graph as an annotated
element sequence, so each connection can have pre and post annotations.
Ast.SpecConnectionGraph.Direct now holds a list of
Annotated[Connection], and Connection keeps the annotated AST
connection in a new astOpt field, filled in by Connection.fromAst.

The AST writer and the FPP writer write the annotations. The analysis
JSON output leaves out astOpt, since the AST output already has it.

Fixes nasa#664
In Parser, id is the parser for the id token, not the identity
function, so the connections parser did not compile.
fpp-syntax and fpp-to-fpp now write the annotations on the first
connection of syntax.fpp. In the AST JSON of fpp-to-json, each direct
connection is now an annotated triple, like the other annotated
elements, and the parser assigns the node IDs that follow it
differently, as it does after other annotated element sequences.
@bocchino
bocchino requested review from Kronos3 and bocchino November 17, 2026 00:24

@bocchino bocchino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good! We need to update the language specification and the User's Guide to match. Please make those changes. By coincidence, it looks like the section to update in both documents is 14.2.1.

@Shakhtar-Sankur

Copy link
Copy Markdown
Contributor Author

Thanks, Rob! I'll update the language specification and the User's Guide (section 14.2.1 in both) to cover annotations on individual connections, and push the changes shortly.

List a connection in a direct graph specifier among the annotatable
elements in the language specification (section 14.2.1), and show an
annotated connection in the User's Guide section on direct graph
specifiers.
@bocchino

bocchino commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

@Shakhtar-Sankur I see the changes, thanks. Is this PR ready for re-review?

@Shakhtar-Sankur

Copy link
Copy Markdown
Contributor Author

Yes, it's ready for re-review. Commit a98042e adds connections in direct graph specifiers to the list of annotatable elements in the spec (14.2.1) and an annotated connection example to the User's Guide (14.2.1). I haven't regenerated the HTML files; happy to do that too if you'd like.

@bocchino

bocchino commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Sounds good! Yes, please regenerate the HTML. That's part of the process for updating the docs. Then I'll re-review.

@Shakhtar-Sankur

Copy link
Copy Markdown
Contributor Author

Done: I've regenerated the HTML for the spec and the User's Guide in 18fcab5. Ready for re-review whenever you are.

@bocchino bocchino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@bocchino
bocchino merged commit 3dc4831 into nasa:main Dec 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow annotations for individual topology connections

3 participants