Child pages
  • ExtensibleRule

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Code Block
syntax ExtensibleRule = RuleAttributes "syntax" Name ExtensibleRuleBody;

ExtensibleRule declares the rule that allows you to specify options.   

For example, the following Key rule contains the three options: StringLiteral1, StringLiteral2, and Identifier:

Code Block
syntax Key
{
  | StringLiteral1
  | StringLiteral2
  | Identifier
}

This rule is similar to the following BNF rule:

Code Block
Key = StringLiteral1 | StringLiteral2 | Identifier;

ExtensibleRule lets you define extension bodies in-place:

Code Block
syntax Value
{
  | Object = "{" (Property; ",")* "}";
  | Array  = "[" (Value; ",")* "]";
  | Identifier
  | StringLiteral1
  | StringLiteral2
  | Number
  | "true"
  | "false"
  | "null"
}

ExtensibleRule might not contain any extensions whatsoever:

Code Block
syntax Value
{
}

Extensions can be added later on, for example, in another syntax module defined in a separate assembly.

The reason ExtensibleRule is named “extensible”, is it’s a grammar extension point. Any extensible rule can be extended in a different syntax module (see ExtendSyntax). Besides, the syntax module that extends a rule from another module can be defined in the assembly with the one being extended, as well as in a separate assembly.

Rules can be extended dynamically. It can be done during the grammar loading process as well as during the parsing. This way Nitra-based languages grammar can be dynamically changed, which may be useful when creating changeable syntax languages (such as Nemerle), or when applying extensions to classic languages and DSL.

See also

RuleAttributes
Name
ExtensibleRuleBody