source: node_modules/highlight.js/lib/languages/scala.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[d24f17c]1/*
2Language: Scala
3Category: functional
4Author: Jan Berkel <jan.berkel@gmail.com>
5Contributors: Erik Osheim <d_m@plastic-idolatry.com>
6Website: https://www.scala-lang.org
7*/
8
9function scala(hljs) {
10 const ANNOTATION = {
11 className: 'meta',
12 begin: '@[A-Za-z]+'
13 };
14
15 // used in strings for escaping/interpolation/substitution
16 const SUBST = {
17 className: 'subst',
18 variants: [
19 {
20 begin: '\\$[A-Za-z0-9_]+'
21 },
22 {
23 begin: /\$\{/,
24 end: /\}/
25 }
26 ]
27 };
28
29 const STRING = {
30 className: 'string',
31 variants: [
32 {
33 begin: '"""',
34 end: '"""'
35 },
36 {
37 begin: '"',
38 end: '"',
39 illegal: '\\n',
40 contains: [ hljs.BACKSLASH_ESCAPE ]
41 },
42 {
43 begin: '[a-z]+"',
44 end: '"',
45 illegal: '\\n',
46 contains: [
47 hljs.BACKSLASH_ESCAPE,
48 SUBST
49 ]
50 },
51 {
52 className: 'string',
53 begin: '[a-z]+"""',
54 end: '"""',
55 contains: [ SUBST ],
56 relevance: 10
57 }
58 ]
59
60 };
61
62 const SYMBOL = {
63 className: 'symbol',
64 begin: '\'\\w[\\w\\d_]*(?!\')'
65 };
66
67 const TYPE = {
68 className: 'type',
69 begin: '\\b[A-Z][A-Za-z0-9_]*',
70 relevance: 0
71 };
72
73 const NAME = {
74 className: 'title',
75 begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,
76 relevance: 0
77 };
78
79 const CLASS = {
80 className: 'class',
81 beginKeywords: 'class object trait type',
82 end: /[:={\[\n;]/,
83 excludeEnd: true,
84 contains: [
85 hljs.C_LINE_COMMENT_MODE,
86 hljs.C_BLOCK_COMMENT_MODE,
87 {
88 beginKeywords: 'extends with',
89 relevance: 10
90 },
91 {
92 begin: /\[/,
93 end: /\]/,
94 excludeBegin: true,
95 excludeEnd: true,
96 relevance: 0,
97 contains: [ TYPE ]
98 },
99 {
100 className: 'params',
101 begin: /\(/,
102 end: /\)/,
103 excludeBegin: true,
104 excludeEnd: true,
105 relevance: 0,
106 contains: [ TYPE ]
107 },
108 NAME
109 ]
110 };
111
112 const METHOD = {
113 className: 'function',
114 beginKeywords: 'def',
115 end: /[:={\[(\n;]/,
116 excludeEnd: true,
117 contains: [ NAME ]
118 };
119
120 return {
121 name: 'Scala',
122 keywords: {
123 literal: 'true false null',
124 keyword: 'type yield lazy override def with val var sealed abstract private trait object if forSome for while throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit'
125 },
126 contains: [
127 hljs.C_LINE_COMMENT_MODE,
128 hljs.C_BLOCK_COMMENT_MODE,
129 STRING,
130 SYMBOL,
131 TYPE,
132 METHOD,
133 CLASS,
134 hljs.C_NUMBER_MODE,
135 ANNOTATION
136 ]
137 };
138}
139
140module.exports = scala;
Note: See TracBrowser for help on using the repository browser.