maint: update required modules to more recent versions.

* src/loadlua.lua.in (std): Require release 35.
(strict): Now spelled 'std.strict'.
(posix): Require release 5.1.28.
(rex_gnu): Require release 2.7.2.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
keycode: use fast homegrown Set instead of std.set.

Provide equivalent semantics to old version of std.set that this
code was written against, saving some indirection and function
call stack frames.
* src/keycode.lua (_mt, Set): Fast implementation.
(is_key, is_modifier): Use it.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
buffer: upgrade to alien strbufs from lua branch tip.

* src/estr.lua, src/astr.lua: Copy from lua branch.
* src/buffer.lua, src/search.lua: Adjust all callers.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
ui: add support for basic color theming.

* src/zi.lua.in (PATH_THEMEDIR): Path to themes.
* Makefile.am (install_edit, inplace_edit): Substitute
pkgthemedir.
* src/bundle.lua: New file. Initialise global 'theme' table from
a named zi theme file.
* src/main.lua (main): If the user startup files didn't do so
already, then load the default color theme.
* src/term_curses.lua (display): New dictionary mapping curses
font rendering capabilities to generic values.
(init_pair): Create a new curses color pair on demand.
(term_get_attribute): Calculate a curses attribute from a theme
file attribute entry.
* src/term_redisplay.lua (draw_end_of_line, draw_status_line)
(term_tidy): Use themeable font rendering attribute.
* theme/Makefile.am: Install theme files.
* theme/README: Description of the theme files syntax.
* theme/zi.lua: New default theme with minimal chrome coloring.
* theme/zile.lua: New theme, equivalent to pre-theming look.
syntax: add support for basic syntax highlighting.

* grammar/lua.syntax: New syntax grammar for Lua language.
* grammar/Makefile.am: Install syntax grammars.
* src/zi.lua.in (PATH_GRAMMARDIR): Path to themes.
* Makefile.am (install_edit, inplace_edit): Substitute
pkggrammardir.
* src/bundle.lua: Use lrex onigurama engine for easier porting
of TextMate grammar files.
(load_grammar): Initial massaging of a grammar file for fast
access to attributes.
* src/buffer.lua (buffer_new): Initialise syntax member.
* src/file.lua (find_file): Load the grammar when opening a new
file.
* src/main.lua (main): Highlight the scratch buffer correctly.
* src/syntax.lua: New file. Return a sparse array of attributes
for a line of text according to that buffer's grammar.
* src/term_redisplay.lua (draw_line): Use it to set attributes
as the line is displayed.
* src/Makefile.am (src_zi_LUA): Add new src/syntax.lua.
syntax: select the appropriate mode according to file extension

* grammar/diff.syntax: New file, with the syntax grammar for diff
and patch files.
* theme/zi.lua: Set highlight styles for new diff grammar.
* src/bundle.lua (load_file_associations): Load a map of file
extension to grammar basename using the fileTypes key in each
grammar file.
* src/term_redisplay.lua (draw_status_line): Display the name of
the loaded grammar for the current buffer in its mode-line.
refactor: centralise parser state in a table.

* src/syntax.lua (state.new): New function. Return a new parser
state...
(syntax_attrs): ...refactored from here.
(highlight): Change to accept a single state table parameter.
(parse): Likewise, but save long derefrence chains into locals
for better access speed.
refactor: add parser state metamethods and simplify.

* src/syntax.lua (push_op): Moved from here...
(metatable.push_op): ...to here.  Adjust all callers.
(metatable.get_attrs, metatable.get_ops, metatable.get_highlights)
(metatable.get_pats, metatable.get_s): Hide access to parser state
internals behind accessor methods. Adjust all callers.
(state.new): Set the metatable on the new parser state.
(highlight): Cache parser attrs and ops in locals for faster
access.
syntax: support colored capture expressions.

* src/bundle.lua (scopetoattr): Factor out attribute lookup by
scope name.
(compile_patterns): New function. Factored out of load_grammar.
(load_grammar): Adjust.
* src/syntax.lua (rex_exec): Also adjust capture indexes to be
0-based.
(parse): Queue additional instructions for highlighting captures.
syntax: support begin and end expressions on a single line.

* src/bundle.lua (capturestoattr): Call scopetoattr for each
element of captures.
(load_grammar): Factor out pattern compilation from here...
(compile_patterns): New function.  ...to here.
(compile_rex): Precompile onig regular expressions.
* src/syntax.lua (leftmost_match): Account for matching against
expressions in .rex and .finish.
(parse): keep a pattern stack so that we can push a new pattern
list onto the stack for matching subexpressions, and then pop
back to the original when the finish expression is matched.
Similarly, save the active color to a color stack when a new
pattern list is pushed, and use that to color the whole begin/
end pair when the finish expression is matched.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
syntax: support back-references in grammar end expressions.

Somewhat trickier than expected because we do want to match the
likes of \2, while not accidentally expanding \\2 (not a back-
reference, just an escaped backslash followed by a plain 2):
* src/bundle.lua (compile_rex): Now a global function.
(has_backrefs): New function to check for back-references, being
careful of unbalanced escapes.
(compile_grammar): Don't precompile `end' expressions with un-
resolved back-references.
* src/syntax.lua (expand): New function to expand back-
references in expressions using a reference string and capture
offsets, and then compile on demand; again being careful of
unbalanced escapes.
(parse): Pass capture offsets to expression matches, and use
them to expand back-references on demand.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
syntax: support grammar repository and include references.

* grammar/lua.syntax (string.quoted.single.lua)
(string.quoted.double.lua): Use repository to reduce repetition
of escaped character patterns.
(string.quoted.single.lua, string.quoted.double.lua): Add
repository pattern for % placeholders in format strings.
* src/bundle.lua (compile_pattern): Factored out from the
inner loop of compile_patterns.
(load_grammar): Use compile_patterns on repository entries
too.
* src/syntax.lua (leftmost_match): Look-up include references
in the grammar repository, and perform matches against any
expressions or pattern list found there.
syntax: only recalculate edited line and onwards

* src/buffer.lua (replace_estr): Mark newly edited line as dirty.
* src/syntax.lua (state.new): Bump dirty.  Store bp and lnum.
(metadata.get_lnum): New accessor method.
(syntax_attrs): Unless this line has been edited since the last
time it was displayed, or comes after the last edited line, just
return the highlighting calculated last time.
syntax: support multi-line syntax matches.

* src/syntax.c (state.init): Store the initial state for the
parser in the first line of the file when first called.
(state.new): Copy the stored parser state for this line into the
new state table.
(metatable.store): After highlighting, save the current state to the
next line in the buffer so that we can pick up highlighting from
there without re-parsing the entire file.
ui: preliminary non-blocking syntax highlighting.

TODO: only refresh highlights in active window buffer