From f6e1808e441c64f47f6fb86886eb9ad5a4e74156 Mon Sep 17 00:00:00 2001 From: iamcco Date: Mon, 26 Jun 2023 14:13:57 +0800 Subject: [PATCH] feat(vimparser): update to latest version --- package.json | 2 +- src/lib/vimparser.js | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3de1092..bbc996c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vim-language-server", - "version": "2.3.0", + "version": "2.3.1", "description": "vim language server", "keywords": [ "viml", diff --git a/src/lib/vimparser.js b/src/lib/vimparser.js index 1efd4f3..91fc9c0 100644 --- a/src/lib/vimparser.js +++ b/src/lib/vimparser.js @@ -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(); @@ -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 == "") { @@ -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); @@ -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() == "") { + 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; }