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

Determine architecture #2

Open
scottgonzalez opened this issue Oct 21, 2015 · 1 comment
Open

Determine architecture #2

scottgonzalez opened this issue Oct 21, 2015 · 1 comment

Comments

@scottgonzalez
Copy link
Owner

There are several steps that this tool will need to go through that I can think of right now:

Get the contents of the files to diff

For standard diffs, this is simple since we just read in the contents of the two files. However, this tool will mostly likely be used in conjunction with a version control system, so we'll need to build in hooks to define how to get the two different versions of the file. I suspect there will be a lot of system-specific code for each VCS we support.

Generate the CST for both files

This is complicated by the fact that CST parsers don't exist for many languages. In addition to that, my understanding is that upgrading an AST parser to a CST parser isn't exactly a trivial process, especially if there's no standard to follow.

We'll need hooks for these parsers based on file extension. We can fall back to a standard text-based diff if we don't have a parser registered for a given file extension.

Some parsers will need to call into other parsers. For example, the HTML parser will want to run <style> content through the CSS parser and <script> content through the JS parser.

Generate the diff from the CSTs

I'm not sure if we'll want to create an object structure that we can transform into the actual diff or if we'll just want to always generate a diff that matches the standard diff format.

Apply syntax highlighting

I'm not sure how many tools exist for applying syntax highlighting to small code snippets. This might be a very difficult problem since you lose so much context when you're applying the highlighting to the individual portions of the diff.


There's probably more that I'm not thinking of. Let's gather ideas here and build out a plan.

@drabiega
Copy link

Generating CST parsers from grammars is actually pretty easy. It would be possible to modify the generated parsers so that they could operate on snippets and apply syntax highlighting, but it's probably easier to annotate the CST before the diff and then use those annotations to do the syntax highlighting.

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

No branches or pull requests

2 participants