lang-go.js 2.3 KB

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