mirror of
https://github.com/alecthomas/chroma.git
synced 2025-02-13 13:28:27 +02:00
Add J lexer
Generated with _tools/pygments2chroma.py. Sample `toupper` verb from `stdlib.ijs`: https://github.com/jsoftware/jsource/blob/j808-release/jlibrary/system/main/stdlib.ijs
This commit is contained in:
parent
aaa94ce97c
commit
a1c4eaa235
@ -44,7 +44,7 @@ F | Factor, Fish, Forth, Fortran, FSharp
|
||||
G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groovy
|
||||
H | Handlebars, Haskell, Haxe, HCL, Hexdump, HTML, HTTP, Hy
|
||||
I | Idris, INI, Io
|
||||
J | Java, JavaScript, JSON, Julia, Jungle
|
||||
J | J, Java, JavaScript, JSON, Julia, Jungle
|
||||
K | Kotlin
|
||||
L | Lighttpd configuration file, LLVM, Lua
|
||||
M | Mako, markdown, Mason, Mathematica, Matlab, MiniZinc, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL
|
||||
|
73
lexers/j/j.go
Normal file
73
lexers/j/j.go
Normal file
@ -0,0 +1,73 @@
|
||||
package j
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// J lexer.
|
||||
var J = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "J",
|
||||
Aliases: []string{"j"},
|
||||
Filenames: []string{"*.ijs"},
|
||||
MimeTypes: []string{"text/x-j"},
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`#!.*$`, CommentPreproc, nil},
|
||||
{`NB\..*`, CommentSingle, nil},
|
||||
{`\n+\s*Note`, CommentMultiline, Push("comment")},
|
||||
{`\s*Note.*`, CommentSingle, nil},
|
||||
{`\s+`, Text, nil},
|
||||
{`'`, LiteralString, Push("singlequote")},
|
||||
{`0\s+:\s*0|noun\s+define\s*$`, NameEntity, Push("nounDefinition")},
|
||||
{`(([1-4]|13)\s+:\s*0|(adverb|conjunction|dyad|monad|verb)\s+define)\b`, NameFunction, Push("explicitDefinition")},
|
||||
{Words(``, `\b[a-zA-Z]\w*\.`, `for_`, `goto_`, `label_`), NameLabel, nil},
|
||||
{Words(``, `\.`, `assert`, `break`, `case`, `catch`, `catchd`, `catcht`, `continue`, `do`, `else`, `elseif`, `end`, `fcase`, `for`, `if`, `return`, `select`, `throw`, `try`, `while`, `whilst`), NameLabel, nil},
|
||||
{`\b[a-zA-Z]\w*`, NameVariable, nil},
|
||||
{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},
|
||||
{`=[.:]`, Operator, nil},
|
||||
{"[-=+*#$%@!~`^&\";:.,<>{}\\[\\]\\\\|/]", Operator, nil},
|
||||
{`[abCdDeEfHiIjLMoprtT]\.`, KeywordReserved, nil},
|
||||
{`[aDiLpqsStux]\:`, KeywordReserved, nil},
|
||||
{`(_[0-9])\:`, KeywordConstant, nil},
|
||||
{`\(`, Punctuation, Push("parentheses")},
|
||||
Include("numbers"),
|
||||
},
|
||||
"comment": {
|
||||
{`[^)]`, CommentMultiline, nil},
|
||||
{`^\)`, CommentMultiline, Pop(1)},
|
||||
{`[)]`, CommentMultiline, nil},
|
||||
},
|
||||
"explicitDefinition": {
|
||||
{`\b[nmuvxy]\b`, NameDecorator, nil},
|
||||
Include("root"),
|
||||
{`[^)]`, Name, nil},
|
||||
{`^\)`, NameLabel, Pop(1)},
|
||||
{`[)]`, Name, nil},
|
||||
},
|
||||
"numbers": {
|
||||
{`\b_{1,2}\b`, LiteralNumber, nil},
|
||||
{`_?\d+(\.\d+)?(\s*[ejr]\s*)_?\d+(\.?=\d+)?`, LiteralNumber, nil},
|
||||
{`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
|
||||
{`_?\d+x`, LiteralNumberIntegerLong, nil},
|
||||
{`_?\d+`, LiteralNumberInteger, nil},
|
||||
},
|
||||
"nounDefinition": {
|
||||
{`[^)]`, LiteralString, nil},
|
||||
{`^\)`, NameLabel, Pop(1)},
|
||||
{`[)]`, LiteralString, nil},
|
||||
},
|
||||
"parentheses": {
|
||||
{`\)`, Punctuation, Pop(1)},
|
||||
Include("explicitDefinition"),
|
||||
Include("root"),
|
||||
},
|
||||
"singlequote": {
|
||||
{`[^']`, LiteralString, nil},
|
||||
{`''`, LiteralString, nil},
|
||||
{`'`, LiteralString, Pop(1)},
|
||||
},
|
||||
},
|
||||
))
|
6
lexers/testdata/j.actual
vendored
Normal file
6
lexers/testdata/j.actual
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
NB. from stdlib.ijs
|
||||
toupper=: 3 : 0`((((65+i.26){a.)(97+i.26)}a.) {~ a. i. ])@.(2 = 3!:0)
|
||||
x=. I. 26 > n=. ((97+i.26){a.) i. t=. ,y
|
||||
($y) $ ((x{n) { (65+i.26){a.) x}t
|
||||
)
|
||||
|
119
lexers/testdata/j.expected
vendored
Normal file
119
lexers/testdata/j.expected
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
[
|
||||
{"type":"CommentSingle","value":"NB. from stdlib.ijs"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameVariable","value":"toupper"},
|
||||
{"type":"Operator","value":"=:"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameFunction","value":"3 : 0"},
|
||||
{"type":"Operator","value":"`"},
|
||||
{"type":"Punctuation","value":"(((("},
|
||||
{"type":"LiteralNumberInteger","value":"65"},
|
||||
{"type":"Operator","value":"+"},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Operator","value":"{"},
|
||||
{"type":"NameVariable","value":"a"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Punctuation","value":")("},
|
||||
{"type":"LiteralNumberInteger","value":"97"},
|
||||
{"type":"Operator","value":"+"},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Operator","value":"}"},
|
||||
{"type":"NameVariable","value":"a"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"{~"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameVariable","value":"a"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"]"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Operator","value":"@."},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralNumberInteger","value":"2"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralNumberInteger","value":"3"},
|
||||
{"type":"Operator","value":"!:"},
|
||||
{"type":"LiteralNumberInteger","value":"0"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameDecorator","value":"x"},
|
||||
{"type":"Operator","value":"=."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameVariable","value":"I"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"\u003e"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameDecorator","value":"n"},
|
||||
{"type":"Operator","value":"=."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"(("},
|
||||
{"type":"LiteralNumberInteger","value":"97"},
|
||||
{"type":"Operator","value":"+"},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Operator","value":"{"},
|
||||
{"type":"NameVariable","value":"a"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameVariable","value":"t"},
|
||||
{"type":"Operator","value":"=."},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":","},
|
||||
{"type":"NameDecorator","value":"y"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Operator","value":"$"},
|
||||
{"type":"NameDecorator","value":"y"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"$"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"(("},
|
||||
{"type":"NameDecorator","value":"x"},
|
||||
{"type":"Operator","value":"{"},
|
||||
{"type":"NameDecorator","value":"n"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"{"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralNumberInteger","value":"65"},
|
||||
{"type":"Operator","value":"+"},
|
||||
{"type":"NameVariable","value":"i"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Operator","value":"{"},
|
||||
{"type":"NameVariable","value":"a"},
|
||||
{"type":"Operator","value":"."},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameDecorator","value":"x"},
|
||||
{"type":"Operator","value":"}"},
|
||||
{"type":"NameVariable","value":"t"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameLabel","value":")"},
|
||||
{"type":"Text","value":"\n\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user