Extract out to scan_bracket_argument function

This commit is contained in:
Uy Ha 2021-06-26 22:52:19 +02:00
parent 3b2b47dbaa
commit 06d75be374
2 changed files with 12 additions and 8 deletions

View file

@ -24,3 +24,7 @@ message(STATUS #[[Some comment]] "comment is next" #[[Some comment]])
(comment (bracket_argument))
)
)
======================
Line comment [comment]
======================

View file

@ -3,16 +3,11 @@
#include <tree_sitter/parser.h>
namespace {
enum TokenType { BRACKET_ARGUMENT };
enum TokenType { BRACKET_ARGUMENT, LINE_COMMENT };
void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
bool scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
using std::iswspace;
if (!valid_symbols[BRACKET_ARGUMENT])
return false;
while (iswspace(lexer->lookahead))
bool scan_bracket_argument(TSLexer *lexer) {
while (std::iswspace(lexer->lookahead))
skip(lexer);
if (lexer->lookahead != '[')
@ -47,6 +42,11 @@ bool scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
}
}
}
return false;
}
bool scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
if (valid_symbols[BRACKET_ARGUMENT])
return scan_bracket_argument(lexer);
return false;
}