Skip to content

Commit cd07c10

Browse files
committed
fix region after trivia start
1 parent deb8bfb commit cd07c10

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

crates/emmylua_parser/src/grammar/doc/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ fn parse_docs(p: &mut LuaDocParser) {
5757
p.bump();
5858
parse_continue_or(p);
5959
}
60+
LuaTokenKind::TKDocTriviaStart => {
61+
p.bump();
62+
}
6063
_ => {
6164
p.bump();
6265
}
6366
}
6467

6568
if let Some(reader) = &p.lexer.reader {
6669
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+
)
6974
{
7075
p.bump_to_end();
7176
continue;

crates/emmylua_parser/src/grammar/doc/test.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,4 +1895,40 @@ Syntax(Chunk)@0..90
18951895

18961896
assert_ast_eq!(code, result);
18971897
}
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+
}
18981934
}

crates/emmylua_parser/src/kind/lua_token_kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub enum LuaTokenKind {
8282
TkLongCommentStart, // --[[
8383
TkDocLongStart, // --[[@
8484
TkDocStart, // ---@
85+
TKDocTriviaStart, // --------------
8586
TkDocTrivia, // other can not parsed
8687
TkLongCommentEnd, // ]] or ]===]
8788

crates/emmylua_parser/src/lexer/lua_doc_lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl LuaDocLexer<'_> {
123123
}
124124
_ => {
125125
reader.eat_while(|_| true);
126-
LuaTokenKind::TkDocTrivia
126+
LuaTokenKind::TKDocTriviaStart
127127
}
128128
}
129129
}

crates/emmylua_parser/src/parser/lua_doc_parser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ impl LuaDocParser<'_, '_> {
9898
self.eat_current_and_lex_next();
9999
}
100100
}
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+
}
101109
_ => {}
102110
}
103111
}

0 commit comments

Comments
 (0)