@@ -68,16 +68,8 @@ bool LuaTokenParser::Parse()
6868
6969 if (!text.empty ())
7070 {
71- if (type == TK_LONG_COMMENT || type == TK_SHEBANG || type == TK_SHORT_COMMENT)
72- {
73- _commentTokens.emplace_back (type, text, TextRange (
74- static_cast <int >(_buffStart), static_cast <int >(_buffIndex)));
75- }
76- else
77- {
78- _tokens.emplace_back (type, text, TextRange (
79- static_cast <int >(_buffStart), static_cast <int >(_buffIndex)));
80- }
71+ _tokens.emplace_back (type, text, TextRange (
72+ static_cast <int >(_buffStart), static_cast <int >(_buffIndex)));
8173 }
8274 else
8375 {
@@ -119,6 +111,37 @@ LuaToken& LuaTokenParser::LookAhead()
119111}
120112
121113LuaToken& LuaTokenParser::Current ()
114+ {
115+ if (_currentIndex < _tokens.size ())
116+ {
117+ do
118+ {
119+ switch (_tokens[_currentIndex].TokenType )
120+ {
121+ case TK_DOC_COMMENT:
122+ case TK_SHORT_COMMENT:
123+ case TK_LONG_COMMENT:
124+ case TK_SHEBANG:
125+ {
126+ _commentTokens.push_back (_tokens[_currentIndex]);
127+ Next ();
128+ break ;
129+ }
130+ default :
131+ {
132+ goto endLoop;
133+ }
134+ }
135+ }
136+ while (true );
137+ endLoop:
138+ return _tokens[_currentIndex];
139+ }
140+
141+ return _eosToken;
142+ }
143+
144+ LuaToken& LuaTokenParser::CurrentWithComment ()
122145{
123146 if (_currentIndex < _tokens.size ())
124147 {
@@ -228,6 +251,7 @@ LuaTokenType LuaTokenParser::Lex()
228251 // is comment
229252 SaveAndNext ();
230253
254+ LuaTokenType type = TK_SHORT_COMMENT;
231255 if (GetCurrentChar () == ' [' )
232256 {
233257 std::size_t sep = SkipSep ();
@@ -237,14 +261,19 @@ LuaTokenType LuaTokenParser::Lex()
237261 return TK_LONG_COMMENT;
238262 }
239263 }
264+ else if (GetCurrentChar () == ' -' )
265+ {
266+ SaveAndNext ();
267+ type = TK_DOC_COMMENT;
268+ }
240269
241270 // is short comment
242271 while (!CurrentIsNewLine () && GetCurrentChar () != EOZ)
243272 {
244273 SaveAndNext ();
245274 }
246275
247- return TK_SHORT_COMMENT ;
276+ return type ;
248277 }
249278 case ' [' :
250279 {
@@ -343,7 +372,7 @@ LuaTokenType LuaTokenParser::Lex()
343372 }
344373 case ' "' :
345374 case ' \' ' :
346- // extend support
375+ // extend support
347376 case ' `' :
348377 {
349378 ReadString (ch);
@@ -812,6 +841,17 @@ bool LuaTokenParser::IsReserved(std::string_view text)
812841 return LuaReserved.find (text) != LuaReserved.end ();
813842}
814843
844+ bool LuaTokenParser::IsInlineComment ()
845+ {
846+ if (_tokens.empty ())
847+ {
848+ return false ;
849+ }
850+
851+ auto lastTokenLine = _file->GetLine (_tokens.back ().Range .EndOffset );
852+ return _file->GetLine (static_cast <int >(_buffStart)) == lastTokenLine;
853+ }
854+
815855void LuaTokenParser::PushLuaError (std::string_view message, TextRange range)
816856{
817857 _errors.emplace_back (message, range);
0 commit comments