1 | #
|
2 | # # Brief syntax highlighter
|
3 | # Highlights `brief` function specification in the following format:
|
4 | #
|
5 | # ```
|
6 | # functionName(Type argument1, Type1/Type2 argument2, Type optionalArgument1?): Type
|
7 | # ```
|
8 | #
|
9 | # ```
|
10 | # functionName(Type argument1, Type1/Type2 argument2, [Type optionalArgument1]): Type
|
11 | # ```
|
12 | #
|
13 | # Optional arguments are marked by the `?` at the end, or are surrounded in square braces `[...]`.
|
14 | # Possible argument types are delimited by slash `/`.
|
15 | #
|
16 | module.exports = (hljs) ->
|
17 | TYPENAME =
|
18 | begin: "[\\w/]+\\s+"
|
19 | end: "[\\w]+"
|
20 | excludeEnd: true
|
21 | endsWithParent: true
|
22 | className: "attribute"
|
23 |
|
24 | SNIPPET = [
|
25 | begin: "^\\s*\\w+"
|
26 | end: "\\("
|
27 | excludeEnd: true
|
28 | className: "title"
|
29 | ,
|
30 | end: "\\)"
|
31 | excludeEnd: true
|
32 | contains: [
|
33 | begin: "\\s*"
|
34 | end: ","
|
35 | excludeBegin: true
|
36 | endsWithParent: true
|
37 | contains: [
|
38 | begin: "\\["
|
39 | end: "\\]"
|
40 | endsWithParent: true
|
41 | className: "optional"
|
42 | contains: [TYPENAME]
|
43 | ,
|
44 | begin: "[\\w/\\s]+\\?+"
|
45 | endsWithParent: true
|
46 | returnBegin: true
|
47 | className: "optional"
|
48 | contains: [TYPENAME]
|
49 | , TYPENAME,
|
50 | begin: ":\\s*"
|
51 | end: "[\\w]+"
|
52 | excludeBegin: true
|
53 | endsWithParent: true
|
54 | className: "attribute"
|
55 | ]
|
56 | ]
|
57 | ]
|
58 | contains: SNIPPET
|