summaryrefslogtreecommitdiff
path: root/src/wast-parser.cc
diff options
context:
space:
mode:
authorJacob Gravelle <jgravelle@google.com>2019-05-07 22:30:07 -0700
committerBen Smith <binji@chromium.org>2019-05-07 22:30:07 -0700
commit0af114943e38a0c0a4ccb0b49b4a8fb07d1bd056 (patch)
tree9bd7bc7a9b44355fcd7d4269c9f7c461f457534f /src/wast-parser.cc
parentf46149231522736d909c7c18d6fd2471ec53393f (diff)
downloadwabt-0af114943e38a0c0a4ccb0b49b4a8fb07d1bd056.tar.gz
wabt-0af114943e38a0c0a4ccb0b49b4a8fb07d1bd056.tar.bz2
wabt-0af114943e38a0c0a4ccb0b49b4a8fb07d1bd056.zip
Initial custom annotation support (#1076)
Lex custom annotations, but discard them in the parser. In the future we should be able to parse some of them, but this is simple and spec-compliant for now.
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r--src/wast-parser.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 209773cc..63929706 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -391,8 +391,35 @@ Location WastParser::GetLocation() {
}
TokenType WastParser::Peek(size_t n) {
- while (tokens_.size() <= n)
- tokens_.push_back(lexer_->GetToken(this));
+ while (tokens_.size() <= n) {
+ Token cur = lexer_->GetToken(this);
+ if (cur.token_type() != TokenType::LparAnn) {
+ tokens_.push_back(cur);
+ } else {
+ // Custom annotation. For now, discard until matching Rpar
+ if (!options_->features.annotations_enabled()) {
+ Error(cur.loc, "annotations not enabled: %s", cur.to_string().c_str());
+ return TokenType::Invalid;
+ }
+ int indent = 1;
+ while (indent > 0) {
+ cur = lexer_->GetToken(this);
+ switch (cur.token_type()) {
+ case TokenType::Lpar:
+ case TokenType::LparAnn:
+ indent++;
+ break;
+
+ case TokenType::Rpar:
+ indent--;
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ }
return tokens_.at(n).token_type();
}