Skip to content

Frontend parsing breakdown #4131

Open
Open
@gtrepta

Description

@gtrepta

(WIP)

Kompile calls parseDefinition, which calls out to the DefinitionParsing class that handles all the frontend outer/inner parsing. Its first step is to do outer parsing, things it does here that are noteworthy:

  • A parsing utility method called slurp is used to parse the modules in the definition file, resolve file paths in requires clauses, and recursively slurp those files into the definition.
  • Automatically parses and adds prelude.md to the definition unless --no-prelude was passed
  • Resolves the main/syntax modules, throwing an error if it can't do that
  • Checks for modules with duplicate names and throws an error if they aren't the same module (a module could somehow be parsed in twice, for instance)
  • Checks user list declarations for proper structure
  • Checks bracket productions for proper structure as well
  • Convert user lists into kore representable productions
  • Regex terminals are converted, with special handling of lookahead/lookbehind assertions.
  • Syntax priority/associativity sentences are generated from priority blocks, and production attributes.
  • Temporarily add sort declarations for configuration cells and fragments that are possibly being used as nonterminals in productions.
  • The modules are flat (imports in the module are just import sentences) by this point, they get resolved into kore modules where the imports are modules themselves.
  • Syntax synonyms get resolved (ie. if you have syntax Num = Int, then any productions with Num nonterminals become Int)
  • Trims any modules from the definition that can't be reached through the main module's imports. Also includes some builtin modules that are/were necessary (MAP, K-REFLECTION, STDIN-STREAM, STDOUT-STREAM. K-IO if --coverage is used)

At this point it's time to do inner parsing. This is done in two steps, first on the configuration declarations and then on the rest of the definition.

Briefly, Resolving the configuration bubbles does a few things:

  • Adds the DEFAULT-CONFIGURATION to the main module's imports if it doesn't have it's own configuration declaration
  • Adds the MAP module to the main module's imports as well, as it's necessary for configuration initialization. (An error will be thrown if it can't somehow find the MAP module in the definition!)
  • Parses the configuration bubbles across the entire definition.
  • Adds the parsed configurations to the modules in the definition.
  • Checks for duplicate K cells or usage of reserved cell names.
  • Adds the syntax/rules associated with the parsed configuration to the modules.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions