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

Side by Side Diff: mojom/mojom_parser/lexer/tokens.go

Issue 1837353002: Mojom parser: Fix snippet algorithm. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 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') | no next file » | 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 // TokenKinds is a type which describes the kinds of tokens which can be 5 // TokenKinds is a type which describes the kinds of tokens which can be
6 // encountered in a mojom file. 6 // encountered in a mojom file.
7 7
8 package lexer 8 package lexer
9 9
10 import ( 10 import (
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 begin += (index + 1) 259 begin += (index + 1)
260 break 260 break
261 } 261 }
262 } 262 }
263 263
264 // Now we calculate the end of the snippet line. Either the first new li ne 264 // Now we calculate the end of the snippet line. Either the first new li ne
265 // rune or a total of no more than 79 characters. 265 // rune or a total of no more than 79 characters.
266 end := len(source) 266 end := len(source)
267 for index, rune := range source[token.SourcePosBytes:] { 267 for index, rune := range source[token.SourcePosBytes:] {
268 if rune == '\n' || runeCount >= 78 { 268 if rune == '\n' || runeCount >= 78 {
269 » » » end = index + begin + token.LinePosBytes 269 » » » end = index + token.SourcePosBytes
270 break 270 break
271 } 271 }
272 runeCount++ 272 runeCount++
273 } 273 }
274 274
275 snippetBuffer := bytes.NewBufferString(source[begin:end]) 275 snippetBuffer := bytes.NewBufferString(source[begin:end])
276 snippetBuffer.WriteRune('\n') 276 snippetBuffer.WriteRune('\n')
277 277
278 // We calculate how much whitespace to add before the caret marker for t he 278 // We calculate how much whitespace to add before the caret marker for t he
279 // token. Please note that there is an assumption that all non-tab chara cters 279 // token. Please note that there is an assumption that all non-tab chara cters
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 319
320 text := token.Text 320 text := token.Text
321 length := len(text) 321 length := len(text)
322 if (length < 2) || (text[0] != '"') || (text[length-1] != '"') { 322 if (length < 2) || (text[0] != '"') || (text[length-1] != '"') {
323 panic(fmt.Sprintf("Lexer returned a string literal token whose " + 323 panic(fmt.Sprintf("Lexer returned a string literal token whose " +
324 "text was not delimited by quotation marks: '%s'.", text )) 324 "text was not delimited by quotation marks: '%s'.", text ))
325 } 325 }
326 return text[1 : length-1] 326 return text[1 : length-1]
327 } 327 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/lexer/lexer_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698