Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Add method call expression support #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Fymyte
Copy link
Collaborator

@Fymyte Fymyte commented Sep 12, 2022

No description provided.

@Fymyte Fymyte force-pushed the feat/method-expression branch from ecc2792 to c174b20 Compare September 12, 2022 02:20
@@ -103,6 +103,7 @@ module.exports = grammar({
[$.binary_operation, $.unary_operation, $.field_expression],
[$.binary_operation, $.field_expression],
[$.list, $._pattern_atom],
[$._ident, $.lambda_expression],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this 'eeded now and was not needed before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I get a conflict

Unresolved conflict for symbol sequence:
  _function  '{'  identifier  •  '->'  …
Possible interpretations:
  1:  _function  '{'  (_ident  identifier)  •  '->'  …
  2:  _function  (lambda_expression  '{'  identifier  •  '->'  _expression  '}')

I don't exactly know where a '{' identifier '->' is allowed elsewhere than in lambda, but it doesn't know if it should consider the identifier as part of lambda expression or the name of the method expression

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it might be because of the braces expansions then.

There must be another place where this kind of conflict is handled.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need double braces in a brace expansion if we use a lambda within it

let Function_name = {-> 'hello'}
echo Function_{{-> 'name'}()}()

also an identifier needs to immediately follow a -> for it to be considered part of the method call. :h E274

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found where the conflict was coming from and why we didn't get it before.
By adding method_expression, we allowed the syntax

'{' _ident -> ... '}'

twice for an expression. One in lamda_expression and the other as a single curly_brace expression identifier

_ident (identifier (_curly_brace_name_expression '{' (method_expression _ident '->' _expression  '}' ))

Allow only lambda and identifier in method
@Fymyte Fymyte force-pushed the feat/method-expression branch from 3a63629 to bdc3772 Compare February 12, 2023 14:02
@ad-chaos
Copy link

call F()->G() seems to generate an error node.

@Fymyte
Copy link
Collaborator Author

Fymyte commented Feb 12, 2023

call F()->G() seems to generate an error node.

From what I understand of :h E132 this is not a supported syntax.

eval F()->G()

Seems to be parsed properly

@ad-chaos
Copy link

contrived example of valid vimscipt.

func Hello()
    return 'hello'
endfunc

func Print(arg)
    echo a:arg
endfunc

call Hello()->Print()

@Fymyte Fymyte force-pushed the feat/method-expression branch from 81a1ae8 to 485a500 Compare February 12, 2023 17:30
@Fymyte Fymyte force-pushed the feat/method-expression branch from 485a500 to 0bd25f8 Compare February 12, 2023 17:33
@Fymyte
Copy link
Collaborator Author

Fymyte commented Feb 12, 2023

Hmm
I understand why it works but I don't know how we are supposed to handle it.
In the manual, a call statement is call {name}([arguments]), so the ([args]) is part of the statement.
For method calls, ([args]) seems to also be part of the method_call expression.

We could allow both call_expression and method_expression in a call_statement @vigoux what do you think ?

@Fymyte
Copy link
Collaborator Author

Fymyte commented Feb 12, 2023

@ad-chaos This should work properly now, I will just for vigoux to validate

@Fymyte
Copy link
Collaborator Author

Fymyte commented Feb 12, 2023

With this PR we are 1 step closer to parse the vim runtime.
This code is parsed without error now

func s:DecodeMessage(quotedText)
  if a:quotedText[0] != '"'
    echoerr 'DecodeMessage(): missing quote in ' . a:quotedText
    return
  endif
  return a:quotedText
        \ ->substitute('^"\|".*\|\\n', '', 'g')
        \ ->substitute('\\t', "\t", 'g')
        \ ->substitute('\\000', s:NullRepl, 'g')
        \ ->substitute('\\\o\o\o', {-> eval('"' .. submatch(0) .. '"')}, 'g')
        \ ->substitute('\\\\', '\', 'g')
        \ ->substitute(s:NullRepl, '\\000', 'g')
endfunc

But adding a comment between the method call lines breaks.

func s:DecodeMessage(quotedText)
  return a:quotedText
        \ ->substitute('^"\|".*\|\\n', '', 'g')
        " this is a comment
        \ ->substitute('\\t', "\t", 'g')
endfunc

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

Successfully merging this pull request may close these issues.

None yet

3 participants