From bc0b3f1eb03ada1dcbd77dd65f308bb04c146761 Mon Sep 17 00:00:00 2001 From: mhoffm Date: Sat, 26 Jun 2021 10:31:33 +0200 Subject: [PATCH] wip make sure that heredoc identifier sits on a line of its own --- README.md | 7 +------ src/scanner.cc | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index af8c4ed..64c5e64 100644 --- a/README.md +++ b/README.md @@ -20,15 +20,10 @@ To run tests simply run `nix-shell --run 'tree-sitter test'`. The directory `example/real_world_stuff` contains a corpus of hcl files that I found with the github query `language:HCL` for users `coreos`, `hashicorp`, `oracle` and `terraform-community-modules`. -Given that some language features are still missing ( see TODO ) there are some expected parse errors: - ```bash tree-sitter parse --quiet --stat example/real_world_stuff/*/* -example/real_world_stuff/oracle/oracle%opengrok%opengrok-indexer%src%test%resources%analysis%terraform%sample.tf 1 ms (ERROR [205, 8] - [214, 1]) - -Total parses: 2015; successful parses: 2014; failed parses: 1; success percentage: 99.95% - +Total parses: 1892; successful parses: 1892; failed parses: 0; success percentage: 100.00% ``` The aim is to build unit testcases from selected failure classes and slowly get to 100%. diff --git a/src/scanner.cc b/src/scanner.cc index 1df062c..337e49a 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -137,8 +137,19 @@ public: return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK); } } - context_stack.pop_back(); - return accept_and_advance(lexer, HEREDOC_IDENTIFIER); + // check if the identifier is on a line of its own + lexer->mark_end(lexer); + while (iswspace(lexer->lookahead) && lexer->lookahead != '\n') { + advance(lexer); + } + if (lexer->lookahead == '\n') { + context_stack.pop_back(); + return accept_and_advance(lexer, HEREDOC_IDENTIFIER); + } else { + advance(lexer); + lexer->mark_end(lexer); + return accept_inplace(lexer, TEMPLATE_LITERAL_CHUNK); + } } // manage template literal chunks