File tree Expand file tree Collapse file tree 5 files changed +53
-3
lines changed
crates/emmylua_parser/src Expand file tree Collapse file tree 5 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -57,15 +57,20 @@ fn parse_docs(p: &mut LuaDocParser) {
57
57
p. bump ( ) ;
58
58
parse_continue_or ( p) ;
59
59
}
60
+ LuaTokenKind :: TKDocTriviaStart => {
61
+ p. bump ( ) ;
62
+ }
60
63
_ => {
61
64
p. bump ( ) ;
62
65
}
63
66
}
64
67
65
68
if let Some ( reader) = & p. lexer . reader {
66
69
if !reader. is_eof ( )
67
- && p. current_token ( ) != LuaTokenKind :: TkDocStart
68
- && p. current_token ( ) != LuaTokenKind :: TkDocLongStart
70
+ && !matches ! (
71
+ p. current_token( ) ,
72
+ LuaTokenKind :: TkDocStart | LuaTokenKind :: TkDocLongStart
73
+ )
69
74
{
70
75
p. bump_to_end ( ) ;
71
76
continue ;
Original file line number Diff line number Diff line change @@ -1895,4 +1895,40 @@ Syntax(Chunk)@0..90
1895
1895
1896
1896
assert_ast_eq ! ( code, result) ;
1897
1897
}
1898
+
1899
+ #[ test]
1900
+ fn test_region_with_comment ( ) {
1901
+ let code = r#"
1902
+ -----------
1903
+ --region hhhh
1904
+ --comment
1905
+ --endregion
1906
+ "# ;
1907
+
1908
+ let result = r#"
1909
+ Syntax(Chunk)@0..89
1910
+ Syntax(Block)@0..89
1911
+ Token(TkEndOfLine)@0..1 "\n"
1912
+ Token(TkWhitespace)@1..9 " "
1913
+ Syntax(Comment)@9..80
1914
+ Token(TKDocTriviaStart)@9..20 "-----------"
1915
+ Token(TkEndOfLine)@20..21 "\n"
1916
+ Token(TkWhitespace)@21..29 " "
1917
+ Token(TkDocTrivia)@29..31 "--"
1918
+ Token(TkDocTrivia)@31..42 "region hhhh"
1919
+ Token(TkEndOfLine)@42..43 "\n"
1920
+ Token(TkWhitespace)@43..51 " "
1921
+ Token(TkNormalStart)@51..53 "--"
1922
+ Syntax(DocDescription)@53..71
1923
+ Token(TkDocDetail)@53..60 "comment"
1924
+ Token(TkEndOfLine)@60..61 "\n"
1925
+ Token(TkWhitespace)@61..69 " "
1926
+ Token(TkNormalStart)@69..71 "--"
1927
+ Token(TkDocEndRegion)@71..80 "endregion"
1928
+ Token(TkEndOfLine)@80..81 "\n"
1929
+ Token(TkWhitespace)@81..89 " "
1930
+ "# ;
1931
+
1932
+ assert_ast_eq ! ( code, result) ;
1933
+ }
1898
1934
}
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ pub enum LuaTokenKind {
82
82
TkLongCommentStart , // --[[
83
83
TkDocLongStart , // --[[@
84
84
TkDocStart , // ---@
85
+ TKDocTriviaStart , // --------------
85
86
TkDocTrivia , // other can not parsed
86
87
TkLongCommentEnd , // ]] or ]===]
87
88
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ impl LuaDocLexer<'_> {
123
123
}
124
124
_ => {
125
125
reader. eat_while ( |_| true ) ;
126
- LuaTokenKind :: TkDocTrivia
126
+ LuaTokenKind :: TKDocTriviaStart
127
127
}
128
128
}
129
129
}
Original file line number Diff line number Diff line change @@ -98,6 +98,14 @@ impl LuaDocParser<'_, '_> {
98
98
self . eat_current_and_lex_next ( ) ;
99
99
}
100
100
}
101
+ LuaDocLexerState :: Init => {
102
+ while matches ! (
103
+ self . current_token,
104
+ LuaTokenKind :: TkEndOfLine | LuaTokenKind :: TkWhitespace
105
+ ) {
106
+ self . eat_current_and_lex_next ( ) ;
107
+ }
108
+ }
101
109
_ => { }
102
110
}
103
111
}
You can’t perform that action at this time.
0 commit comments