Skip to content

New odt output format: dtsc - #15

Open
lucasvr wants to merge 2 commits into
a6f:mainfrom
lucasvr:lucas/dtsc-output
Open

New odt output format: dtsc#15
lucasvr wants to merge 2 commits into
a6f:mainfrom
lucasvr:lucas/dtsc-output

Conversation

@lucasvr

@lucasvr lucasvr commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The new format generates a dts-like output, but comments from the input
files are spliced back into the merged tree before pretty-printing.

Builds on top of PR #14

Comments and whitespace between top-level definitions are not part
of any `TopDef`, so copy the source text separating each definition
from the previous one when the output is Format::Dti.
The new format generates a `dts`-like output, but comments from the input
files are spliced back into the merged tree before pretty-printing.

@a6f a6f left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this might be done more cleanly with a new implementation of merge(). Manually tracking source positions and reconstituting spans is definitely going around the parser instead of using it to give structure to the input.

Much of the difficulty here is with how pest handles trivia. A model which attaches it to an adjacent non-trivial node could help here, and would also help with some difficult cases in the pretty-printer.

What application do you have in mind for this?

@lucasvr

lucasvr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

I think this might be done more cleanly with a new implementation of merge(). Manually tracking source positions and reconstituting spans is definitely going around the parser instead of using it to give structure to the input.

Much of the difficulty here is with how pest handles trivia. A model which attaches it to an adjacent non-trivial node could help here, and would also help with some difficult cases in the pretty-printer.

What application do you have in mind for this?

I'm mostly looking for an API that works like odt -I dts -O dtv while merging + preserving comments. The UI of the clocktree editor appends a new / { } block each time the user wants to save changes made to the graph, but the series of appends doesn't generate a pretty-looking file.

@a6f a6f left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm mostly looking for an API that works like odt -I dts -O dtv while merging + preserving comments. The UI of the clocktree editor appends a new / { } block each time the user wants to save changes made to the graph, but the series of appends doesn't generate a pretty-looking file.

Maybe we could implement something more restricted which can handle that. Does the editor emit comments or deletions? If all it does is set properties, maybe we could inject those directly at the site of the definitions they replace. Or we could only merge a comment-free pair of blocks at the bottom of the file, instead of having to come up with semantics for merging comments.

Comment thread src/bin/dtc.rs
Comment on lines +325 to +328
// Text ahead of constructs that are not themselves emitted
// (/delete-node/, /delete-property/) carries over to the next
// emitted construct (i.e., the next property or child node, or the
// closing brace if none follows).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hmm. Consider:

// comment 1
/ {
    // comment 2
    soc {
        // comment 3

        // comment 4
        /delete-node/ dev@0;
    };
};

Arguably we should discard all of these comments, since the whole block is likely redundant after merging. Comments 1-3 might have something interesting to say, but it's unclear where to place them that won't be confusing. You almost want to ask an LLM if moving them has preserved their meaning or not....

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.

2 participants