Commit graph

10 commits

Author SHA1 Message Date
Jöran Karl
c3052b491f
parser: Check and prompt for empty patterns and region properties (fix crash) (#3256)
* 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
2024-04-21 20:13:28 +02:00
Dmytro Maluka
dc833d3552 Check for missing or empty filetype in syntax files
To avoid surprises like with jsonnet.
2024-03-28 01:22:25 +01:00
Dmytro Maluka
08892b125f
Fix crash when syntax file has no rules (#3213)
If a syntax file aaa.yaml contains no `rules` directive, then after
`set filetype aaa` micro crashes with d.rules nil pointer dereference
in HasIncludes():

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:221 (0x44c527)
runtime/panic.go:220 (0x44c4f7)
github.com/zyedidia/micro/v2/pkg/highlight/parser.go:239 (0x820919)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:830 (0x82b818)
github.com/zyedidia/micro/v2/internal/buffer/settings.go:33 (0x83b665)
github.com/zyedidia/micro/v2/internal/action/command.go:578 (0x87d75f)
github.com/zyedidia/micro/v2/internal/action/command.go:598 (0x87da79)
github.com/zyedidia/micro/v2/internal/action/command.go:634 (0x87de54)
github.com/zyedidia/micro/v2/internal/action/command.go:1030 (0x880f68)
github.com/zyedidia/micro/v2/internal/action/actions.go:1545 (0x870d72)
github.com/zyedidia/micro/v2/internal/info/infobuffer.go:152 (0x8421b4)
github.com/zyedidia/micro/v2/internal/action/infopane.go:208 (0x8854cc)
github.com/zyedidia/micro/v2/internal/action/infopane.go:54 (0x8844d6)
github.com/zyedidia/micro/v2/internal/action/infopane.go:131 (0x884d42)
github.com/zyedidia/micro/v2/internal/action/infopane.go:95 (0x8849ff)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:481 (0x8bfb86)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:397 (0x8bf63e)
runtime/proc.go:255 (0x438867)
runtime/asm_amd64.s:1581 (0x467a81)
2024-03-25 19:35:57 +01:00
Dmytro Maluka
3f4942cedb syntax parser: reintroduce header regex in .hdr files
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.
2024-03-24 04:47:04 +01:00
Jöran Karl
433879046e Improve file detection with signature check capabilities
This allows more complex detection upon regex rules for a certain amount of
lines.
2023-10-26 20:20:02 +02:00
Dmitry Maluka
9fabffc880
Fix issues with handling invalid regex in syntax files (#2913)
* 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.
2023-09-09 19:17:23 -07:00
Zachary Yedidia
bd83c6a8a9 Remove detect requirement and detect in jinja file
Ref #1415
2019-12-28 22:27:44 -05:00
Zachary Yedidia
5b52b8a60f Support includes 2019-12-28 21:57:03 -05:00
Zachary Yedidia
a61616d79e More efficient loading for default syntax files
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
2019-12-28 21:26:22 -05:00
Zachary Yedidia
0612af1590 Change project layout and use go.mod 2019-12-25 17:05:10 -05:00
Renamed from cmd/micro/highlight/parser.go (Browse further)