Skip to content

Incorrect parsing of (concatenation (simple_expansion) (word)) when word begins with } #241

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

Closed
aarondill opened this issue Jan 22, 2024 · 4 comments

Comments

@aarondill
Copy link

Given a snippet like v=$hello}/world (which assigns the value of hello, followed by the literal }/world)
It is parsed as this (using TSPlayground):

program [0, 0] - [1, 0]
  variable_assignment [0, 0] - [0, 15]
    name: variable_name [0, 0] - [0, 1]
    value: concatenation [0, 2] - [0, 15]
      simple_expansion [0, 2] - [0, 8]
        variable_name [0, 3] - [0, 8]
      word [0, 9] - [0, 15]

Assuming the concatenation node is stored in concatNode:

console.log(concatNode.text) // $hello}/world
console.log(concatNode.namedChildren[0].text) // $hello
console.log(concatNode.namedChildren[0].type) // simple_expansion

console.log(concatNode.namedChildren[1].type) // word
// This should begin with the literal bracket!
console.log(concatNode.namedChildren[1].text) // /world

Looking at the start and ending positions, it seems the } is mistakenly included in the simple_expansion, but somehow isn't included in it's text value (and shouldn't be!)

@aarondill
Copy link
Author

aarondill commented Jan 22, 2024

the snippet I originally discovered this with was . $utils}/hello || exit
Assuming the concatenation node is node, running the following testing snippet results in the following output:

testing snippet
  log(`node: ${node}`)
  log(`node.type: ${node?.type}`)
  log(`node.text: ${node?.text}`)
  log(`node.startPosition.column: ${node?.startPosition.column}`)
  log(`node.endPosition.column: ${node?.endPosition.column}`)
  log(``)
  for (let i = 0; i < node.childCount; i++) {
    const child = node.child(i)
    log(`child(${i}): ${child}`)
    log(`child(${i}).type: ${child?.type}`)
    log(`child(${i}).text: ${child?.text}`)
    log(`child(${i}).startPosition.column: ${child?.startPosition.column}`)
    log(`child(${i}).endPosition.column: ${child?.endPosition.column}`)
    log(``)
  }
node: (concatenation (simple_expansion (variable_name)) (word))
node.type: concatenation
node.text: $utils}/hello
node.startPosition.column: 2
node.endPosition.column: 15

child(0): (simple_expansion (variable_name))
child(0).type: simple_expansion
child(0).text: $utils
child(0).startPosition.column: 2
child(0).endPosition.column: 8

child(1): (word)
child(1).type: word
child(1).text: /hello
child(1).startPosition.column: 9
child(1).endPosition.column: 15

@amaanq
Copy link
Member

amaanq commented Feb 10, 2024

hm, i cant comment on your js code, but the parse tree output looks good on my end:

image

@amaanq amaanq closed this as completed Feb 10, 2024
@aarondill
Copy link
Author

aarondill commented Feb 10, 2024

You're correct. I'm sorry for wasting your time.
I was working on a patch for bash-language-server and came across this issue.
I (mistakenly) believed they were using an up-to-date version of this parser, but it turns out it is 198(!) commits out of date.
It seems I just need to wait until bash-lsp/bash-language-server#943 gets resolved.

@amaanq
Copy link
Member

amaanq commented Feb 10, 2024

no worries there are so many changes (and more coming soon!), that i cant blame them for not updating yet

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