Skip to content

Rewrite v2 #1

@SamTebbs33

Description

@SamTebbs33

The whole system should be replaced with a more modular system, consisting of a frontend, midend and backend:

  • Frontend: Consists of a grammar for the language and a parser that parses that grammar and converts it into a JSON syntax tree.
  • Midend: Provides a mapping between Elk syntax elements and HTML. The mapping comes in the form of a JSON object with each element specifying its components and how its HTML is computed.
  • Backend: Performs the conversion between Elk and HTML according to the mapping. This should just require running an interpreter to interpret the mapping code, providing it with some hooks (template storage) and the syntax elements given in the syntax tree.

An example of a syntax tree for


html {
  h1: Hi!
}

would e.g. be

{
  "class": "StatementBody",
  "terminal": false,
  "fields": [
    {
      "class": "Tag",
      "terminal": false,
      "fields": [ { "class": "ID", "terminal": true, "value": "html" },
        {
          "class": "StatementBody",
          "terminal": false,
          "fields": [
            {
              "class": "Tag",
              "terminal": false,
              "fields": [{ "class": "String", "terminal": true, "value": "hi!" }]
            }
          ]
        }
        ]
    }
  ]
}

A midend mapping for a Tag could look something like:

{
  "name": "Tag",
  "fields": [ { "name": "id", "class": "ID" }, { "name": metadata", "class": "Metadata" }, { "name": "body", "class": "StatementBody" } ],
  "mapping": "return '<$id $metadata>$body</$id>'"
}

This would make porting to other platforms (e.g. Java, C, Scala) much simpler since only the parser and backend have to be re-implemented for the new platform, rather than that as well as the mapping and class structure.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions