| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 True | 60 True |
| 61 False | 61 False |
| 62 Default | 62 Default |
| 63 | 63 |
| 64 // Constants | 64 // Constants |
| 65 IntConstDec | 65 IntConstDec |
| 66 IntConstHex | 66 IntConstHex |
| 67 FloatConst | 67 FloatConst |
| 68 Ordinal | 68 Ordinal |
| 69 StringLiteral | 69 StringLiteral |
| 70 |
| 71 // Comments |
| 72 SingleLineComment |
| 73 MultiLineComment |
| 70 ) | 74 ) |
| 71 | 75 |
| 72 // This method is used to generate user-facing strings in compilation error | 76 // This method is used to generate user-facing strings in compilation error |
| 73 // messages. For example for LBrace we produce the string "'{'". Notice the | 77 // messages. For example for LBrace we produce the string "'{'". Notice the |
| 74 // single-quotes. This will be used for example in an error message that looks | 78 // single-quotes. This will be used for example in an error message that looks |
| 75 // like the following: | 79 // like the following: |
| 76 // Unexpected token at line 5, column 6: '###'. Expecting '{'. | 80 // Unexpected token at line 5, column 6: '###'. Expecting '{'. |
| 77 func (tokenKind TokenKind) String() string { | 81 func (tokenKind TokenKind) String() string { |
| 78 switch tokenKind { | 82 switch tokenKind { |
| 79 // Errors | 83 // Errors |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return "decimal integer literal" | 159 return "decimal integer literal" |
| 156 case IntConstHex: | 160 case IntConstHex: |
| 157 return "hex integer literal" | 161 return "hex integer literal" |
| 158 case FloatConst: | 162 case FloatConst: |
| 159 return "float literal" | 163 return "float literal" |
| 160 case Ordinal: | 164 case Ordinal: |
| 161 return "an ordinal" | 165 return "an ordinal" |
| 162 case StringLiteral: | 166 case StringLiteral: |
| 163 return "a string literal" | 167 return "a string literal" |
| 164 | 168 |
| 169 case SingleLineComment: |
| 170 return "single line comment" |
| 171 case MultiLineComment: |
| 172 return "multi line comment" |
| 173 |
| 165 default: | 174 default: |
| 166 // Note(rudominer) It is important to use %d below so as to avoi
d | 175 // Note(rudominer) It is important to use %d below so as to avoi
d |
| 167 // re-invoking this method and causing an infinite recursion. | 176 // re-invoking this method and causing an infinite recursion. |
| 168 return fmt.Sprintf("%d", tokenKind) | 177 return fmt.Sprintf("%d", tokenKind) |
| 169 } | 178 } |
| 170 } | 179 } |
| 171 | 180 |
| 172 type Token struct { | 181 type Token struct { |
| 173 Kind TokenKind | 182 Kind TokenKind |
| 174 Text string | 183 Text string |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 snippetBuffer.WriteString("\x1b[32;1m") | 298 snippetBuffer.WriteString("\x1b[32;1m") |
| 290 } | 299 } |
| 291 snippetBuffer.WriteString(strings.Repeat("^", tokenSize)) | 300 snippetBuffer.WriteString(strings.Repeat("^", tokenSize)) |
| 292 if color { | 301 if color { |
| 293 // Reset all printing attributes. | 302 // Reset all printing attributes. |
| 294 snippetBuffer.WriteString("\x1b[0m") | 303 snippetBuffer.WriteString("\x1b[0m") |
| 295 } | 304 } |
| 296 snippet = snippetBuffer.String() | 305 snippet = snippetBuffer.String() |
| 297 return | 306 return |
| 298 } | 307 } |
| OLD | NEW |