Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2064)

Unified Diff: mojom/mojom_parser/lexer/token_stream.go

Issue 1593543004: Update the mojom lexer to emit comment tokens. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojom/mojom_parser/lexer/token_stream.go
diff --git a/mojom/mojom_parser/lexer/token_stream.go b/mojom/mojom_parser/lexer/token_stream.go
index beb399a164ca443a0f9293736706e7b1e124be01..9b2ec422afb1eec4f92c8ffde76516fb04eddb35 100644
--- a/mojom/mojom_parser/lexer/token_stream.go
+++ b/mojom/mojom_parser/lexer/token_stream.go
@@ -49,3 +49,38 @@ func (s *TokenChan) ConsumeNext() {
s.nextToken = eofToken
}
}
+
+// *FilteredTokenStream implements TokenStream
+// This implementation uses an underlying implementation of TokenStream, but
+// it implements a TokenKind blacklist. All tokens of the blacklisted TokenKinds
+// will be silently dropped.
+type FilteredTokenStream struct {
+ // tokenStream is the underlying TokenStream that is the data source.
+ tokenStream TokenStream
+ // blacklist contains the TokenKinds that should be skipped in the source
+ // TokenStream.
+ blacklist map[TokenKind]bool
+}
+
+// See TokenStream.
+func (s *FilteredTokenStream) PeekNext() (token Token) {
+ for t := s.tokenStream.PeekNext(); s.isBlacklisted(t); s.tokenStream.ConsumeNext() {
rudominer 2016/01/16 01:08:58 Shouldn't there be some condition here for end-of-
azani 2016/01/20 00:00:11 No. isBlacklisted always returns false if the unde
+ }
+
+ return s.tokenStream.PeekNext()
+}
+
+// See TokenStream.
+func (s *FilteredTokenStream) ConsumeNext() {
+ s.tokenStream.ConsumeNext()
+}
+
+// isBlacklisted checks if a Token is of a blacklisted TokenKind.
+func (s *FilteredTokenStream) isBlacklisted(token Token) bool {
+ // We don't allow blacklisting EOF since that would cause an infinite loop.
+ if token.Kind == EOF {
+ return false
+ }
+ _, ok := s.blacklist[token.Kind]
+ return ok
+}

Powered by Google App Engine
This is Rietveld 408576698