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

Comments should be preserved, not removed #3

Open
deathcap opened this issue May 4, 2016 · 2 comments
Open

Comments should be preserved, not removed #3

deathcap opened this issue May 4, 2016 · 2 comments

Comments

@deathcap
Copy link
Owner

deathcap commented May 4, 2016

No description provided.

@deathcap
Copy link
Owner Author

deathcap commented May 6, 2016

Comments are removed by the preprocessor, and cannot currently be parsed by pycparser eliben/pycparser#102 Ignoring comments. This therefore has the same underlying cause as #1 Preprocessor constants should be preserved, not expanded.

Idea for how to fix these issues: change the design of transpile-c-to-js to not write out the JavaScript from the AST — instead, have it parse C into the AST, and manipulate the C source as text to make it valid JavaScript, rewriting the C constructs to JS. Since JS is a C-style language, it won't have to be completely rewritten. And we do want to preserve the syntactical structure and style of the source code as much as possible.

Mainly transpile-c-to-js's task would be to find the character ranges of C types, and remove/replace them with JS let, function, arguments, operators, declarations, and so on — keeping everything else mostly intact. For GH-1, may also need to instrument a C preprocessor, to replace #define FOO 1 with const FOO = 1;; as this knowledge is lost when the original source is piped to cpp, then analyzed by pycparser.

@deathcap
Copy link
Owner Author

Like https://news.ycombinator.com/item?id=11704472

Rather than manipulating the AST, Bublé manipulates the source code directly, using the AST as a guide – so there's no costly code generation step at the end.

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

1 participant