1 package j
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var J = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "J",
12 Aliases: []string{"j"},
13 Filenames: []string{"*.ijs"},
14 MimeTypes: []string{"text/x-j"},
15 },
16 jRules,
17 ))
18
19 func jRules() Rules {
20 return Rules{
21 "root": {
22 {`#!.*$`, CommentPreproc, nil},
23 {`NB\..*`, CommentSingle, nil},
24 {`\n+\s*Note`, CommentMultiline, Push("comment")},
25 {`\s*Note.*`, CommentSingle, nil},
26 {`\s+`, Text, nil},
27 {`'`, LiteralString, Push("singlequote")},
28 {`0\s+:\s*0|noun\s+define\s*$`, NameEntity, Push("nounDefinition")},
29 {`(([1-4]|13)\s+:\s*0|(adverb|conjunction|dyad|monad|verb)\s+define)\b`, NameFunction, Push("explicitDefinition")},
30 {Words(``, `\b[a-zA-Z]\w*\.`, `for_`, `goto_`, `label_`), NameLabel, nil},
31 {Words(``, `\.`, `assert`, `break`, `case`, `catch`, `catchd`, `catcht`, `continue`, `do`, `else`, `elseif`, `end`, `fcase`, `for`, `if`, `return`, `select`, `throw`, `try`, `while`, `whilst`), NameLabel, nil},
32 {`\b[a-zA-Z]\w*`, NameVariable, nil},
33 {Words(``, ``, `ARGV`, `CR`, `CRLF`, `DEL`, `Debug`, `EAV`, `EMPTY`, `FF`, `JVERSION`, `LF`, `LF2`, `Note`, `TAB`, `alpha17`, `alpha27`, `apply`, `bind`, `boxopen`, `boxxopen`, `bx`, `clear`, `cutLF`, `cutopen`, `datatype`, `def`, `dfh`, `drop`, `each`, `echo`, `empty`, `erase`, `every`, `evtloop`, `exit`, `expand`, `fetch`, `file2url`, `fixdotdot`, `fliprgb`, `getargs`, `getenv`, `hfd`, `inv`, `inverse`, `iospath`, `isatty`, `isutf8`, `items`, `leaf`, `list`, `nameclass`, `namelist`, `names`, `nc`, `nl`, `on`, `pick`, `rows`, `script`, `scriptd`, `sign`, `sminfo`, `smoutput`, `sort`, `split`, `stderr`, `stdin`, `stdout`, `table`, `take`, `timespacex`, `timex`, `tmoutput`, `toCRLF`, `toHOST`, `toJ`, `tolower`, `toupper`, `type`, `ucp`, `ucpcount`, `usleep`, `utf8`, `uucp`), NameFunction, nil},
34 {`=[.:]`, Operator, nil},
35 {"[-=+*#$%@!~`^&\";:.,<>{}\\[\\]\\\\|/]", Operator, nil},
36 {`[abCdDeEfHiIjLMoprtT]\.`, KeywordReserved, nil},
37 {`[aDiLpqsStux]\:`, KeywordReserved, nil},
38 {`(_[0-9])\:`, KeywordConstant, nil},
39 {`\(`, Punctuation, Push("parentheses")},
40 Include("numbers"),
41 },
42 "comment": {
43 {`[^)]`, CommentMultiline, nil},
44 {`^\)`, CommentMultiline, Pop(1)},
45 {`[)]`, CommentMultiline, nil},
46 },
47 "explicitDefinition": {
48 {`\b[nmuvxy]\b`, NameDecorator, nil},
49 Include("root"),
50 {`[^)]`, Name, nil},
51 {`^\)`, NameLabel, Pop(1)},
52 {`[)]`, Name, nil},
53 },
54 "numbers": {
55 {`\b_{1,2}\b`, LiteralNumber, nil},
56 {`_?\d+(\.\d+)?(\s*[ejr]\s*)_?\d+(\.?=\d+)?`, LiteralNumber, nil},
57 {`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
58 {`_?\d+x`, LiteralNumberIntegerLong, nil},
59 {`_?\d+`, LiteralNumberInteger, nil},
60 },
61 "nounDefinition": {
62 {`[^)]`, LiteralString, nil},
63 {`^\)`, NameLabel, Pop(1)},
64 {`[)]`, LiteralString, nil},
65 },
66 "parentheses": {
67 {`\)`, Punctuation, Pop(1)},
68 Include("explicitDefinition"),
69 Include("root"),
70 },
71 "singlequote": {
72 {`[^']`, LiteralString, nil},
73 {`''`, LiteralString, nil},
74 {`'`, LiteralString, Pop(1)},
75 },
76 }
77 }
78
View as plain text