Commit graph

72 commits

Author SHA1 Message Date
Max Brunsfeld
5e2456c2f2 Avoid using recursion for ts_subtree_compare
This can lead to stack overflow crashes.
2023-11-27 11:35:33 -08:00
Amaan Qureshi
05a4f9f3e3
Merge pull request #1411 from aminya/c-warnings
Fix compiling C library with Clang on Windows
2023-08-03 13:39:52 -04:00
Amaan Qureshi
13f6ec2b0c
fix: rename shadowed variables from -Wshadow warnings and apply some useful clang-tidy warnings 2023-07-19 18:12:26 -04:00
Amaan Qureshi
753fa1c3ff
fix(lib): explicitly cast numbers to the same size in potential spots for infinite loops 2023-07-19 03:49:14 -04:00
Max Brunsfeld
0b817a609f Clear the parse stack when terminating parsing early due to error cost
This fixes a bug where the parse tree would not be rebalanced if this
code path was taken.
2023-02-13 13:45:12 -08:00
Max Brunsfeld
efd22e452b Fix suppression of empty tokens during error handling at included range boundaries 2022-11-14 12:20:39 -08:00
Logan Collins
5337a678fa Resolving a potential crash freeing a null pointer when cancelling parses. 2022-10-31 11:35:52 -07:00
Matt
af6611e530
matching integer types 2022-09-21 08:50:01 -04:00
Max Brunsfeld
3ac36b0cbe Handle backslashes in token names when printing DOT debug graphs 2022-06-25 17:13:11 -07:00
Max Brunsfeld
5aa2f4dc8c Log when ignoring an empty external token after an error 2022-06-24 19:07:27 -07:00
Max Brunsfeld
d223a81b50 Allow empty external tokens during err recovery if they change the scanner's state 2022-06-24 15:58:13 -07:00
Max Brunsfeld
c0e1991f6b 🎨 ts_parser__lex 2022-06-24 14:24:21 -07:00
Max Brunsfeld
ca902065cb Fix bug when stack versions merge after reducing a non-terminal extra 2022-06-24 14:24:21 -07:00
Rich Siegel
150eb2966b Fixed warning/error when compiling with clang -Os.
DISCUSSION:

When compiling with `-Os` for "smallest, fastest", an error is reported in `parser.c`:

```
/Users/siegel/git/tree-sitter/lib/src/./parser.c:1368:10: error: unused variable 'did_merge' [-Werror,-Wunused-variable]
    bool did_merge = ts_stack_merge(self->stack, version, previous_version_count);
         ^
1 error generated.
```

This is because with `NDEBUG` set,  `assert(e)` collapses to `(void)0`,
which in turn means that `did_merge` does not actually get consumed.
This seems to get caught when compiling with `-Os`, but not otherwise.

Compiler version:
```
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
2022-03-04 18:00:16 -05:00
Max Brunsfeld
8decec3774 Properly incorporate lookahead bytes when recovering via missing token 2022-03-02 17:12:25 -08:00
Max Brunsfeld
0fb864c1a0 Retain information about the lexer's lookahead for the token where an error was detected 2022-02-22 09:45:26 -08:00
Max Brunsfeld
0bdd9b640c Store the lookahead subtree of paused stack versions, not just the lookahead symbol 2022-02-22 09:45:26 -08:00
Max Brunsfeld
d08f1af15c 🎨 2022-02-22 09:43:57 -08:00
Amin Yahyaabadi
6e0c49305e Use ISO C and C++ conformant name: _fdopen on windows
Fixes
```
warning: In file included from src\lib.c:12:
warning: src/./parser.c:1781:28: warning: 'fdopen' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _fdopen. See online help for details. [-Wdeprecated-declarations]
warning:     self->dot_graph_file = fdopen(fd, "a");
warning:                            ^
warning: C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h:2431:28: note: 'fdopen' has been explicitly marked deprecated here
warning:         _Check_return_     _CRT_NONSTDC_DEPRECATE(_fdopen)    _ACRTIMP FILE* __cdecl fdopen(_In_ int _FileHandle, _In_z_ char const* _Format);
warning:                            ^
warning: C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:414:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
warning:         #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(             \
warning:                                                  ^
warning: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30133\include\vcruntime.h:310:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
warning: #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
```
2022-01-21 22:39:24 -08:00
Max Brunsfeld
584b55df8d Delete unused code, tweak whitespace 2022-01-19 16:54:57 -08:00
Max Brunsfeld
4e2e059865 Ensure 'extra' bit is set correctly when reusing a node
Fixes #1444
2021-11-19 12:43:55 -08:00
Andrew Hlynskyi
7f538170bf fix(parser): count rows in the debug log from 0 2021-07-15 11:47:14 +03:00
Max Brunsfeld
a40045a419 When editing, properly invalidate trees that depend on get_column 2021-03-11 14:46:13 -08:00
Max Brunsfeld
774ae5e3d5 In parse tables, store production ids as 16 bits
Also remove the use of bitfields from the parse table format.
In all cases, bitfields were not necessary to achieve the
current binary sizes. Avoiding them makes the binaries more
portable.

There was no way to make this change backward-compatible,
so we have finally dropped support for parsers generated
with an earlier version of Tree-sitter.

At some point, when Atom adopts this version of Tree-sitter,
this change will affect Atom users who have installed packages
using third-party Tree-sitter parsers. The packages will need
to be updated to use a regenerated version of the parsers.
2021-02-25 16:12:31 -08:00
Andrew Hlynskyi
6448053efa parser.c - added backslash escaping in LOG_LOOKAHEAD to make it clear in case of \n 2021-02-08 13:33:54 +02:00
Andrew Hlynskyi
51f8b16bb0 parser.c - make LOG_LOKAHEAD simpler according to disscussion in PR #917 2021-02-08 13:32:15 +02:00
Andrew Hlynskyi
f92ad04824 parser.c - added LOG_LOOKAHEAD macro to escape \n in logging 2021-02-08 06:23:55 +02:00
Max Brunsfeld
908b102786 Add more doc comments in the C lib 2020-10-23 12:15:44 -07:00
Max Brunsfeld
d533d1f076 Allocate parent nodes together with their child array 2020-10-23 12:15:44 -07:00
Hansraj Das
000455ee79 Multiple typo fixes
* This is a patch from neovim PR: https://github.com/neovim/neovim/pull/13063
2020-10-11 13:02:40 +05:30
Björn Linse
04eacc44ef avoid warnings for implicit fallthrough in switch statements 2020-08-26 10:04:08 +02:00
Max Brunsfeld
81bbdf19f4 Fix handling of non-terminal extras that share non-extra rules
Fixes #701
2020-07-29 09:50:13 -07:00
Max Brunsfeld
253f23c3d4 Fix error when parse error occurs after non-terminal extra 2020-07-28 13:33:13 -07:00
Max Brunsfeld
0bf2450b4a Always enforce stack version limit during reductions
Fixes #669
2020-07-06 15:58:33 -07:00
Max Brunsfeld
0e5ff14976
Requery the parse table when breaking down the parse stack on invalid lookahead (#636)
* Requery parse table after breaking down parse stack due to invalid lookahead

* Include Ruby parser in randomized test suite

Ruby and PHP are our only two languages that use non-terminal extras.
Adding Ruby uncovered some bugs.

* Print edited source code when running parse --edit w/ debug flag

* Recompute lookahead when breaking down stack on invalid lookahead

* Fix stack summary leak when there are two discontinuities on a stack version
2020-06-04 13:40:04 -07:00
Thomas Vigouroux
81d533d2d1
Fix compilation warnings (#635)
* lib: fix compilation warnings

* ci: add CFLAGS
2020-06-03 12:19:57 -07:00
Riccardo Schirone
780e9cecc9 Do not use multiple unnamed structs inside of unions 2020-04-29 20:42:45 +02:00
Max Brunsfeld
7f4828254f Fix criteria for detecting when an aborted parse is resuming 2020-03-09 11:30:08 -07:00
Max Brunsfeld
31f3e866cf 📝 Add comment for non-terminal extra edge case 2020-03-02 14:21:03 -08:00
Max Brunsfeld
ee46218a73 Fix incremental parsing problem with non-terminal extras
Also add PHP grammar as a fixture to test against.
2020-03-02 14:17:12 -08:00
Max Brunsfeld
d8c3f472d2 Fix fallout from ts_language_next_state fix 2020-02-10 12:00:58 -08:00
Max Brunsfeld
7de36a33eb Remove halt_on_error API 2020-01-27 15:36:09 -08:00
Max Brunsfeld
9f63139a10 Fix error when set_included_ranges is called with an invalid range list 2020-01-17 10:31:28 -08:00
Max Brunsfeld
0cb2ef1082 Fix code paths that still conflated null characters with EOF 2019-12-06 15:29:03 -08:00
Max Brunsfeld
fcaabea0cf Allow non-terminal extras 2019-10-21 16:08:59 -07:00
Max Brunsfeld
64c6cf4473 Implicitly reset parser's state if language is changed after a timeout 2019-10-18 11:28:59 -07:00
Max Brunsfeld
aace0970d8 Tweak formatting, add comments 2019-08-19 17:31:35 -07:00
Max Brunsfeld
ef87ed6130 Check once for cancellation at the beginning of a parse 2019-08-19 17:31:35 -07:00
Max Brunsfeld
64fc944202 Fix missing criteria for leaf node reuse 2019-06-20 15:02:20 -07:00
Max Brunsfeld
0e046fc6c0 Fix bug when the assert macro is disabled
Fixes #364
2019-06-14 14:23:38 -07:00