@@ -610,8 +610,8 @@ function ExArg() {
610610// HEREDOC .rlist .op .body
611611// DEF .ea .body .left .rlist .default_args .attr .enddef
612612// ENDDEF .ea
613- // VAR .ea .op .left .list .rest .right .type
614- // FINAL .ea .op .left .list .rest .right .type
613+ // VAR .ea .op .left .list .rest .right .type_str
614+ // FINAL .ea .op .left .list .rest .right .type_str
615615// EXPORT .ea .body
616616// IMPORT .ea .str .left
617617// VIM9SCRIPT .ea
@@ -1513,7 +1513,7 @@ VimLParser.prototype.separate_nextcmd = function() {
15131513 }
15141514 this . reader . getn ( 1 ) ;
15151515 }
1516- else if ( c == "|" || c == "\n" || c == "\"" && ! viml_eqregh ( this . ea . cmd . flags , "\\<NOTRLCOM\\>" ) && ( this . ea . cmd . name != "@" && this . ea . cmd . name != "*" || this . reader . getpos ( ) != this . ea . argpos ) && ( this . ea . cmd . name != "redir" || this . reader . getpos ( ) . i != this . ea . argpos . i + 1 || pc != "@" ) || this . vim9script && c == "#" && ! viml_eqregh ( this . ea . cmd . flags , "\\<NOTRLCOM\\>" ) ) {
1516+ else if ( c == "|" || c == "\n" || c == "\"" && ! viml_eqregh ( this . ea . cmd . flags , "\\<NOTRLCOM\\>" ) && ( this . ea . cmd . name != "@" && this . ea . cmd . name != "*" || this . reader . getpos ( ) != this . ea . argpos ) && ( this . ea . cmd . name != "redir" || this . reader . getpos ( ) . i != this . ea . argpos . i + 1 || pc != "@" ) || this . vim9script && c == "#" && iswhite ( pc ) && ! viml_eqregh ( this . ea . cmd . flags , "\\<NOTRLCOM\\>" ) ) {
15171517 var has_cpo_bar = FALSE ;
15181518 // &cpoptions =~ 'b'
15191519 if ( ( ! has_cpo_bar || ! viml_eqregh ( this . ea . cmd . flags , "\\<USECTRLV\\>" ) ) && pc == "\\" ) {
@@ -2079,19 +2079,20 @@ VimLParser.prototype.parse_cmd_def = function() {
20792079 while ( TRUE ) {
20802080 var varnode = Node ( NODE_IDENTIFIER ) ;
20812081 this . reader . skip_white ( ) ;
2082+ varnode . type_str = "" ;
20822083 // Check for ...name (variadic)
20832084 if ( this . reader . peekn ( 3 ) == "..." ) {
20842085 this . reader . getn ( 3 ) ;
20852086 this . reader . skip_white ( ) ;
2086- var vname = this . reader . read_alpha ( ) ;
2087+ var vname = this . reader . read_word ( ) ;
20872088 varnode . pos = this . reader . getpos ( ) ;
20882089 varnode . value = "..." + vname ;
20892090 // Optionally read type annotation
20902091 this . reader . skip_white ( ) ;
20912092 if ( this . reader . peekn ( 1 ) == ":" ) {
20922093 this . reader . getn ( 1 ) ;
20932094 this . reader . skip_white ( ) ;
2094- this . read_type ( ) ;
2095+ varnode . type_str = this . read_type ( ) ;
20952096 }
20962097 viml_add ( node . rlist , varnode ) ;
20972098 this . reader . skip_white ( ) ;
@@ -2104,7 +2105,7 @@ VimLParser.prototype.parse_cmd_def = function() {
21042105 }
21052106 }
21062107 var npos = this . reader . getpos ( ) ;
2107- var pname = this . reader . read_alpha ( ) ;
2108+ var pname = this . reader . read_word ( ) ;
21082109 if ( pname == "" ) {
21092110 if ( this . reader . peekn ( 1 ) == ")" ) {
21102111 this . reader . getn ( 1 ) ;
@@ -2124,7 +2125,7 @@ VimLParser.prototype.parse_cmd_def = function() {
21242125 if ( this . reader . peekn ( 1 ) == ":" ) {
21252126 this . reader . getn ( 1 ) ;
21262127 this . reader . skip_white ( ) ;
2127- this . read_type ( ) ;
2128+ varnode . type_str = this . read_type ( ) ;
21282129 }
21292130 // Check for default value
21302131 this . reader . skip_white ( ) ;
@@ -2394,8 +2395,32 @@ VimLParser.prototype.parse_cmd_import = function() {
23942395 node . left = NIL ;
23952396 node . str = "" ;
23962397 this . reader . skip_white ( ) ;
2397- // Read the rest of the import line as a string (import autoload 'path' or import 'path' as Name)
2398- node . str = this . reader . getn ( - 1 ) ;
2398+ // Read the rest of the import line, stopping at a trailing comment.
2399+ var line = "" ;
2400+ var pending_ws = "" ;
2401+ var last_was_white = FALSE ;
2402+ while ( TRUE ) {
2403+ var c = this . reader . peekn ( 1 ) ;
2404+ if ( c == "" ) {
2405+ break ;
2406+ }
2407+ if ( c == "#" && last_was_white ) {
2408+ // Consume the rest of the line, so parse_trail doesn't see it.
2409+ this . reader . getn ( - 1 ) ;
2410+ break ;
2411+ }
2412+ this . reader . getn ( 1 ) ;
2413+ if ( iswhite ( c ) ) {
2414+ pending_ws += c ;
2415+ var last_was_white = TRUE ;
2416+ }
2417+ else {
2418+ line += pending_ws + c ;
2419+ var pending_ws = "" ;
2420+ var last_was_white = FALSE ;
2421+ }
2422+ }
2423+ node . str = line ;
23992424 this . add_node ( node ) ;
24002425}
24012426
@@ -5725,6 +5750,9 @@ Compiler.prototype.compile_var = function(node) {
57255750 }
57265751 var left = "(" + left + ")" ;
57275752 }
5753+ if ( node . type_str != "" ) {
5754+ left += ": " + node . type_str ;
5755+ }
57285756 var right = this . compile ( node . right ) ;
57295757 this . out ( "(var %s %s %s)" , node . op , left , right ) ;
57305758}
@@ -5741,6 +5769,9 @@ Compiler.prototype.compile_final = function(node) {
57415769 }
57425770 var left = "(" + left + ")" ;
57435771 }
5772+ if ( node . type_str != "" ) {
5773+ left += ": " + node . type_str ;
5774+ }
57445775 var right = this . compile ( node . right ) ;
57455776 this . out ( "(final %s %s %s)" , node . op , left , right ) ;
57465777}
0 commit comments