|
| 1 | +package f |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/alecthomas/chroma" // nolint |
| 5 | + "github.com/alecthomas/chroma/lexers/internal" |
| 6 | +) |
| 7 | + |
| 8 | +// Fennel lexer. |
| 9 | +var Fennel = internal.Register(MustNewLazyLexer( |
| 10 | + &Config{ |
| 11 | + Name: "Fennel", |
| 12 | + Aliases: []string{"fennel", "fnl"}, |
| 13 | + Filenames: []string{"*.fennel"}, |
| 14 | + MimeTypes: []string{"text/x-fennel", "application/x-fennel"}, |
| 15 | + }, |
| 16 | + fennelRules, |
| 17 | +)) |
| 18 | + |
| 19 | +// Here's some Fennel code used to generate the lists of keywords: |
| 20 | +// (local fennel (require :fennel)) |
| 21 | +// |
| 22 | +// (fn member? [t x] (each [_ y (ipairs t)] (when (= y x) (lua "return true")))) |
| 23 | +// |
| 24 | +// (local declarations [:fn :lambda :λ :local :var :global :macro :macros]) |
| 25 | +// (local keywords []) |
| 26 | +// (local globals []) |
| 27 | +// |
| 28 | +// (each [name data (pairs (fennel.syntax))] |
| 29 | +// (if (member? declarations name) nil ; already populated |
| 30 | +// data.special? (table.insert keywords name) |
| 31 | +// data.macro? (table.insert keywords name) |
| 32 | +// data.global? (table.insert globals name))) |
| 33 | +// |
| 34 | +// (fn quoted [tbl] |
| 35 | +// (table.sort tbl) |
| 36 | +// (table.concat (icollect [_ k (ipairs tbl)] |
| 37 | +// (string.format "`%s`" k)) ", ")) |
| 38 | +// |
| 39 | +// (print :Keyword (quoted keywords)) |
| 40 | +// (print :KeywordDeclaration (quoted declarations)) |
| 41 | +// (print :NameBuiltin (quoted globals)) |
| 42 | + |
| 43 | +func fennelRules() Rules { |
| 44 | + return Rules{ |
| 45 | + "root": { |
| 46 | + {`;.*$`, CommentSingle, nil}, |
| 47 | + {`\s+`, Whitespace, nil}, |
| 48 | + {`-?\d+\.\d+`, LiteralNumberFloat, nil}, |
| 49 | + {`-?\d+`, LiteralNumberInteger, nil}, |
| 50 | + {`0x-?[abcdef\d]+`, LiteralNumberHex, nil}, |
| 51 | + {`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, |
| 52 | + {`'(?!#)[\w!$%*+<=>?/.#-]+`, LiteralStringSymbol, nil}, |
| 53 | + {`\\(.|[a-z]+)`, LiteralStringChar, nil}, |
| 54 | + {`::?#?(?!#)[\w!$%*+<=>?/.#-]+`, LiteralStringSymbol, nil}, |
| 55 | + {"~@|[`\\'#^~&@]", Operator, nil}, |
| 56 | + {Words(``, ` `, `#`, `%`, `*`, `+`, `-`, `->`, `->>`, `-?>`, `-?>>`, `.`, `..`, `/`, `//`, `:`, `<`, `<=`, `=`, `>`, `>=`, `?.`, `^`, `accumulate`, `and`, `band`, `bnot`, `bor`, `bxor`, `collect`, `comment`, `do`, `doc`, `doto`, `each`, `eval-compiler`, `for`, `hashfn`, `icollect`, `if`, `import-macros`, `include`, `length`, `let`, `lshift`, `lua`, `macrodebug`, `match`, `not`, `not=`, `or`, `partial`, `pick-args`, `pick-values`, `quote`, `require-macros`, `rshift`, `set`, `set-forcibly!`, `tset`, `values`, `when`, `while`, `with-open`, `~=`), Keyword, nil}, |
| 57 | + {Words(``, ` `, `fn`, `global`, `lambda`, `local`, `macro`, `macros`, `var`, `λ`), KeywordDeclaration, nil}, |
| 58 | + {Words(``, ` `, `_G`, `arg`, `assert`, `bit32`, `bit32.arshift`, `bit32.band`, `bit32.bnot`, `bit32.bor`, `bit32.btest`, `bit32.bxor`, `bit32.extract`, `bit32.lrotate`, `bit32.lshift`, `bit32.replace`, `bit32.rrotate`, `bit32.rshift`, `collectgarbage`, `coroutine`, `coroutine.create`, `coroutine.resume`, `coroutine.running`, `coroutine.status`, `coroutine.wrap`, `coroutine.yield`, `debug`, `debug.debug`, `debug.gethook`, `debug.getinfo`, `debug.getlocal`, `debug.getmetatable`, `debug.getregistry`, `debug.getupvalue`, `debug.getuservalue`, `debug.sethook`, `debug.setlocal`, `debug.setmetatable`, `debug.setupvalue`, `debug.setuservalue`, `debug.traceback`, `debug.upvalueid`, `debug.upvaluejoin`, `dofile`, `error`, `getmetatable`, `io`, `io.close`, `io.flush`, `io.input`, `io.lines`, `io.open`, `io.output`, `io.popen`, `io.read`, `io.tmpfile`, `io.type`, `io.write`, `ipairs`, `load`, `loadfile`, `loadstring`, `math`, `math.abs`, `math.acos`, `math.asin`, `math.atan`, `math.atan2`, `math.ceil`, `math.cos`, `math.cosh`, `math.deg`, `math.exp`, `math.floor`, `math.fmod`, `math.frexp`, `math.ldexp`, `math.log`, `math.log10`, `math.max`, `math.min`, `math.modf`, `math.pow`, `math.rad`, `math.random`, `math.randomseed`, `math.sin`, `math.sinh`, `math.sqrt`, `math.tan`, `math.tanh`, `module`, `next`, `os`, `os.clock`, `os.date`, `os.difftime`, `os.execute`, `os.exit`, `os.getenv`, `os.remove`, `os.rename`, `os.setlocale`, `os.time`, `os.tmpname`, `package`, `package.loadlib`, `package.searchpath`, `package.seeall`, `pairs`, `pcall`, `print`, `rawequal`, `rawget`, `rawlen`, `rawset`, `require`, `select`, `setmetatable`, `string`, `string.byte`, `string.char`, `string.dump`, `string.find`, `string.format`, `string.gmatch`, `string.gsub`, `string.len`, `string.lower`, `string.match`, `string.rep`, `string.reverse`, `string.sub`, `string.upper`, `table`, `table.concat`, `table.insert`, `table.maxn`, `table.pack`, `table.remove`, `table.sort`, `table.unpack`, `tonumber`, `tostring`, `type`, `unpack`, `xpcall`), NameBuiltin, nil}, |
| 59 | + {`(?<=\()(?!#)[\w!$%*+<=>?/.#-]+`, NameFunction, nil}, |
| 60 | + {`(?!#)[\w!$%*+<=>?/.#-]+`, NameVariable, nil}, |
| 61 | + {`(\[|\])`, Punctuation, nil}, |
| 62 | + {`(\{|\})`, Punctuation, nil}, |
| 63 | + {`(\(|\))`, Punctuation, nil}, |
| 64 | + }, |
| 65 | + } |
| 66 | +} |
0 commit comments