diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-31 12:50:33 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-31 12:58:21 +0200 |
| commit | dc5f5a45a2315011ebeeb0a56a7434ead292dc96 (patch) | |
| tree | 42e155217801668ace0d7c0a2264a323ed42c801 /lua | |
| parent | 6f44057d09b865e9c7e443cd7d7adb8e541121db (diff) | |
| download | vis-dc5f5a45a2315011ebeeb0a56a7434ead292dc96.tar.gz vis-dc5f5a45a2315011ebeeb0a56a7434ead292dc96.tar.xz | |
lexers: sync with scintillua changeset 600 rev fdeca0b808bf
I think the default value for the cache argument to the lexer load
function should be true, not false. Optimize for the common case.
This makes the API ugly/harder to use. But for now we follow upstream.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lexers/lexer.lua | 8 | ||||
| -rw-r--r-- | lua/lexers/logtalk.lua | 52 | ||||
| -rw-r--r-- | lua/lexers/moonscript.lua | 1 | ||||
| -rw-r--r-- | lua/lexers/prolog.lua | 139 | ||||
| -rw-r--r-- | lua/plugins/filetype.lua | 3 | ||||
| -rw-r--r-- | lua/plugins/textobject-lexer.lua | 2 | ||||
| -rw-r--r-- | lua/vis-std.lua | 2 |
7 files changed, 184 insertions, 23 deletions
diff --git a/lua/lexers/lexer.lua b/lua/lexers/lexer.lua index e7d749f..d4af90c 100644 --- a/lua/lexers/lexer.lua +++ b/lua/lexers/lexer.lua @@ -1028,10 +1028,14 @@ end -- @param name The name of the lexing language. -- @param alt_name The alternate name of the lexing language. This is useful for -- embedding the same child lexer with multiple sets of start and end tokens. +-- @param cache Flag indicating whether or not to load lexers from the cache. +-- This should only be `true` when initially loading a lexer (e.g. not from +-- within another lexer for embedding purposes). +-- The default value is `false`. -- @return lexer object -- @name load -function M.load(name, alt_name) - if M.lexers[alt_name or name] then return M.lexers[alt_name or name] end +function M.load(name, alt_name, cache) + if cache and M.lexers[alt_name or name] then return M.lexers[alt_name or name] end parent_lexer = nil -- reset -- When using Scintillua as a stand-alone module, the `property` and diff --git a/lua/lexers/logtalk.lua b/lua/lexers/logtalk.lua new file mode 100644 index 0000000..3986859 --- /dev/null +++ b/lua/lexers/logtalk.lua @@ -0,0 +1,52 @@ +-- Copyright © 2017 Michael T. Richter <ttmrichter@gmail.com>. See LICENSE. +-- Logtalk LPeg lexer. + +local l = require 'lexer' +local token, word_match = l.token, l.word_match +local B, P, R, S, V = lpeg.B, lpeg.P, lpeg.R, lpeg.S, lpeg.V + +local M = { _NAME = 'logtalk' } + +local keyword = token(l.KEYWORD, word_match{ + -- Logtalk "keywords" generated from Vim syntax highlighting file with Prolog + -- keywords stripped since we're building up on the Prolog lexer. + 'abolish_category', 'abolish_events', 'abolish_object', 'abolish_protocol', + 'after', 'alias', 'as', 'before', 'built_in', 'calls', 'category', + 'category_property', 'coinductive', 'complements', 'complements_object', + 'conforms_to_protocol', 'create', 'create_category', 'create_object', + 'create_protocol', 'create_logtalk_flag', 'current', 'current_category', + 'current_event', 'current_logtalk_flag', 'current_object', 'current_protocol', + 'define_events', 'encoding', 'end_category', 'end_class', 'end_object', + 'end_protocol', 'extends', 'extends_category', 'extends_object', + 'extends_protocol', 'forward', 'implements', 'implements_protocol', 'imports', + 'imports_category', 'include', 'info', 'instantiates', 'instantiates_class', + 'is', 'logtalk_compile', 'logtalk_library_path', 'logtalk_load', + 'logtalk_load_context', 'logtalk_make', 'meta_non_terminal', 'mode', 'object', + 'object_property', 'parameter', 'private', 'protected', 'protocol_property', + 'self', 'sender', 'set_logtalk_flag', 'specializes', 'specializes_class', + 'synchronized', 'this', 'threaded', 'threaded_call', 'threaded_engine', + 'threaded_engine_create', 'threaded_engine_destroy', 'threaded_engine_fetch', + 'threaded_engine_next', 'threaded_engine_next_reified', + 'threaded_engine_post', 'threaded_engine_self', 'threaded_engine_yield', + 'threaded_exit', 'threaded_ignore', 'threaded_notify', 'threaded_once', + 'threaded_peek', 'threaded_wait', 'uses', + + -- info/1 and info/2 predicates have their own keywords, manually extracted + -- from documentation + 'comment', 'argnames', 'arguments', 'author', 'version', 'date', 'parameters', + 'parnames', 'copyright', 'license', 'remarks', 'see_also', +}) + +-- Extend prolog lexer to include logtalk extensions. +local prolog = l.load('prolog') +local _rules = prolog._rules +for i = 1, #_rules do + if _rules[i][1] == 'keyword' then + table.insert(_rules, i, {'logtalk_keyword', keyword}) + end +end + +M._rules = _rules +M._foldsymbols = prolog._foldsymbols + +return M diff --git a/lua/lexers/moonscript.lua b/lua/lexers/moonscript.lua index 50638ed..c0a00d2 100644 --- a/lua/lexers/moonscript.lua +++ b/lua/lexers/moonscript.lua @@ -163,7 +163,6 @@ M._tokenstyles = { fndef = l.STYLE_PREPROCESSOR, symbol = l.STYLE_EMBEDDED, tbl_key = l.STYLE_REGEX, - error = l.STYLE_ERROR, } M._FOLDBYINDENTATION = true diff --git a/lua/lexers/prolog.lua b/lua/lexers/prolog.lua index 75a3c5c..2999674 100644 --- a/lua/lexers/prolog.lua +++ b/lua/lexers/prolog.lua @@ -25,24 +25,127 @@ local number = token(l.NUMBER, l.digit^1 * ('.' * l.digit^1)^-1) -- Keywords. local keyword = token(l.KEYWORD, word_match{ - 'module', 'meta_predicate', 'multifile', 'dynamic', 'abolish', - 'current_output', 'peek_code', 'append', 'current_predicate', 'put_byte', - 'arg', 'current_prolog_flag', 'put_char', 'asserta', 'assert', 'fail', - 'put_code', 'assertz', 'findall', 'read', 'at_end_of_stream', 'float', - 'read_term', 'atom', 'flush_output', 'repeat', 'atom_chars', 'functor', - 'retract', 'atom_codes', 'get_byte', 'set_input', 'atom_concat', 'get_char', - 'set_output', 'atom_length', 'get_code', 'set_prolog_flag', 'atomic', 'halt', - 'set_stream_position', 'bagof', 'integer', 'setof', 'call', 'is', - 'stream_property', 'catch', 'nl', 'sub_atom', 'char_code', 'nonvar', 'throw', - 'char_conversion', 'number', 'clause', 'number_chars', - 'unify_with_occurs_check', 'close', 'number_codes', 'var', 'compound', 'once', - 'copy_term', 'op', 'write', 'writeln', 'write_canonical', 'write_term', - 'writeq', 'current_char_conversion', 'open', 'current_input', 'peek_byte', - 'current_op', 'peek_char', 'false', 'true', 'consult', 'member', 'memberchk', - 'reverse', 'permutation', 'delete', - -- Math. - 'mod', 'div', 'abs', 'exp', 'ln', 'log', 'sqrt', 'round', 'trunc', 'val', - 'cos', 'sin', 'tan', 'arctan', 'random', 'randominit' + -- Directives, by manual scanning of SWI-Prolog source code + 'abolish', 'arithmetic_function', 'at_halt', 'create_prolog_flag', + 'discontiguous', 'dynamic', 'elif', 'else', 'endif', 'format_predicate', 'if', + 'initialization', 'lazy_list_iterator', 'listing', 'load_extensions', + 'meta_predicate', 'mode', 'module', 'module_transparent', 'multifile', 'op', + 'persistent', 'pop_operators', 'pred', 'predicate_options', + 'prolog_load_context', 'public', 'push_operators', 'record', + 'redefine_system_predicate', 'reexport', 'set_prolog_flag', 'setting', + 'thread_local', 'type', 'use_foreign_library', 'use_module', 'volatile', + + -- Built-in predicates, generated in SWI-Prolog via current_predictate/1. + 'abolish', 'abort', 'absolute_file_name', 'access_file', 'acyclic_term', + 'add_import_module', 'append', 'apply', 'arg', 'assert', 'asserta', 'assertz', + 'at_end_of_stream', 'at_halt', 'atom', 'atom_chars', 'atom_codes', + 'atom_concat', 'atomic', 'atomic_concat', 'atomic_list_concat', + 'atomics_to_string', 'atom_length', 'atom_number', 'atom_prefix', + 'atom_string', 'atom_to_term', 'attach_packs', 'attvar', 'autoload_path', + 'bagof', 'between', 'b_getval', 'blob', 'break', 'b_set_dict', 'b_setval', + 'byte_count', 'call', 'callable', 'call_cleanup', 'call_continuation', + 'call_dcg', 'call_residue_vars', 'call_shared_object_function', + 'call_with_depth_limit', 'call_with_inference_limit', 'cancel_halt', 'catch', + 'character_count', 'char_code', 'char_conversion', 'char_type', 'clause', + 'clause_property', 'close', 'close_shared_object', 'code_type', + 'collation_key', 'compare', 'compile_aux_clauses', 'compile_predicates', + 'compiling', 'compound', 'compound_name_arguments', 'compound_name_arity', + 'consult', 'context_module', 'copy_predicate_clauses', 'copy_stream_data', + 'copy_term', 'copy_term_nat', 'create_prolog_flag', + 'current_arithmetic_function', 'current_atom', 'current_blob', + 'current_char_conversion', 'current_engine', 'current_flag', + 'current_format_predicate', 'current_functor', 'current_input', 'current_key', + 'current_locale', 'current_module', 'current_op', 'current_output', + 'current_predicate', 'current_prolog_flag', 'current_resource', + 'current_signal', 'current_trie', 'cwd', 'cyclic_term', 'date_time_stamp', + 'dcg_translate_rule', 'debugging', 'default_module', 'del_attr', 'del_attrs', + 'del_dict', 'delete_directory', 'delete_file', 'delete_import_module', + 'deterministic', 'dict_create', 'dict_pairs', 'directory_files', 'divmod', + 'downcase_atom', 'duplicate_term', 'dwim_match', 'dwim_predicate', + 'engine_create', 'engine_destroy', 'engine_fetch', 'engine_next', + 'engine_next_reified', 'engine_post', 'engine_self', 'engine_yield', + 'ensure_loaded', 'erase', 'exception', 'exists_directory', 'exists_file', + 'expand_answer', 'expand_file_name', 'expand_file_search_path', 'expand_goal', + 'expand_query', 'expand_term', 'export', 'extern_indirect', 'fail', 'false', + 'fast_read', 'fast_term_serialized', 'fast_write', 'file_base_name', + 'file_directory_name', 'file_name_extension', 'file_search_path', + 'fill_buffer', 'findall', 'findnsols', 'flag', 'float', 'flush_output', + 'forall', 'format', 'format_predicate', 'format_time', 'freeze', 'frozen', + 'functor', 'garbage_collect', 'garbage_collect_atoms', + 'garbage_collect_clauses', 'gc_file_search_cache', 'get0', 'get', 'get_attr', + 'get_attrs', 'get_byte', 'get_char', 'get_code', 'get_dict', 'getenv', + 'get_flag', 'get_single_char', 'get_string_code', 'get_time', + 'goal_expansion', 'ground', 'halt', 'ignore', 'import', 'import_module', + 'instance', 'integer', 'intern_indirect', 'is_absolute_file_name', 'is_dict', + 'is_engine', 'is_list', 'is_stream', 'is_thread', 'keysort', 'known_licenses', + 'leash', 'length', 'library_directory', 'license', 'line_count', + 'line_position', 'load_files', 'locale_create', 'locale_destroy', + 'locale_property', 'make_directory', 'make_library_index', 'memberchk', + 'message_hook', 'message_property', 'message_queue_create', + 'message_queue_destroy', 'message_queue_property', 'message_to_string', + 'module', 'module_property', 'msort', 'mutex_create', 'mutex_destroy', + 'mutex_lock', 'mutex_property', 'mutex_statistics', 'mutex_trylock', + 'mutex_unlock', 'mutex_unlock_all', 'name', 'nb_current', 'nb_delete', + 'nb_getval', 'nb_linkarg', 'nb_link_dict', 'nb_linkval', 'nb_setarg', + 'nb_set_dict', 'nb_setval', 'nl', 'nonvar', 'noprofile', 'noprotocol', + 'normalize_space', 'nospy', 'nospyall', 'not', 'notrace', 'nth_clause', + 'nth_integer_root_and_remainder', 'number', 'number_chars', 'number_codes', + 'number_string', 'numbervars', 'once', 'on_signal', 'op', 'open', + 'open_null_stream', 'open_resource', 'open_shared_object', 'open_string', + 'open_xterm', 'peek_byte', 'peek_char', 'peek_code', 'peek_string', 'phrase', + 'plus', 'portray', 'predicate_option_mode', 'predicate_option_type', + 'predicate_property', 'print', 'print_message', 'print_message_lines', + 'print_toplevel_variables', 'profiler', 'prolog', 'prolog_choice_attribute', + 'prolog_current_choice', 'prolog_current_frame', 'prolog_cut_to', + 'prolog_debug', 'prolog_event_hook', 'prolog_file_type', + 'prolog_frame_attribute', 'prolog_list_goal', 'prolog_load_context', + 'prolog_load_file', 'prolog_nodebug', 'prolog_skip_frame', + 'prolog_skip_level', 'prolog_stack_property', 'prolog_to_os_filename', + 'prompt1', 'prompt', 'protocol', 'protocola', 'protocolling', 'put', + 'put_attr', 'put_attrs', 'put_byte', 'put_char', 'put_code', 'put_dict', + 'pwd', 'qcompile', 'random_property', 'rational', 'read', 'read_clause', + 'read_history', 'read_link', 'read_pending_chars', 'read_pending_codes', + 'read_string', 'read_term', 'read_term_from_atom', 'recorda', 'recorded', + 'recordz', 'redefine_system_predicate', 'reexport', 'reload_library_index', + 'rename_file', 'repeat', 'require', 'reset', 'reset_profiler', + 'residual_goals', 'resource', 'retract', 'retractall', 'same_file', + 'same_term', 'see', 'seeing', 'seek', 'seen', 'select_dict', 'setarg', + 'set_end_of_stream', 'setenv', 'set_flag', 'set_input', 'set_locale', + 'setlocale', 'set_module', 'setof', 'set_output', 'set_prolog_flag', + 'set_prolog_IO', 'set_prolog_stack', 'set_random', 'set_stream', + 'set_stream_position', 'setup_call_catcher_cleanup', 'setup_call_cleanup', + 'shell', 'shift', 'size_file', 'skip', 'sleep', 'sort', 'source_file', + 'source_file_property', 'source_location', 'split_string', 'spy', + 'stamp_date_time', 'statistics', 'stream_pair', 'stream_position_data', + 'stream_property', 'string', 'string_chars', 'string_code', 'string_codes', + 'string_concat', 'string_length', 'string_lower', 'string_upper', + 'strip_module', 'style_check', 'sub_atom', 'sub_atom_icasechk', 'sub_string', + 'subsumes_term', 'succ', 'swiplrc', 'tab', 'tell', 'telling', 'term_attvars', + 'term_expansion', 'term_hash', 'term_string', 'term_to_atom', + 'term_variables', 'text_to_string', 'thread_at_exit', 'thread_create', + 'thread_detach', 'thread_exit', 'thread_get_message', 'thread_join', + 'thread_message_hook', 'thread_peek_message', 'thread_property', + 'thread_self', 'thread_send_message', 'thread_setconcurrency', + 'thread_signal', 'thread_statistics', 'throw', 'time_file', 'tmp_file', + 'tmp_file_stream', 'told', 'trace', 'tracing', 'trie_destroy', 'trie_gen', + 'trie_insert', 'trie_insert_new', 'trie_lookup', 'trie_new', 'trie_property', + 'trie_term', 'trim_stacks', 'true', 'ttyflush', 'tty_get_capability', + 'tty_goto', 'tty_put', 'tty_size', 'unifiable', 'unify_with_occurs_check', + 'unload_file', 'unsetenv', 'upcase_atom', 'use_module', 'var', 'variant_hash', + 'variant_sha1', 'var_number', 'var_property', 'verbose_expansion', 'version', + 'visible', 'wait_for_input', 'wildcard_match', 'with_mutex', 'with_output_to', + 'working_directory', 'write', 'write_canonical', 'write_length', 'writeln', + 'writeq', 'write_term', + + -- Built-in functions, generated in SWI-Prolog via current_arithmetic_function/1. + 'xor', 'rem', 'rdiv', 'mod', 'div', 'abs', 'acos', 'acosh', 'asin', 'asinh', + 'atan2', 'atan', 'atanh', 'ceil', 'ceiling', 'copysign', 'cos', 'cosh', + 'cputime', 'e', 'epsilon', 'erf', 'erfc', 'eval', 'exp', 'float', + 'float_fractional_part', 'float_integer_part', 'floor', 'gcd', 'getbit', + 'inf', 'integer', 'lgamma', 'log10', 'log', 'lsb', 'max', 'min', 'msb', + 'nan', 'pi', 'popcount', 'powm', 'random', 'random_float', 'rational', + 'rationalize', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', + 'truncate', }) -- Identifiers. diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua index 4d522e6..5a6259a 100644 --- a/lua/plugins/filetype.lua +++ b/lua/plugins/filetype.lua @@ -214,6 +214,9 @@ vis.ftdetect.filetypes = { litcoffee = { ext = { "%.litcoffee$" }, }, + logtalk = { + ext = { "%.lgt$" }, + }, lua = { ext = { "%.lua$" }, mime = { "text/x-lua" }, diff --git a/lua/plugins/textobject-lexer.lua b/lua/plugins/textobject-lexer.lua index ef29a9c..fc4876b 100644 --- a/lua/plugins/textobject-lexer.lua +++ b/lua/plugins/textobject-lexer.lua @@ -14,7 +14,7 @@ vis:textobject_new("ii", function(win, pos) end -- TODO make sure we start at a line boundary? - local lexer = vis.lexers.load(win.syntax) + local lexer = vis.lexers.load(win.syntax, nil, true) local data = win.file:content(before, after - before) local tokens = lexer:lex(data) local cur = before diff --git a/lua/vis-std.lua b/lua/vis-std.lua index f7dc4f5..01d137a 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -39,7 +39,7 @@ end, "Number of bytes to consider for syntax highlighting") vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win) if win.syntax == nil or vis.lexers == nil then return end - local lexer = vis.lexers.load(win.syntax) + local lexer = vis.lexers.load(win.syntax, nil, true) if lexer == nil then return end -- TODO: improve heuristic for initial style |
