Child pages
  • Inline code syntax

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

I extremely don't like code inline with rules. One of the biggest things in Nitra is clean grammar, so that you can work with language in a straightforward way.
Here is an example:

Code Block
    ChoiceTokenRule                  = LeftRule sm RightRules
      alias LeftRule = TokenRule : 10;
      alias RightRules = ("|" TokenRule : 10)+;
      override MakeContext
        def context1 = LeftRule.MakeContext(parent);
        def context2 = FoldThrough(RightRules, context1, ((_, r), c) => r.MakeContext(c));
      override Typing = RegularRule.Choice(Location, LeftRule.Typing() :: RightRules.Map(r => r[1].Typing()));

Here syntax has rule definition, aliases, some behavior definition, which is so similar syntactically, but so different semantically that it requires conscious parsing by brains to understand what is this. I could tell that it violates SOLID in every way possible, but philosophy aside it will be huge nightmare to maintain and evolve.

I propose separation of syntactical and semantic aspects.

  • syntax and action should never appear in a same construct
  • they can appear in the same file side by side, so they are part of the same language
  • actions declarations are like "parts" of same declaration, so you can have one file with all Typing actions and another file with all Formatting actions.

Proposed approach is by defining Calculations