tree-sitter-viml icon indicating copy to clipboard operation
tree-sitter-viml copied to clipboard

Add method call expression support

Open Fymyte opened this issue 2 years ago • 6 comments

Fymyte avatar Sep 12 '22 02:09 Fymyte

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

ad-chaos avatar Feb 12 '23 16:02 ad-chaos

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

Fymyte avatar Feb 12 '23 17:02 Fymyte

contrived example of valid vimscipt.

func Hello()
    return 'hello'
endfunc

func Print(arg)
    echo a:arg
endfunc

call Hello()->Print()

ad-chaos avatar Feb 12 '23 17:02 ad-chaos

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 avatar Feb 12 '23 17:02 Fymyte

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

Fymyte avatar Feb 12 '23 17:02 Fymyte

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

Fymyte avatar Feb 12 '23 18:02 Fymyte