Class ToAst

java.lang.Object
org.clafer.ast.ToAst

public final class ToAst extends Object
Builds chocosolver's AstModel from a static explicit model of the explicit IR: the core explicit model that clafer -m clafer --core prints, a static rich one, which it lowers to the core with ToCore, or what AstPrinter prints. It resolves the names: the clafers, which may be used before they are declared, and the variables of the quantifiers.

The clafers are created in the order of the source, so that the instances are numbered as the compiler numbers them, then given their super clafers, and then their references and group cards, after their super clafers'. What the printer writes because it applies, this sets only where it is not inherited: a group card equal to the super clafer's is the super clafer's. A written reference is the clafer's own.

A nested abstract clafer's multiplicity counts the instances of its subclafers in each parent, so it becomes a constraint of the parent on #this.A, as the compiler gives it to chocosolver. A temporal model has a diagnostic on each line with a temporal construct, since chocosolver solves only static models. real and double have no solver.

Clafers, constraints, objectives and assertions get the spans of their source, so chocosolver's errors name their positions. Errors do not stop the build: it reports a diagnostic and goes on with the next declaration or constraint.

  • Method Details

    • parse

      public static ToAst.Result parse(String source)
      Parses an explicit model and builds its AstModel.
      Parameters:
      source - the text
      Returns:
      the model, its objectives and assertions, and the errors of the parser and the build, by position
    • toAst

      public static ToAst.Result toAst(Ir.Model tree)
      Builds the AstModel of an explicit model.
      Parameters:
      tree - the explicit model
      Returns:
      the model, its objectives and assertions, and the errors