Commit Graph

897 Commits (2ca123333175618cd3ebbc3cd167a32a9249aef6)
 

Author SHA1 Message Date
Arthur Baars 2ca1233331 Update generated code 2021-11-16 21:20:43 +07:00
Arthur Baars 76cbd1bb75 Add _expression and _simple_numeric to supertypes list 2021-11-16 21:20:43 +07:00
Arthur Baars 2a98a53b45 Add supertypes for pattern rules 2021-11-16 21:20:43 +07:00
Arthur Baars d3955c7ae5 split case / case_match 2021-11-16 21:20:43 +07:00
Arthur Baars df3a7ca99b Add test cases 2021-11-16 21:20:43 +07:00
Arthur Baars f7528122d6 Make grammar rules more tree-sitter-like 2021-11-16 21:20:37 +07:00
Arthur Baars 00d4cdc038 Add pattern matching 2021-11-15 08:45:01 +07:00
Gleb Pomykalov 1fedb2a117
wasm32-wasi SDK doesn't support exceptions. This commit disables exceptions when compile for wasm32-wasi. (#192) 2021-10-12 10:20:47 +07:00
Arthur Baars bb6a42e42b
Merge pull request #191 from aibaars/forwarded-args
Add forwarded parameters/arguments
2021-10-11 11:41:26 +07:00
Arthur Baars 95af674ff8 Merge remote-tracking branch 'origin/master' into forwarded-args 2021-10-11 11:14:31 +07:00
Arthur Baars d1171a5085
Merge pull request #190 from aibaars/end-less-methods
Endless methods
2021-10-09 06:36:20 +07:00
Arthur Baars 192ed481ec Add forward_argument to test cases 2021-10-09 06:31:47 +07:00
Arthur Baars 0efc23b7a8 Add forward parameter/argument 2021-10-08 13:32:11 +07:00
Arthur Baars 85ce8b4277 Add tests 2021-10-08 13:16:54 +07:00
Arthur Baars cdc7405ed2 Add end-less method definitions 2021-10-08 13:16:54 +07:00
Arthur Baars 6c5b0f3aa5 Formatting changes 2021-10-07 13:30:23 +07:00
Andrew Helwer 0c1e470822
Fix CRLF behavior mismatch during error recovery (#189)
* Added failing test

* Works

* Made control flow explicit
2021-09-28 14:17:59 +07:00
Andrew Helwer fcb189661c
Fixed CRLF behavior for tests (#188)
* Fixed CRLF behavior for tests

* Add windows tests to CI

* Removed comment about windows tests from CI file

* Run tests on PRs

* Use windows test script in CI
2021-09-24 23:22:28 +07:00
Martin Jambon 391269d74d
Fix hard break in PR template 2021-05-04 14:02:32 +07:00
Martin Jambon 963b7b8b20
Merge pull request #169 from tree-sitter/pr-template
Add the same PR template as for tree-sitter-javascript
2021-04-23 00:42:26 +07:00
Martin Jambon d9c53f29b7 Add the same PR template as for tree-sitter-javascript 2021-04-22 19:02:12 +07:00
Max Brunsfeld dfff673b41 Ignore target directory in npm tarballs 2021-03-28 09:25:28 +07:00
Patrick Thomson a58928e2d7
Merge pull request #166 from tree-sitter/switch-to-gh-actions-ci
Switch to GitHub Actions CI.
2021-03-09 16:12:15 +07:00
Patrick Thomson 6589d79cb3 Don't build on Windows for now. 2021-03-09 15:56:29 +07:00
Patrick Thomson 0a10ae9379 Switch to GitHub Actions CI.
Travis is going away, and Actions can take care of Appveyor's
responsibilities too. I've disabled the webhooks for the
aforementioned services.
2021-03-09 15:49:41 +07:00
Max Brunsfeld fd087c78c7 Update Cargo.toml 2021-03-03 17:04:06 +07:00
Max Brunsfeld fe6a2d634d 0.19.0 2021-03-03 16:54:30 +07:00
Max Brunsfeld 22801a4caa Bump tree-sitter-cli to 0.19 2021-03-03 16:54:25 +07:00
Arthur Baars 32cd5a04ad
Allow multiple statements in interpolation (#163)
* Allow multiple statements in interpolation

* ⬆️ tree-sitter-cli to 0.18.2

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
2021-02-18 16:58:49 +07:00
Nick Rolfe 2503f005d9
Add field names to range (#161) 2021-02-16 07:49:47 +07:00
Nathaniel Brahms 1fa06a9ea8
Prefer element reference over method invocation (#156)
* Prefer element reference over method invocation

Ruby presents two ~syntactic~ sugarings that can not be distinguished
unambiguously from syntax alone:

First, array elements can be referenced using a bracketed argument after
any amount of white space, so:

    x.[](0)

    x[0]

    x [0]

are all equivalent.

Second, methods may be invoked with omitted parends, so:

    f(y)

    f y

are equivalent.

The ambiguity can be seen when the function argument is a literal array:

    f [0]

At this point, there is no syntactic information that can distinguish
between element reference and procedural invocation.

This can be seen by running this program in irb:

    irb(main):001:0> x = [0, 1, 2]
    => [0, 1, 2]
    irb(main):002:0> x.[](0)
    => 0
    irb(main):003:0> x [0]
    => 0
    irb(main):004:0> def y(z)
    irb(main):005:1>   z
    irb(main):006:1> end
    => :y
    irb(main):007:0> y([0])
    => [0]
    irb(main):008:0> y [0]
    => [0]

Previously, tree-sitter-ruby handled this ambiguity by presenting both
`x [0]` and `y [0]` as procedural invocation.

However, this causes a parse error as described in
tree-sitter/tree-sitter-ruby#146, when parsing

    d.find { |x| a(x) } [b] == c

Here I add an optional, lower-precedence interpretation of `x [0]` as an
element reference.

Due to the construction of the grammar in this project, this
unfortunately causes problems when attempting to parse constructs like:

    fun [0] do
      something
    end

as the parser will eagerly consume `fun [0]` as the left-hand-side of
a binary expression. To deal with this case, I explicitly add this
construct to the `call` production rule. Unfortunately I had to resort
to the GLR parser in order to resolve the ambiguity between these two
rules.

Finally, note that the tree obtained from the construct

    z [0] == 0

is context-sensitive in Ruby. If `z` is an array type, it is interpreted
as `binary ( reference ( identifier, integer ), integer`. If `z` is
a method, it is interpreted as `call ( identifier, binary ( array
(integer), integer)`. Since tree-sitter assumes the parsed language is
context-free, there's no good way for us to resolve this ambiguity. This
commit prefers the second, method-invocation, interpretation, which
appears to be more common within the test corpus.

* Use external scanner logic to distinguish between arrays & subscripts

When an opening square bracket appears immediately after a callable
expression like "a" or "a.b", we must decide between two possible
interpretations of the bracket:
1. It could be part of an element reference, as in
   `a[0] = true`.
2. Or it could be an array literal, passed as an argumet, as in
   `puts [1, 2, 3]`

If there is no preceding whitespace, the bracket should *always* be
treated as part of an element reference. This matches MRI's behavior.

If there *is* preceding whitespace, MRI makes its decision in a
context-sensitive way, based on whether the preceding expression
is a local variable or a method name.

This parser is not context-sensitive, so we instead will interpret
the bracket as part of an array literal whenever that is syntactically
valid, and interpret it as part of element reference otherwise. The
external scanner can use the validity of other expression tokens like
`string` to infer whether an array literal would be valid.

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
2021-02-04 16:29:15 +07:00
Arthur Baars ebf6b3dd32
Allow expression to continue after a line-comment (#157) 2021-02-04 14:22:09 +07:00
Nick Rolfe add8cb36d5
Make superclass a field (#159)
* Make superclass a field

* Update test to expect superclass field
2021-01-29 10:43:54 +07:00
Nathaniel Brahms 8fd340fe8b
Support :!~ symbols, add symbol test cases (#153)
* Support :!~ symbols, add symbol test cases

This commit updates the lexer to specifically match the symbol :!~.

I also add test cases from
https://github.com/ruby/spec/blob/master/language/symbol_spec.rb:

- :_
- :!~
- :''

Fixes tree-sitter/tree-sitter-ruby#143.

* fixup! Support :!~ symbols, add symbol test cases
2021-01-22 10:19:21 +07:00
Nathaniel Brahms 6ee7d3869d
Add support for hex character literals (#154)
Per irb:

    irb(main):016:0> ?\xff
    => "\xFF"
    irb(main):017:0> ?\u{024f}
    => "ɏ"
    irb(main):018:0> ?\u024f
    => "ɏ"

Add these test cases and update the character matching regex to enable.

Fixes tree-sitter/tree-sitter-ruby#145.
2021-01-21 09:38:12 +07:00
Nick Rolfe 454f90628d
Separate symbol aliases into distinct types (#152)
* Separate symbol aliases into distinct types

* Rename string_symbol to delimited_symbol

* Rename identifier_hash_key_symbol to hash_key_symbol
2021-01-20 09:59:55 +07:00
Nick Rolfe 8a059c83d1
Fix error parsing hash splat arg followed by another arg (#151) 2021-01-14 09:40:37 +07:00
Nick Rolfe 5021a6a6ed
for-loop pattern improvements (#150)
Trailing commas (accepted by MRI) no longer cause parser errors, e.g.
in:

  for x, in 1..10 do
    puts x
  end

For the following example, with multiple identifiers *not* surrounded by
parentheses, it was awkward to have multiple pattern nodes without an
overall node for the entire `key, value` pattern. Now, there is one.

  for key, value in my_hash do
  end
2021-01-05 07:42:39 +07:00
Pedro Nascimento bb572f60e9
Fix hexadecimal with a capital X (#149) 2020-12-20 12:25:50 +07:00
Pedro Nascimento 53a05110fe
Allow interpolation to be empty (#131) 2020-12-20 12:20:18 +07:00
Nick Rolfe 49c5f6e9cc
Unify call and method_call (#142)
foo.bar and foo.bar() result in the same shape of parse tree, where
previously the latter had an extra level of nesting with a call inside
the method_call. Now they are both just a call.
2020-12-15 12:01:17 +07:00
Max Brunsfeld 694f81cbc5 Fix handling of multi-line interpolations within heredocs
Fixes #140
2020-12-08 09:57:41 +07:00
Nick Rolfe d384ced744
Add operator field name to operator_assignment (#141) 2020-12-08 09:52:52 +07:00
Rick Winfrey 4ba96497dd
Merge pull request #139 from tree-sitter/rational-fix
Support float rational numbers
2020-12-07 12:19:37 +07:00
Rick Winfrey f54547e311 Check in parser 2020-12-07 10:49:13 +07:00
Rick Winfrey 5ebabb6cd4 Add rational number test cases 2020-12-07 10:48:58 +07:00
Rick Winfrey 66f336d817 Support rational floats 2020-12-07 10:40:05 +07:00
Martin Jambon 602b8e2acd
Fix range of characters supported in keyword argument (#137)
* Add failing test case for 'foo(a_:b,)'

* Fix scanner for identifiers followed by a colon.
Fixes https://github.com/tree-sitter/tree-sitter-ruby/issues/136

* First character of identifier can't be a digit
2020-12-07 07:50:56 +07:00
Arthur Baars b92e1f80e5
Correct field for when.pattern (#135) 2020-12-03 09:40:41 +07:00
Patrick Thomson e8d04ec8b6
Merge pull request #133 from nickrolfe/setter_identifier
Give setter identifier a field name
2020-12-02 08:51:18 +07:00