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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojom/mojom_parser/lexer/lexer_test.go ('k') | mojom/mojom_parser/lexer/tokens.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // TokenStream is the interface between the lexer and the parser. The lexer 5 // TokenStream is the interface between the lexer and the parser. The lexer
6 // creates a TokenStream which the parser consumes. 6 // creates a TokenStream which the parser consumes.
7 7
8 package lexer 8 package lexer
9 9
10 type TokenStream interface { 10 type TokenStream interface {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 // See TokenStream. 44 // See TokenStream.
45 func (s *TokenChan) ConsumeNext() { 45 func (s *TokenChan) ConsumeNext() {
46 if t, open := <-s.tokenChan; open { 46 if t, open := <-s.tokenChan; open {
47 s.nextToken = t 47 s.nextToken = t
48 } else { 48 } else {
49 s.nextToken = eofToken 49 s.nextToken = eofToken
50 } 50 }
51 } 51 }
52
53 // *FilteredTokenStream implements TokenStream
54 // This implementation uses an underlying implementation of TokenStream, but
55 // it implements a TokenKind blacklist. All tokens of the blacklisted TokenKinds
56 // will be silently dropped.
57 type FilteredTokenStream struct {
58 // tokenStream is the underlying TokenStream that is the data source.
59 tokenStream TokenStream
60 // blacklist contains the TokenKinds that should be skipped in the sourc e
61 // TokenStream.
62 blacklist map[TokenKind]bool
63 }
64
65 // See TokenStream.
66 func (s *FilteredTokenStream) PeekNext() (token Token) {
67 t := s.tokenStream.PeekNext()
68 for s.isBlacklisted(t) {
69 s.tokenStream.ConsumeNext()
70 t = s.tokenStream.PeekNext()
71 }
72
73 return t
74 }
75
76 // See TokenStream.
77 func (s *FilteredTokenStream) ConsumeNext() {
78 s.tokenStream.ConsumeNext()
rudominer 2016/01/20 00:40:31 I wonder if there should be a ConsumeNextInternal(
azani 2016/01/25 20:37:06 Done.
79 }
80
81 // isBlacklisted checks if a Token is of a blacklisted TokenKind.
82 func (s *FilteredTokenStream) isBlacklisted(token Token) bool {
83 // We don't allow blacklisting EOF since that would cause an infinite lo op.
84 if token.Kind == EOF {
rudominer 2016/01/20 00:40:31 Instead of this, make a constructor for FilteredTo
azani 2016/01/25 20:37:06 Done.
85 return false
86 }
87 _, ok := s.blacklist[token.Kind]
rudominer 2016/01/20 00:40:31 After the above change you can make this function
azani 2016/01/25 20:37:06 Done.
88 return ok
89 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/lexer/lexer_test.go ('k') | mojom/mojom_parser/lexer/tokens.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698