gdamore / tree-sitter-d

D Grammar for Tree Sitter
MIT License
41 stars 7 forks source link

build: Make scanner.c build with clang #22

Closed vadorovsky closed 9 months ago

vadorovsky commented 9 months ago

isascii is a GCC extension, not present in clang.

nordlow commented 9 months ago

The file scanner.c is generated by tree-sitter right? If so why modify the code?

nordlow commented 9 months ago

The file scanner.c is generated by tree-sitter right? If so why modify the code?

Ahh, so it's hand-written. Why is this needed? For performance?

vadorovsky commented 9 months ago

Oh, I didn't know it's auto-generated. In that case, I'm happy to apply the fix in tree-sitter.

This change is needed for me to be able to build Helix (which pulls tree-sitter-d as a dependency) with clang as C compiler. isascii is not present in clang, so trying to build it fails with the following errors:

  Failure 2/2: d Parser compilation failed.
  Stdout:
  Stderr: /home/vadorovsky/repos/helix/runtime/grammars/sources/d/src/scanner.c:70:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     70 |                         if (!isascii(lexer->lookahead) ||
        |                              ^
  /home/vadorovsky/repos/helix/runtime/grammars/sources/d/src/scanner.c:81:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     81 |                         if (!isascii(lexer->lookahead) ||
        |                              ^
  /home/vadorovsky/repos/helix/runtime/grammars/sources/d/src/scanner.c:92:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     92 |                         if (!isascii(lexer->lookahead) ||
        |                              ^
  /home/vadorovsky/repos/helix/runtime/grammars/sources/d/src/scanner.c:126:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    126 |                         if (!isascii(lexer->lookahead) ||

I had to patch tree-sitter-d with what I submitted here to make it build.

gdamore commented 9 months ago

The file scanner.c is generated by tree-sitter right? If so why modify the code?

No, scanner.c is not auto-generated-- parse.c is.

gdamore commented 9 months ago

The reason is hand-coded is partly for performance, but partly for simplicity -- some aspects of the D grammar are best done at lexing time -- trying to specify the lexing part of the grammar in tree-sitter itself would greatly explode the grammar, and complicate the rule set. D is already complex enough as it is. :-)