Sublime Forum

[syntax definition] allow to nest contexts within contexts

#1

For readability, maintenance and organization, it’d be neat if we could next a context definition inside another context. a nested context would then only be useable inside the enclosing context. Thus we could have:

contexts:
  general_context_1:
    - nested_contexts:
        specific_context_a_only_really used_inisde_context_1:
          #...
        specific_context_a_only_really used_inisde_context_1:
          #...
        #more specific contexts
  general_context_2
    - nested_contexts:
        specific_context_c_only_really used_inisde_context_2:
          #...
        specific_context_d_only_really used_inisde_context_2:
          #...
        #more specific contexts

instead of

contexts:
  general_context_1:
    #...
  specific_context_a_only_really used_inisde_context_1:
    #...
  specific_context_a_only_really used_inisde_context_1:
    #...
  #more 1-specific contexts
  general_context_2
    #...
  specific_context_c_only_really used_inisde_context_2:
    #...
  specific_context_d_only_really used_inisde_context_2:
    #...
  #more 2-specific contexts

In the proposed way, it’s crystal clear where a context is just a specialised state in a more general construct, and I suspect many standard syntaxes could be made more readable for new developers that read/study them.

0 Likes

#2

I guess you can’t use anonymous contexts because you want to refer to them more than once from the “parent” context?
maybe just name them so that the specific contexts start with the name of the general context.
I don’t really feel the need for this feature because it’s fairly easy to see where contexts are referenced from and jump around

2 Likes

#3

Yes, you are correct in your first assumption. And maybe it’s that I’m used to think in an OO manner (even lexically so) but I feel like having some sort of scope-and-indet-based structure for scopes would be beneficial.

Yes, I can sooner or later figure out what is used where, but e.g. going into the c# syntax definition it’s quite nightmarish to figure out how do things works and to retain in your memory the relations between different contexts.

0 Likes

#4

Sorry for that ^^. The idea is that most of the time I tried to make it like that:

general_context_1:

specific_context_1_1:

specific_context_1_2:

general_context_2:

specific_context_2_1:

specific_context_2_2:

But that’s probably not always true.

0 Likes

#5

Hey, if anything, it’s me who should apologise: probably my wording made it sound harsher than I intended. I didn’t meant to critizise that syntax in particular, just to illustrate the general point that the more complex the syntax, the harder to graps its structure whith the current format, in general.

1 Like