Blame view

assets/plugins/google-code-prettify/lang-scala.js 2.5 KB
cf76164e6   Ting Chan   20190709
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  // Copyright (C) 2010 Google Inc.
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //      http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  
  /**
   * @fileoverview
   * Registers a language handler for Scala.
   *
   * Derived from http://lampsvn.epfl.ch/svn-repos/scala/scala-documentation/trunk/src/reference/SyntaxSummary.tex
   *
   * @author mikesamuel@gmail.com
   */
  
  PR['registerLangHandler'](
      PR['createSimpleLexer'](
          [
           // Whitespace
           [PR['PR_PLAIN'],       /^[\t
  \r \xA0]+/, null, '\t
  \r \xA0'],
           // A double or single quoted string 
            // or a triple double-quoted multi-line string.
           [PR['PR_STRING'],
            /^(?:"(?:(?:""(?:""?(?!")|[^\\"]|\\.)*"{0,3})|(?:[^"\r
  \\]|\\.)*"?))/,
            null, '"'],
           [PR['PR_LITERAL'],     /^`(?:[^\r
  \\`]|\\.)*`?/, null, '`'],
           [PR['PR_PUNCTUATION'], /^[!#%&()*+,\-:;<=>?@\[\\\]^{|}~]+/, null,
            '!#%&()*+,-:;<=>?@[\\]^{|}~']
          ],
          [
           // A symbol literal is a single quote followed by an identifier with no
           // single quote following
           // A character literal has single quotes on either side
           [PR['PR_STRING'],      /^'(?:[^\r
  \\']|\\(?:'|[^\r
  ']+))'/],
           [PR['PR_LITERAL'],     /^'[a-zA-Z_$][\w$]*(?!['$\w])/],
           [PR['PR_KEYWORD'],     /^(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|object|override|package|private|protected|requires|return|sealed|super|throw|trait|try|type|val|var|while|with|yield)\b/],
           [PR['PR_LITERAL'],     /^(?:true|false|null|this)\b/],
           [PR['PR_LITERAL'],     /^(?:(?:0(?:[0-7]+|X[0-9A-F]+))L?|(?:(?:0|[1-9][0-9]*)(?:(?:\.[0-9]+)?(?:E[+\-]?[0-9]+)?F?|L?))|\\.[0-9]+(?:E[+\-]?[0-9]+)?F?)/i],
           // Treat upper camel case identifiers as types.
           [PR['PR_TYPE'],        /^[$_]*[A-Z][_$A-Z0-9]*[a-z][\w$]*/],
           [PR['PR_PLAIN'],       /^[$a-zA-Z_][\w$]*/],
           [PR['PR_COMMENT'],     /^\/(?:\/.*|\*(?:\/|\**[^*/])*(?:\*+\/?)?)/],
           [PR['PR_PUNCTUATION'], /^(?:\.+|\/)/]
          ]),
      ['scala']);