BenjaminSchaaf / sbnf

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

Non-overlapping sub-scope specializations #1

Open FichteFoll opened 4 years ago

FichteFoll commented 4 years ago

The scope naming conventions on the ST docs page mention that e.g. for function meta scopes their specialization should not be stacked. In particular, this means that the function body should be scoped as meta.function.body and not meta.function meta.function.body.

A possible solution for SBNF would be the following syntax, where a scope beginning with a . would extend the last scope on the stack instead of pushing a new scope onto it.

function-definition{meta.function} = `fn` '[a-zA-Z]+'{.name} function-parameters function-body ;
function-parameters{.parameters} = `(` `)` ;
function-body{.body} = block ;

The same concept also applies to mapping keys and values, annotations, and possibly further specializations that haven't been standardized yet.

clear_scopes doesn't seem to be implemented by snbf yet, but if it was, it should be applied first, i.e. the specialization be applied on second-to-last scope.