1 |
|
2 | 'use strict'
|
3 |
|
4 | const es6prefix = /(?:(?:export|default)\s+)*/.source
|
5 | const keyword = /[A-Za-z_][A-Za-z0-9_]*/.source
|
6 |
|
7 | function wrap (str) {
|
8 | return str.replace(/ {2}/g, /\s+/.source).replace(/ /g, /\s*/.source)
|
9 | }
|
10 |
|
11 | const cStyleComments = {
|
12 | commentstart: '/\\*',
|
13 | commentstartex: '/\\*\\*',
|
14 | commentend: '\\*/',
|
15 | commentdoc: '\\*',
|
16 | commentlinestart: '//'
|
17 | }
|
18 |
|
19 | module.exports = {
|
20 | languages: {
|
21 | javascript: {
|
22 | extensions: ['.js', '.es6'],
|
23 | slug: 'js',
|
24 | syntax: cStyleComments,
|
25 | preludes: [
|
26 | {
|
27 |
|
28 | regex: wrap(`^ ${es6prefix}class (${keyword})( extends (${keyword}))? { $`),
|
29 | type: 'class',
|
30 | title: '\\1',
|
31 | signature: null
|
32 | },
|
33 | {
|
34 |
|
35 | regex: wrap(`^ ${es6prefix}function (${keyword}) \\((.*?)\\) { $`),
|
36 | type: 'function',
|
37 | title: '\\1',
|
38 | signature: '\\1(\\2)'
|
39 | },
|
40 | {
|
41 |
|
42 | regex: wrap(`^ (${keyword}) \\((.*?)\\) { $`),
|
43 | type: 'function',
|
44 | title: '\\1',
|
45 | signature: '\\1(\\2)'
|
46 | },
|
47 | {
|
48 |
|
49 | regex: wrap(`^ (?:${keyword}\\.)*(${keyword}) = function (${keyword})? \\((.*?)\\) { $`),
|
50 | type: 'function',
|
51 | title: '\\1',
|
52 | signature: '\\1(\\3)'
|
53 | },
|
54 | {
|
55 |
|
56 | regex: wrap(`^ ${es6prefix}(?:var|let|const) (${keyword})`),
|
57 | type: 'variable',
|
58 | title: '\\1',
|
59 | signature: null
|
60 | },
|
61 | {
|
62 |
|
63 | regex: wrap(`^ (?:${keyword}\\.)*(${keyword}) =`),
|
64 | type: 'attribute',
|
65 | title: '\\1',
|
66 | signature: null
|
67 | }
|
68 | ]
|
69 | }
|
70 | },
|
71 | css: {
|
72 | extensions: ['.css'],
|
73 | slug: 'css',
|
74 | syntax: cStyleComments
|
75 | },
|
76 | sass: {
|
77 | extensions: ['.sass', '.scss'],
|
78 | slug: 'scss',
|
79 | syntax: cStyleComments
|
80 | },
|
81 | c: {
|
82 | extensions: ['.c'],
|
83 | slug: 'c',
|
84 | syntax: cStyleComments
|
85 | }
|
86 | }
|