1package e 2 3import ( 4 . "github.com/alecthomas/chroma" // nolint 5 "github.com/alecthomas/chroma/lexers/internal" 6) 7 8// Erlang lexer. 9var Erlang = internal.Register(MustNewLazyLexer( 10 &Config{ 11 Name: "Erlang", 12 Aliases: []string{"erlang"}, 13 Filenames: []string{"*.erl", "*.hrl", "*.es", "*.escript"}, 14 MimeTypes: []string{"text/x-erlang"}, 15 }, 16 erlangRules, 17)) 18 19func erlangRules() Rules { 20 return Rules{ 21 "root": { 22 {`\s+`, Text, nil}, 23 {`%.*\n`, Comment, nil}, 24 {Words(``, `\b`, `after`, `begin`, `case`, `catch`, `cond`, `end`, `fun`, `if`, `let`, `of`, `query`, `receive`, `try`, `when`), Keyword, nil}, 25 {Words(``, `\b`, `abs`, `append_element`, `apply`, `atom_to_list`, `binary_to_list`, `bitstring_to_list`, `binary_to_term`, `bit_size`, `bump_reductions`, `byte_size`, `cancel_timer`, `check_process_code`, `delete_module`, `demonitor`, `disconnect_node`, `display`, `element`, `erase`, `exit`, `float`, `float_to_list`, `fun_info`, `fun_to_list`, `function_exported`, `garbage_collect`, `get`, `get_keys`, `group_leader`, `hash`, `hd`, `integer_to_list`, `iolist_to_binary`, `iolist_size`, `is_atom`, `is_binary`, `is_bitstring`, `is_boolean`, `is_builtin`, `is_float`, `is_function`, `is_integer`, `is_list`, `is_number`, `is_pid`, `is_port`, `is_process_alive`, `is_record`, `is_reference`, `is_tuple`, `length`, `link`, `list_to_atom`, `list_to_binary`, `list_to_bitstring`, `list_to_existing_atom`, `list_to_float`, `list_to_integer`, `list_to_pid`, `list_to_tuple`, `load_module`, `localtime_to_universaltime`, `make_tuple`, `md5`, `md5_final`, `md5_update`, `memory`, `module_loaded`, `monitor`, `monitor_node`, `node`, `nodes`, `open_port`, `phash`, `phash2`, `pid_to_list`, `port_close`, `port_command`, `port_connect`, `port_control`, `port_call`, `port_info`, `port_to_list`, `process_display`, `process_flag`, `process_info`, `purge_module`, `put`, `read_timer`, `ref_to_list`, `register`, `resume_process`, `round`, `send`, `send_after`, `send_nosuspend`, `set_cookie`, `setelement`, `size`, `spawn`, `spawn_link`, `spawn_monitor`, `spawn_opt`, `split_binary`, `start_timer`, `statistics`, `suspend_process`, `system_flag`, `system_info`, `system_monitor`, `system_profile`, `term_to_binary`, `tl`, `trace`, `trace_delivered`, `trace_info`, `trace_pattern`, `trunc`, `tuple_size`, `tuple_to_list`, `universaltime_to_localtime`, `unlink`, `unregister`, `whereis`), NameBuiltin, nil}, 26 {Words(``, `\b`, `and`, `andalso`, `band`, `bnot`, `bor`, `bsl`, `bsr`, `bxor`, `div`, `not`, `or`, `orelse`, `rem`, `xor`), OperatorWord, nil}, 27 {`^-`, Punctuation, Push("directive")}, 28 {`(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)`, Operator, nil}, 29 {`"`, LiteralString, Push("string")}, 30 {`<<`, NameLabel, nil}, 31 {`>>`, NameLabel, nil}, 32 {`((?:[a-z]\w*|'[^\n']*[^\\]'))(:)`, ByGroups(NameNamespace, Punctuation), nil}, 33 {`(?:^|(?<=:))((?:[a-z]\w*|'[^\n']*[^\\]'))(\s*)(\()`, ByGroups(NameFunction, Text, Punctuation), nil}, 34 {`[+-]?(?:[2-9]|[12][0-9]|3[0-6])#[0-9a-zA-Z]+`, LiteralNumberInteger, nil}, 35 {`[+-]?\d+`, LiteralNumberInteger, nil}, 36 {`[+-]?\d+.\d+`, LiteralNumberFloat, nil}, 37 {`[]\[:_@\".{}()|;,]`, Punctuation, nil}, 38 {`(?:[A-Z_]\w*)`, NameVariable, nil}, 39 {`(?:[a-z]\w*|'[^\n']*[^\\]')`, Name, nil}, 40 {`\?(?:(?:[A-Z_]\w*)|(?:[a-z]\w*|'[^\n']*[^\\]'))`, NameConstant, nil}, 41 {`\$(?:(?:\\(?:[bdefnrstv\'"\\]|[0-7][0-7]?[0-7]?|(?:x[0-9a-fA-F]{2}|x\{[0-9a-fA-F]+\})|\^[a-zA-Z]))|\\[ %]|[^\\])`, LiteralStringChar, nil}, 42 {`#(?:[a-z]\w*|'[^\n']*[^\\]')(:?\.(?:[a-z]\w*|'[^\n']*[^\\]'))?`, NameLabel, nil}, 43 {`\A#!.+\n`, CommentHashbang, nil}, 44 {`#\{`, Punctuation, Push("map_key")}, 45 }, 46 "string": { 47 {`(?:\\(?:[bdefnrstv\'"\\]|[0-7][0-7]?[0-7]?|(?:x[0-9a-fA-F]{2}|x\{[0-9a-fA-F]+\})|\^[a-zA-Z]))`, LiteralStringEscape, nil}, 48 {`"`, LiteralString, Pop(1)}, 49 {`~[0-9.*]*[~#+BPWXb-ginpswx]`, LiteralStringInterpol, nil}, 50 {`[^"\\~]+`, LiteralString, nil}, 51 {`~`, LiteralString, nil}, 52 }, 53 "directive": { 54 {`(define)(\s*)(\()((?:(?:[A-Z_]\w*)|(?:[a-z]\w*|'[^\n']*[^\\]')))`, ByGroups(NameEntity, Text, Punctuation, NameConstant), Pop(1)}, 55 {`(record)(\s*)(\()((?:(?:[A-Z_]\w*)|(?:[a-z]\w*|'[^\n']*[^\\]')))`, ByGroups(NameEntity, Text, Punctuation, NameLabel), Pop(1)}, 56 {`(?:[a-z]\w*|'[^\n']*[^\\]')`, NameEntity, Pop(1)}, 57 }, 58 "map_key": { 59 Include("root"), 60 {`=>`, Punctuation, Push("map_val")}, 61 {`:=`, Punctuation, Push("map_val")}, 62 {`\}`, Punctuation, Pop(1)}, 63 }, 64 "map_val": { 65 Include("root"), 66 {`,`, Punctuation, Pop(1)}, 67 {`(?=\})`, Punctuation, Pop(1)}, 68 }, 69 } 70} 71