Skip to content

Commit

Permalink
feat(vimparser): update to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcco committed Jun 26, 2023
1 parent 420a797 commit f6e1808
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vim-language-server",
"version": "2.3.0",
"version": "2.3.1",
"description": "vim language server",
"keywords": [
"viml",
Expand Down
34 changes: 31 additions & 3 deletions src/lib/vimparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,12 +1805,14 @@ VimLParser.prototype.parse_cmd_call = function() {
this.add_node(node);
}

VimLParser.prototype.parse_heredoc = function() {
VimLParser.prototype.parse_heredoc = function(prefix) {
var node = Node(NODE_HEREDOC);
node.pos = this.ea.cmdpos;
node.op = "";
node.rlist = [];
node.body = [];
// allow prefix to precede heredoc end marker if true
var is_trim = FALSE;
while (TRUE) {
this.reader.skip_white();
var pos = this.reader.getpos();
Expand All @@ -1827,6 +1829,9 @@ VimLParser.prototype.parse_heredoc = function() {
keynode.pos = pos;
keynode.value = key;
viml_add(node.rlist, keynode);
if (key == "trim") {
var is_trim = TRUE;
}
}
}
if (node.op == "") {
Expand All @@ -1839,7 +1844,7 @@ VimLParser.prototype.parse_heredoc = function() {
}
var pos = this.reader.getpos();
var line = this.reader.getn(-1);
if (line == node.op) {
if (line == node.op || is_trim && line == prefix + node.op) {
return node;
}
var linenode = Node(NODE_STRING);
Expand Down Expand Up @@ -1894,7 +1899,30 @@ VimLParser.prototype.parse_cmd_let = function() {
this.reader.getn(viml_len(s2));
this.reader.skip_white();
node.op = s2;
node.right = this.parse_heredoc();
// compute allowed prefix for heredoc end marker (e.g. EOF)
var pos = this.reader.tell();
while (this.reader.tell() > 0) {
if (this.reader.peek() == "<EOL>") {
this.reader.seek_cur(1);
break;
}
this.reader.seek_cur(-1);
}
var prefix = "";
while (TRUE) {
var c = this.reader.getn(1);
if (c == ":") {
// any presence of leading ':' disables prefix for heredoc end marker
var prefix = "";
break;
}
else if (!iswhite(c)) {
break;
}
prefix += c;
}
this.reader.seek_set(pos);
node.right = this.parse_heredoc(prefix);
this.add_node(node);
return;
}
Expand Down

0 comments on commit f6e1808

Please sign in to comment.