1/** 2 * @license 3 * Copyright (C) 2010 Google Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19 * @fileoverview 20 * Registers a language handler for the Go language.. 21 * <p> 22 * Based on the lexical grammar at 23 * http://golang.org/doc/go_spec.html#Lexical_elements 24 * <p> 25 * Go uses a minimal style for highlighting so the below does not distinguish 26 * strings, keywords, literals, etc. by design. 27 * From a discussion with the Go designers: 28 * <pre> 29 * On Thursday, July 22, 2010, Mike Samuel <...> wrote: 30 * > On Thu, Jul 22, 2010, Rob 'Commander' Pike <...> wrote: 31 * >> Personally, I would vote for the subdued style godoc presents at http://golang.org 32 * >> 33 * >> Not as fancy as some like, but a case can be made it's the official style. 34 * >> If people want more colors, I wouldn't fight too hard, in the interest of 35 * >> encouragement through familiarity, but even then I would ask to shy away 36 * >> from technicolor starbursts. 37 * > 38 * > Like http://golang.org/pkg/go/scanner/ where comments are blue and all 39 * > other content is black? I can do that. 40 * </pre> 41 * 42 * @author mikesamuel@gmail.com 43 */ 44 45PR['registerLangHandler']( 46 PR['createSimpleLexer']( 47 [ 48 // Whitespace is made up of spaces, tabs and newline characters. 49 [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'], 50 // Not escaped as a string. See note on minimalism above. 51 [PR['PR_PLAIN'], /^(?:\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)|\'(?:[^\'\\]|\\[\s\S])+(?:\'|$)|`[^`]*(?:`|$))/, null, '"\''] 52 ], 53 [ 54 // Block comments are delimited by /* and */. 55 // Single-line comments begin with // and extend to the end of a line. 56 [PR['PR_COMMENT'], /^(?:\/\/[^\r\n]*|\/\*[\s\S]*?\*\/)/], 57 [PR['PR_PLAIN'], /^(?:[^\/\"\'`]|\/(?![\/\*]))+/i] 58 ]), 59 ['go']); 60