1package j
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// J lexer.
9var J = internal.Register(MustNewLexer(
10 &Config{
11 Name: "J",
12 Aliases: []string{"j"},
13 Filenames: []string{"*.ijs"},
14 MimeTypes: []string{"text/x-j"},
15 },
16 Rules{
17 "root": {
18 {`#!.*$`, CommentPreproc, nil},
19 {`NB\..*`, CommentSingle, nil},
20 {`\n+\s*Note`, CommentMultiline, Push("comment")},
21 {`\s*Note.*`, CommentSingle, nil},
22 {`\s+`, Text, nil},
23 {`'`, LiteralString, Push("singlequote")},
24 {`0\s+:\s*0|noun\s+define\s*$`, NameEntity, Push("nounDefinition")},
25 {`(([1-4]|13)\s+:\s*0|(adverb|conjunction|dyad|monad|verb)\s+define)\b`, NameFunction, Push("explicitDefinition")},
26 {Words(``, `\b[a-zA-Z]\w*\.`, `for_`, `goto_`, `label_`), NameLabel, nil},
27 {Words(``, `\.`, `assert`, `break`, `case`, `catch`, `catchd`, `catcht`, `continue`, `do`, `else`, `elseif`, `end`, `fcase`, `for`, `if`, `return`, `select`, `throw`, `try`, `while`, `whilst`), NameLabel, nil},
28 {`\b[a-zA-Z]\w*`, NameVariable, nil},
29 {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},
30 {`=[.:]`, Operator, nil},
31 {"[-=+*#$%@!~`^&\";:.,<>{}\\[\\]\\\\|/]", Operator, nil},
32 {`[abCdDeEfHiIjLMoprtT]\.`, KeywordReserved, nil},
33 {`[aDiLpqsStux]\:`, KeywordReserved, nil},
34 {`(_[0-9])\:`, KeywordConstant, nil},
35 {`\(`, Punctuation, Push("parentheses")},
36 Include("numbers"),
37 },
38 "comment": {
39 {`[^)]`, CommentMultiline, nil},
40 {`^\)`, CommentMultiline, Pop(1)},
41 {`[)]`, CommentMultiline, nil},
42 },
43 "explicitDefinition": {
44 {`\b[nmuvxy]\b`, NameDecorator, nil},
45 Include("root"),
46 {`[^)]`, Name, nil},
47 {`^\)`, NameLabel, Pop(1)},
48 {`[)]`, Name, nil},
49 },
50 "numbers": {
51 {`\b_{1,2}\b`, LiteralNumber, nil},
52 {`_?\d+(\.\d+)?(\s*[ejr]\s*)_?\d+(\.?=\d+)?`, LiteralNumber, nil},
53 {`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
54 {`_?\d+x`, LiteralNumberIntegerLong, nil},
55 {`_?\d+`, LiteralNumberInteger, nil},
56 },
57 "nounDefinition": {
58 {`[^)]`, LiteralString, nil},
59 {`^\)`, NameLabel, Pop(1)},
60 {`[)]`, LiteralString, nil},
61 },
62 "parentheses": {
63 {`\)`, Punctuation, Pop(1)},
64 Include("explicitDefinition"),
65 Include("root"),
66 },
67 "singlequote": {
68 {`[^']`, LiteralString, nil},
69 {`''`, LiteralString, nil},
70 {`'`, LiteralString, Pop(1)},
71 },
72 },
73))