Syntactic Abstraction Code

Syntactic abstraction is a mechanism to support the Fortress language growth. The design of the system is described in our  FOOL'09 paper. This page includes a list of the files implementing the syntactic abstraction mechanism with brief comments.

Parser

Entry Points

There are two entry points to the syntactic abstraction code:

Parsing Programs with New Syntax (parseWithGrammars)

  1. ParserMaker.parserForComponent: Create a parser from the grammars.
    1. GrammarComposer.pegForComponent: Composes grammars together into a flat PEG.
    2. ParserMaker.makeParser: Compile a parser given a set of nonterminals and productions.
      1. Turn PEG into a single new module using ComposingSyntaxDefTranslator. Use ArrayUnpacker to handle ellipses nodes.
      2. RatsParserGenerator.generateParser: Given a set of Rats! modules, generate a new Fortress parser extended with the modifications in the given modules.
  2. RatsUtil.getParserObject: Create a Java parser by invoking Rats! and parse the original component with that parser.
  3. Transform.transform: Macro expander. Traverse a given AST node, replacing transformation nodes with the results of their transformer executions, and return a core Fortress AST.
    1. SyntaxEnvironment: Environment used for hygienic transformation

Grammar Rewriting (GrammarRewriter.rewriteApis)

  1. ItemDisambiguator: Disambiguate item symbols and rewrite to either nonterminal, keyword or token symbol.
  2. Disambiguate nonterminal parameters. (Not yet done)
  3. WhitespaceElimination: Remove whitespace where indicated by no-whitespace symbols.
  4. EscapeRewriter: Rewrite escaped symbols.
  5. ExtensionDesugarer: Desugar extensions: fill in unmentioned imported grammars and collect multiple extensions of same nonterminal together.
  6. RewriteTransformerNames: Rewrite transformer names.
  7. TemplateParser: Parse pretemplates and replace with real templates.
    1. TemplateVarRewriter: Rewrite all occurrences of variables in a given template to occurrences of gaps using BaseTypeCollector.

Other Code

Utilities

  1. Ellipses environment
  2. Gap environment
  3. Nonterminal environment using FortressTypeToJavaType
  4. Environment factories
  5. Variable collector

ASTGen CustomGenerators

  1. Ellipses nodes: EllipsesNode, EllipsesNodeCreator
  2. Template nodes: TemplateGapClass, TemplateGapNodeCreator, TemplateVisitorGenerator, TemplateDepthFirstVisitorGenerator, TemplateDepthFirstVoidVisitorGenerator
  3. Transformation nodes: TransformationNode, TransformationNodeCreator
  4. FortressAst libraries: FortressAstGenerator
  5. SingleSpanConstructorGenerator

Compiler

  1. Indices: GrammarIndex, NonterminalDefIndex, NonterminalExtendIndex, NonterminalIndex
  2. Nonterminal disambiguator: NonterminalDisambiguator, NonterminalEnv, NonterminalNameDisambiguator