BenjaminSchaaf / sbnf

A BNF-style language for writing sublime-syntax files
MIT License
58 stars 6 forks source link

Include external syntaxes #2

Closed FichteFoll closed 4 years ago

FichteFoll commented 4 years ago

The functionality to include an external syntax, such as a regular expression syntax within sbnf's own syntax definition, is currently missing.

I don't have any concrete proposals, but I wanted to track this as an issue for now.

BenjaminSchaaf commented 4 years ago

The parser currently handles % as an inclusion. My idea was to use the following syntax:

main = '<script>'
       %{Packages/JavaScript/JavaScript.sublime-syntax, js-exit}
     ;

js-exit = '</script>' ;
FichteFoll commented 4 years ago

is the first argument optional on this case? Why not use ST's syntax directly, I. e. path#context or scope:source.blub#context (although you should about scopes and context names at the same time, imo).

~ would also be applicable, if I assume correctly.

BenjaminSchaaf commented 4 years ago

I'm sorry, but I don't quite follow. The first argument is the syntax/context to include, while the second argument is for the with_prototype context.

FichteFoll commented 4 years ago

Oh, my bad. I was reading this on mobile and jumping to conclusions. That makes more sense, of course. Maybe make it a prototype: keyword argument.

BenjaminSchaaf commented 4 years ago

b81563dde34448133d3ead244ace161d38234660 Adds an initial implementation for this. There's still work to do with handling all the edge cases, but the basics are there (I'll leave the issue open until those are done). The example has changed dramatically as I've gotten closer to a working implementation. I've arrived at the following:

scope: text.html

main = ( ~'<sbnf>'{tag.begin, embed: Packages/sbnf/sbnf.sublime-syntax, prototype: js-exit}
       )*
     ;

js-exit = ( ~'</sbnf>'{tag.end} )* ;