Skip to content

Grammar and Subgrammar Structure

Benedict Albrecht edited this page Jun 2, 2026 · 4 revisions

Grammar & Subgrammar Structure

Crodox uses a file-based grammar structure where files can include subgrammars to compose complex language definitions.


File Composition (Top-to-Bottom)

The grammar follows a top-to-bottom hierarchy. Objects defined higher up are inherited by all subgrammars below. Objects inside a subgrammar are not counted additionally at the parent level.

graph TD
    MAIN["<b>File.xy</b><br/>&lt;~ &quot;FROM1&quot;.xy ~&gt;"] --> OA["objectA"]
    MAIN --> OB["objectB"]
    MAIN --> SERVICE["<b>File.service.xy</b><br/>&lt;~ &quot;FROM2&quot;.service.xy ~&gt;"]
    MAIN --> OE["objectE"]
    MAIN --> MODULE["<b>File.module.xy</b><br/>&lt;~ &quot;FROM3&quot;.module.xy ~&gt;"]

    SERVICE -.->|"inherits"| OA
    SERVICE -.->|"inherits"| OB
    SERVICE --> OC["objectC"]
    SERVICE --> OD["objectD"]
    SERVICE -.->|"inherits"| OE

    MODULE -.->|"inherits"| OA
    MODULE -.->|"inherits"| OB
    MODULE -.->|"inherits"| OE
    MODULE --> OF["objectF"]
    MODULE --> OG["objectG"]

    style MAIN fill:#4a90d9,color:#fff
    style SERVICE fill:#7b68ee,color:#fff
    style MODULE fill:#7b68ee,color:#fff
    style OC fill:#7b68ee,color:#fff
    style OD fill:#7b68ee,color:#fff
    style OF fill:#7b68ee,color:#fff
    style OG fill:#7b68ee,color:#fff
Loading

How It Works

Files can nest subgrammars using the file syntax. Each subgrammar inherits objects from its parent scope and adds its own definitions.

Example

<~"FROM1".xy~>
    <*objectA*> objectA <*>
    <*objectB*> objectB <*>

    <~"FROM2".service.xy~>
         <*objectC*> objectC <*>
         <*objectD*> objectD <*>
    <~>

    <*objectE*> objectE <*>

    <~"FROM3".module.xy~>
         <*objectF*> objectF <*>
         <*objectG*> objectG <*>
    <~>
<~>

Resulting Visibility

File Visible Objects
File.xy objectA, objectB, objectE
File.service.xy objectA, objectB, objectC, objectD, objectE
File.module.xy objectA, objectB, objectE, objectF, objectG

Rule: Objects defined at the top level are visible in all subgrammars. Objects defined within a subgrammar are only visible within that subgrammar's scope.


Priority

When two object definitions match the same input, the upper definition takes priority. Objects are matched in the order they are defined - top to bottom.


See also: Dependency Structure - How objects form dependency trees.

Clone this wiki locally