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

Method calls on non-variables #11

Open
will opened this issue Sep 3, 2021 · 2 comments
Open

Method calls on non-variables #11

will opened this issue Sep 3, 2021 · 2 comments

Comments

@will
Copy link
Owner

will commented Sep 3, 2021

Hey @spencerwi I've been trying to get like 3.to_s or [1,2,3].first to work, and I think what needs to change is

     property: $ => seq(
-        field('object', $._variable),
+        field('object', $._expression),
         '.',
        field('name', alias(/[a-z][a-z0-9_]*[\?!]?/, $.identifier)),
    ),

since I think you can call a method on the result of any expression (though this might be wrong).

This change causes precedent problems with $assignment , so I'm not sure if I'm on the right track. Do you have ideas on what should be done?

@will
Copy link
Owner Author

will commented Sep 3, 2021

Hm, maybe something like this?

@@ -383,8 +383,8 @@ module.exports = grammar({
         $.index_expression,
         $.property
       );
-      return prec.right(seq(
-        commaSep1(field('lhs', target)),
+      return prec.right(2, seq(
+        prec.right(1, commaSep1(field('lhs', target))),
         optional(field('type', $._typeAnnotation)),
         /=/,
         field('rhs', choice($._variable, $._expression))

@spencerwi
Copy link
Collaborator

Yeah, function calls are definitely the part that's hardest to work through. I've taken a couple of attempts at trying to support "bare" function calls (like puts "test hello" or getter :my_attr), with no real success so far - precedence conflicts happen like crazy. I've been trying to pin down places where whitespace shouldn't be allowed to try to avoid some of the conflicts I see when I poke at it.

I wonder if it's worth trying to adapt the tree-sitter grammar for ruby here...could be worth a shot.

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

No branches or pull requests

2 participants