Remove interpolation and look_for_heredoc_end
@@ -40,7 +40,6 @@ struct Scanner {
enum ScanContentResult {
Error,
- Interpolation,
End
};
@@ -214,7 +213,6 @@ struct Scanner {
if (open_heredocs.empty()) return Error;
Heredoc heredoc = open_heredocs.front();
size_t position_in_word = 0;
- bool look_for_heredoc_end = true;
for (;;) {
if (position_in_word == heredoc.word.size()) {
@@ -229,36 +227,16 @@ struct Scanner {
return End;
}
- if (lexer->lookahead == heredoc.word[position_in_word] && look_for_heredoc_end) {
+ if (lexer->lookahead == heredoc.word[position_in_word]) {
advance(lexer);
position_in_word++;
} else {
position_in_word = 0;
- look_for_heredoc_end = false;
- if (lexer->lookahead == '#') {
advance(lexer);
- if (lexer->lookahead == '{') {
- advance(lexer);
- return Interpolation;
- }
- } else if (lookahead_is_line_end(lexer)) {
- advance(lexer);
- look_for_heredoc_end = true;
- while (lexer->lookahead == ' ' || lexer->lookahead == '\t') {
- advance(lexer);
- if (!heredoc.end_word_indentation_allowed) {
- look_for_heredoc_end = false;
- }
- }
- } else {
- advance(lexer);
- }
}
}
}
-
-
bool scan(TSLexer *lexer, const bool *valid_symbols) {
has_leading_whitespace = false;
bool found_heredoc_starting_linebreak = false;
@@ -267,33 +245,41 @@ struct Scanner {
if (lexer->result_symbol == LINE_BREAK) return true;
if (valid_symbols[HEREDOC_BODY_MIDDLE] && !open_heredocs.empty()) {
- if (scan_interpolation_close(lexer)) {
switch (scan_heredoc_content(lexer)) {
case Error:
return false;
- case Interpolation:
- lexer->result_symbol = HEREDOC_BODY_MIDDLE;
- return true;
case End:
lexer->result_symbol = HEREDOC_BODY_END;
return true;
}
}
- }
if (valid_symbols[HEREDOC_BODY_BEGINNING] && !open_heredocs.empty() && found_heredoc_starting_linebreak) {
switch (scan_heredoc_content(lexer)) {
case Error:
return false;
- case Interpolation:
- lexer->result_symbol = HEREDOC_BODY_BEGINNING;
- return true;
case End:
lexer->result_symbol = SIMPLE_HEREDOC_BODY;
return true;
}
}
+ if (lexer->lookahead == '<') {
+ advance(lexer);
+ if (lexer->lookahead != '<') return false;
+ advance(lexer);
+ if (lexer->lookahead != '<') return false;
+ advance(lexer);
+
+ // Found a heredoc
+ Heredoc heredoc;
+ heredoc.word = scan_heredoc_word(lexer);
+ if (heredoc.word.empty()) return false;
+ open_heredocs.push_back(heredoc);
+ lexer->result_symbol = HEREDOC_BEGINNING;
+ return true;
+ }
+
return false;
}
