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

feat: rewrite the scanner in C #56

Merged
merged 3 commits into from
Jun 19, 2023

Conversation

amaanq
Copy link
Contributor

@amaanq amaanq commented Jun 19, 2023

No description provided.

@amaanq amaanq force-pushed the rewrite-it-in-c branch from bf8cb81 to 0640546 Compare June 19, 2023 03:45
@jonatanklosko
Copy link
Member

Hey @amaanq, thanks for the PR :) I think there are a couple other places to adjust with relation to bindings (ref), can you also please adjust those?

(FTR why we switch tree-sitter/tree-sitter-cpp#209)

src/scanner.c Outdated
Comment on lines 276 to 277
// =, ==, ===, =~, =>
} else if (lexer->lookahead == '=') {
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, I would keep the original formatting :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it'd be nice if there was a clang-format file for that standard..having to manually do that is a bit annoying 😅 if the main want is indents being 2 spaces then thats much easier to do

Copy link
Member

Choose a reason for hiding this comment

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

To be fair there is no standard, I didn't use a formatter :D

If there's an easy way to add a formatter task then that works for me (otherwise whoever changes the file may reformat it using different tool or IDE). Perhaps the clang-format npm package would do? Then we could add it to the formatting tasks we have:

"format": "prettier --trailing-comma es5 --write grammar.js",
"format-check": "prettier --trailing-comma es5 --check grammar.js"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

auto formatting happens from the clangd lsp, a .clang-format file in the project root can set this up easily and clangd will pick it up and override the users config. Here's my config for example to show you a few options that can be configured:

AlignArrayOfStructures: Left
BasedOnStyle: LLVM
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
SeparateDefinitionBlocks: Always
SortIncludes: CaseInsensitive
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeCaseColon: false

Rest are here https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, my point is that we should have a way to easily run it with CLI and also check formatting on CI. Here's the package I found, which as far as I understand calls the clang formatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm..sure that could be fine - I'm not against it but a clang-format file could be enough if anyone's using the lsp/format

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but with the file alone we can't enforce it on CI, and we assume they use LSP (which for example I don't :)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep..understandable. Added the dep + format script, but it has no easy "just show me the errors" option so I just used diff (returns 1 on differences, 0 if none)

@amaanq
Copy link
Contributor Author

amaanq commented Jun 19, 2023

Hey @amaanq, thanks for the PR :) I think there are a couple other places to adjust with relation to bindings (ref), can you also please adjust those?

(FTR why we switch tree-sitter/tree-sitter-cpp#209)

done

package.json Outdated Show resolved Hide resolved
@amaanq amaanq force-pushed the rewrite-it-in-c branch 2 times, most recently from 301951e to be29840 Compare June 19, 2023 22:22
@amaanq
Copy link
Contributor Author

amaanq commented Jun 19, 2023

Forgot to add the .clang-format file 🙈

@amaanq amaanq force-pushed the rewrite-it-in-c branch from be29840 to 4e7ab37 Compare June 19, 2023 22:22
Copy link
Member

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@jonatanklosko jonatanklosko merged commit f74a75d into elixir-lang:main Jun 19, 2023
@amaanq
Copy link
Contributor Author

amaanq commented Jun 19, 2023

thank you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants