Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch syntax parsing to texlab/pest/nom #2

Open
michaelvanstraten opened this issue Jun 5, 2024 · 3 comments
Open

Switch syntax parsing to texlab/pest/nom #2

michaelvanstraten opened this issue Jun 5, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@michaelvanstraten
Copy link
Contributor

No description provided.

@michaelvanstraten michaelvanstraten changed the title Switch syntax parsing rowan using syntax crate of texlab Switch syntax parsing to rowan using syntax crate of texlab Jun 5, 2024
@michaelvanstraten michaelvanstraten changed the title Switch syntax parsing to rowan using syntax crate of texlab Switch syntax parsing to rowan using syntax crate inside of texlab Jun 5, 2024
@WGUNDERWOOD
Copy link
Owner

Thanks for this suggestion; I would definitely be interested in moving the syntax parsing to a system based on texlab. From a brief look around, it seems that I might need to use the parser crate at https://github.com/latex-lsp/texlab/tree/master/crates/parser/src. Let me know if this sounds correct -- maybe there is a high-level function we can use to parse the document initially into a rowan syntax tree?

@michaelvanstraten
Copy link
Contributor Author

There is the parse_latex function, which basically does what we need.

Since rowan is a lossless parser, we can then take the generated tree and, directly, transform it back into the same input. Formatting is then just the act of mutating the tree until the desired result is achieved. I've thought about different abstraction levels yesterday, but I haven't come to a satisfactory solution yet.

I've messaged you on Keybase.

@WGUNDERWOOD WGUNDERWOOD changed the title Switch syntax parsing to rowan using syntax crate inside of texlab Switch syntax parsing to rowan using texlab Jun 9, 2024
@WGUNDERWOOD
Copy link
Owner

WGUNDERWOOD commented Jun 9, 2024

Here's an explicit example of how this might work.

use texlab::parser::parse_latex;
use texlab::syntax::latex::SyntaxNode;

fn main() {
    // sample text
    let text = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        \\begin{equation}\n  \
        E = m c^2\n\
        \\end{equation}\n\
        \\end{document}";

    // convert the text to a syntax tree
    let tree = SyntaxNode::new_root(parse_latex(&text));

    // display the syntax tree
    dbg!(&tree);

    // convert the syntax tree back to text
    println!("{}", &tree.to_string());
}

@WGUNDERWOOD WGUNDERWOOD self-assigned this Jun 9, 2024
@WGUNDERWOOD WGUNDERWOOD added the enhancement New feature or request label Aug 15, 2024
@WGUNDERWOOD WGUNDERWOOD changed the title Switch syntax parsing to rowan using texlab Switch syntax parsing texlab/pest/nom Aug 31, 2024
@WGUNDERWOOD WGUNDERWOOD changed the title Switch syntax parsing texlab/pest/nom Switch syntax parsing to texlab/pest/nom Sep 1, 2024
@WGUNDERWOOD WGUNDERWOOD removed their assignment Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants