gdamore / tree-sitter-d

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

Fix build with -std=c11 #20

Closed wezm closed 11 months ago

wezm commented 1 year ago

When building with gcc or clang passing -std=c11 scanner.c fails to build (helix builds grammars with this argument):

gcc:

src/scanner.c: In function ‘match_escape’:
src/scanner.c:70:30: warning: implicit declaration of function ‘isascii’ [-Wimplicit-function-declaration]
   70 |                         if (!isascii(lexer->lookahead) ||
      |                              ^~~~~~~

clang:

src/scanner.c:70:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        if (!isascii(lexer->lookahead) ||
                             ^
src/scanner.c:81:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        if (!isascii(lexer->lookahead) ||
                             ^
src/scanner.c:92:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        if (!isascii(lexer->lookahead) ||
                             ^
src/scanner.c:126:9: error: call to undeclared function 'isascii'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        if (!isascii(lexer->lookahead) ||
                             ^
4 errors generated.

It seems that isascii is deprecated and is not visible by default with -std=c11. This PR attempts to address that although I'm not 100% sure it's the right fix. A better option might be to define isascii in this project if it's not already defined. Open to suggestions

fweimer-rh commented 11 months ago

I submitted a different fix as helix-editor/helix#8953.

gdamore commented 11 months ago

Note that there are no cases for Unicode where the above definition of isascii is incorrect. There are very few other encodings that don't meet this, and we don't support any of them. (E.g. EBCDIC or SHIFT-JIS.) All the Latin-X versions for example meet this criteria.

gdamore commented 11 months ago

I'm closing this in favor of #22 which fixes the same bug.

wezm commented 11 months ago

Cool, happy to have a fix either way.