* parser: Precise error message for missing `start` & `end` in region
* parser: Check and prompt for empty patterns and region properties
* syntax: Remove empty identifier pattern from log definition
Check if startline value is valid before passing it to input.State(),
to prevent a theoretically possible race when the number of lines
changes in the meantime, causing an out of bounds access.
Actually this race cannot happen: ReHighlightStates() is only called
from the main goroutine, and the line array is modified, again, only by
the main goroutine. So for now this change is rather cosmetic: it is
just to make the highligher API implementation self-sufficiently safe
without assumptions about which goroutines are using which API functions
and how.
This is achieved by the usage of the new `LineArray` locking machanism,
which prevents the interruption in the moment of modifications like insertion
or removal of lines.
Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
Replacing header patterns with signature patterns was a mistake, since
both have their own uses. So restore support for header regex, while
keeping support for signature regex as well.
* Fix panic due to invalid regex in a syntax file
When a user's custom syntax file has a malformed filename regex or
header regex, MakeHeaderYaml() returns error but we do not properly
handle it, which results in a panic due to a dereference of the `header`
pointer which is nil:
Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:221 (0x44c367)
runtime/panic.go:220 (0x44c337)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:709 (0x82bc0f)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:392 (0x828292)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:261 (0x8278c8)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:203 (0x8b9e7b)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:331 (0x8ba9e5)
runtime/proc.go:255 (0x4386a7)
runtime/asm_amd64.s:1581 (0x467941)
* Do not ignore invalid filename regex error in a syntax file
When the filename regex in a syntax file is malformed but the subsequent
header regex is correct, the filename regex error gets silently ignored,
since the `err` value is overwritten by the subsequent successful header
regex result.
* highlighter: Fix regions and patterns inside regions
* highlighting: Remove 2nd recursive highlightRegion() call
...and add limitGroup checks to pattern search.
* yaml: Add TODO type highlighting
* highlighting: Don't stop in highlightRegion() at empty lines
...because possible region line end pattern must be detected.
* syntax/sh: Correct string handling due to additional pattern handling
* syntax/sh: Remove slash in variables
* highlighter: Accept nested region only in case it's within the current reagion
* highlighter: Accept nested patterns only in case it's within the current reagion
* highlighter: Don't search for nesting in case the region end was found at start
* highlighter: Fix region & pattern detection
* syntax/sh: Highlight upper case options too
* syntax/c(pp): Try to synchronize the rules to lower the maintenance effort
* syntax/ruby: Fix explicit filename detection in directories
* highlighter: Respect skip rules in regions
* syntax/sh: Fix parameter expansion, cond. flags and generalize filename via ""
* syntax/php|vi: Correct strings in comments to comments only
Additionally improve vimscript comment handling.
* highlighter: Remove problematic start|end check in find(all)Index()
...and additionally remove recursive region end detection
There is a bit of mess in the usage of HighlightMatches: in some places
we assume that it updates lines from startline to endline inclusive,
in other places we assume it's non-inclusive.
This fix makes it always inclusive.
In particular, it fixes a bug: when we open a file which has no
newline at the end, the last line isn't highlighted.
This change introduces header files for syntax files. The header
files only contain the filetype and detection info and can be
parsed much faster than parsing a full yaml file. To determine
which filetype a file is, only scanning the headers is necessary
and afterwards only one yaml file needs to be parsed. Use the
make_headers.go file to generate the header files. Micro expects
that all default syntax files will have header files and that
custom user syntax files may or may not have them. Resolving
includes within syntax has not yet been implemented. This
optimization improves startup time.
Ref #1427