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

Unified Diff: mojom/mojom_parser/lexer/lexer.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
« no previous file with comments | « no previous file | mojom/mojom_parser/lexer/lexer_test.go » ('j') | mojom/mojom_parser/lexer/token_stream.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/lexer/lexer.go
diff --git a/mojom/mojom_parser/lexer/lexer.go b/mojom/mojom_parser/lexer/lexer.go
index aba64679a49191db49fc9012ac2453cc6606a6c2..a4bb73492746d9c44aec6fe867fce575f9bb5f6a 100644
--- a/mojom/mojom_parser/lexer/lexer.go
+++ b/mojom/mojom_parser/lexer/lexer.go
@@ -26,8 +26,20 @@ import (
)
// Tokenize accepts a source string and parses it into a stream of tokens which
-// can be read from the returned TokenStream.
+// can be read from the returned TokenStream. Comment tokens are ommitted from
+// the returned stream.
func Tokenize(source string) TokenStream {
+ return &FilteredTokenStream{
+ tokenizeUnfiltered(source),
+ map[TokenKind]bool{
+ SingleLineComment: true,
+ MultiLineComment: true}}
+}
+
+// tokenizeUnfiltered returns a TokenStream which does not filter out any of the
+// tokens in the channel. It is used for testing and by Tokenize which adds a
+// filter on top of the stream returned by tokenizeUnfiltered.
+func tokenizeUnfiltered(source string) TokenStream {
tokens := make(chan Token)
l := lexer{source: source, tokens: tokens}
go l.run()
@@ -509,7 +521,7 @@ func lexSingleLineComment(l *lexer) stateFn {
l.Consume()
}
- l.beginToken()
+ l.emitToken(SingleLineComment)
return lexRoot
}
@@ -542,7 +554,7 @@ func lexPossibleEndOfComment(l *lexer) stateFn {
if l.Peek() == '/' {
l.Consume()
- l.beginToken()
+ l.emitToken(MultiLineComment)
return lexRoot
}
« no previous file with comments | « no previous file | mojom/mojom_parser/lexer/lexer_test.go » ('j') | mojom/mojom_parser/lexer/token_stream.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698