Package org.clafer.frontend


package org.clafer.frontend
This package provides the Java frontend of Clafer: a port of the Clafer compiler that reads .cfr models without the Haskell compiler.

It parses the full Clafer language (ClaferParser, with its layout), builds the symbols, checks the model, resolves its names and types, and gives the explicit IR (Ir) and the scopes, as clafer -m clafer gives them; ToCore lowers the rich explicit model to the core. It also reads and prints the explicit languages, follows imports (local files and URLs), and provides claferc (ClaferCommand), the compiler's -m clafer, --core, --meta-data and -m alloy in Java.

  • Class
    Description
    claferc: the Clafer compiler's clafer -m clafer and clafer -m alloy in Java.
    The Clafer compiler, the Haskell clafer, that the Java tools run for what they do not do themselves (clafersg for a model with a [choco| |] escape or with --haskell-frontend, claferc for the modes it forwards): -Dclafer.executable, if it is set; otherwise clafer next to the jar of this class, as in Clafer Tools, where both bundles unpack into one folder with clafersg.jar, claferc.jar and clafer, so that the folder need not be on the PATH; otherwise clafer on the PATH.
    Splits a model in the full Clafer language into tokens, as the compiler's lexer does (clafer.cf, generated by BNFC and Alex).
    The tokens of a model.
    Parses a model in the full Clafer language into its Syntax tree, as the compiler parses it (clafer.cf, generated by BNFC and Happy, and Language.Clafer.parse).
    The tree of a model and its errors.
    The core of the explicit IR: a model is core if and only if it has no rich node (Ir.Node.isRich()).
    An error in the source, with where it is.
    Reads the rich or the core explicit language, as the Clafer compiler prints them (clafer -m clafer, and --core), and the explicit form that chocosolver's AstPrinter prints, into the explicit IR.
    A parsed model.
    Prints the explicit IR exactly as the Clafer compiler prints the rich and the core explicit model (Generator/Explicit.hs), with or without the provenance comments, so that every comparison of two models is a comparison of text.
    The explicit IR: one tree for the rich and the core explicit language of Clafer, as the Clafer compiler prints them (clafer -m clafer, with --core for the core).
    The written bound of a top-level abstract clafer, which counts all its instances, rich: abstract Tools 3..6.
    An anchor, rich: initially p, at the birth of the context, or finally p, at its death.
    An assertion, assert [ exp ].
    A chain of one binary operator: a op b op c.
    The binary operators, by their syntax.
    A function of strings, concat(a, b), prefix(a, b) or suffix(a, b).
    A cardinality, low..high, or low..*.
    upcast(e, T) or downcast(e, T), as chocosolver's printer writes the casts of its analysis.
    A clafer: [abstract] [modifiers] gcard name [: super] [-> | ->> target] card [initializer] { elements }.
    connected(nodes, relation, directed).
    {[1, 2], [3, 4]} :: T * U, a constant set of chocosolver's printer: one row per column of the type.
    A constraint, [ exp ].
    A decimal as written, e.g., 19.99 or -0.5.
    The declarations of a quantifier, [disj] x; y : set.
    A double as written, with its exponent, e.g., 1.2e2.
    left.dref.
    A declaration or constraint of a model or of a clafer.
    An enumeration, rich: enum E = a | b, at the top level.
    An expression.
    if c then a else b, a formula or a set.
    An initializer, rich: = value, or := each value or := together value, with its clock written out (kbak/clafer-semantics#194).
    The initializers, by their syntax.
    An integer, -3 with its sign.
    A navigation, left.right: the right is a name (a child relation), or in chocosolver's printing a relation or a parenthesized set.
    A model: its declarations and constraints in the order they were written, then its objectives and assertions, which the compiler prints at the end.
    A temporal modifier of a clafer, rich.
    The temporal modifiers, by their keywords.
    A name as written: of a clafer, a variable, or a type.
    A name in an expression: a clafer, all its instances or, on the right of a navigation, its relation, or a variable.
    noclafer, the empty set.
    A node of the tree.
    An objective, << max exp >> or << min exp >>.
    The options of the first line, //# OPTIONS --explicit, as the compiler writes them.
    Where a clafer or constraint of the core comes from, as --record-provenance writes it: the rich construct that a lowering made it from, and the position of that construct, e.g., // final, model.cfr:56:5.
    left.parent.
    A behavioral pattern of Dwyer et al.'
    The patterns.
    The scopes of a pattern.
    A position in a source file, as in the compiler's messages.
    q decls | body.
    A quantifier over a set, without variables: some x, no x, lone x, one x, all x.
    The quantifiers.
    A reference: -> target, a set, or ->> target, a bag.
    dref(c) or parent(c), a relation of a clafer, as chocosolver's printer writes it.
    Constraints directly under the root, root { [ exp ] }, as chocosolver's AstPrinter prints a model of its Java API that has them; Clafer has none.
    A string literal as written, with its quotes and escapes.
    A temporal operator of the core: X, F, G, previous, once, historically on one formula, U, W, since, triggered between two.
    The temporal operators of the core.
    this.
    A transition, rich: a --> b, a -[g]-> b, a -->> b or a -[g]->> b, whose target may be a chain of transitions.
    A prefix operator.
    The prefix operators.
    Turns indentation into blocks, as the compiler's layout resolver does (LayoutResolver.resolveLayout): a line indented more than the line before opens a block (TokenKind.INDENT), a line indented less closes the blocks it leaves (TokenKind.DEDENT), and a line at the indentation of a sibling is separated from the line before (TokenKind.SEPARATOR).
    The tokens with the layout made explicit.
    Splits the explicit form of a Clafer model, as AstPrinter prints it, into tokens.
    The tokens of a source text.
    The files of a model: the model and the files it imports, transitively, with --import=FILE in their //# OPTIONS lines, as the compiler reads them (Import.readModel): local files and http or https URLs (Http).
    The restrictions of the imports, which only the command line gives, as the web tools give them to the compiler:
     
    A line in a file.
    The options of a model file that the frontend uses, from its first line, //# OPTIONS ..., as the compiler reads them (Import.fileOptions): --core, --tl, --minint, --maxint, --decimal-digits, --ss and --import.
    What the names of a model refer to, for the language server: the clafers, whose Symbols.ClaferSymbol.nameSpan() is where each is declared, and the clafer that each written name refers to, by the span of the name.
    The scopes that chocosolver solves an explicit model with, as the compiler writes them to the explicit model's scope file (clafer -m clafer --meta-data, model.des.cfr-scope).
    Where a clafer, constraint, assertion or objective is in the source model: from line:column up to, not including, endLine:endColumn.
    The symbols of a model, the first pass after the parser: a symbol per clafer, with its UID, its parent, its super clafer, the type of its reference, its card and group card with the defaults applied, its temporal modifiers and the clock of its initializer.
    A clafer, or an enumeration or one of its literals.
    A group card.
    An interval of a card or a group card.
    The reference of a clafer.
    The modifiers of a reference: finalref, finaltarget, and final, which is both.
    The symbols of a model.
    The syntax tree of a model in the full Clafer language, as written: the tree of the compiler's clafer.cf (AbsClafer), with a span for each node.
    initially e or finally e.
    An assertion, assert [ e ].
    A binary expression.
    The binary operators, with their symbols and levels.
    A cardinality: ?, +, *, a number or an interval.
    A cardinality written as a number, 2.
    A cardinality written as ?, + or *.
    A clafer, e.g., abstract xor A : B -> int ? = 3 { ... }.
    A name in an expression.
    The transition of a clafer, --> e.
    A use of a clafer, `A ? { ... }.
    A constraint, [ e1 e2 ]: the conjunction of its expressions.
    The declaration of a quantifier, x; y : e.
    A declaration at the top level.
    An element: a clafer, a use of a clafer, a constraint, an objective or an assertion.
    The elements of a clafer, in braces or indented.
    An enumeration, enum E = a | b.
    An expression.
    A group cardinality: a keyword or an interval.
    An objective, << minimize e >>.
    How an objective is written.
    A group cardinality written as a keyword: xor, or, mux or opt.
    A name as written, e.g., a clafer's name or a local variable.
    if c then t else e.
    An initializer, = e or := e.
    How an initializer is written.
    let x = v in body.
    A literal: an integer, a double, a real or a string, as written.
    The kinds of literals.
    A model: its declarations in the order they were written.
    A path of names, a\b.
    An interval, 2..3 or 2..*, of a cardinality or of a group cardinality.
    A node of the tree.
    A behavioral pattern, e.g., never e after s, or a must precede b.
    The behavioral patterns.
    The scope of a pattern: before e, after e, between e and e, after e until e.
    The quantifiers.
    A quantified expression without a declaration, some e.
    A quantified expression with a declaration, some disj x : e | body.
    A reference, -> e to a set or ->> e to a bag.
    The scopes of a pattern.
    The super clafer, : e.
    A temporal modifier of a clafer.
    The temporal modifiers.
    A transition arrow: -->, -->> (synchronous), or with a guard, -[ g ]-> and -[ g ]->>.
    A transition, e1 --> e2.
    A prefix expression.
    The prefix operators, with their symbols, levels and the levels of their operands.
    Prints a syntax tree as the compiler's printTree prints its parse tree (PrintClafer, generated by BNFC): the same words, parentheses and line breaks.
    The lowering of the rich explicit model to the explicit core model: the port of the Clafer compiler's lowerAbstractBounds TopLevelBounds . lowerToCore (Intermediate/Core.hs, Initializers.hs, Finality.hs, AbstractMultiplicity.hs), pass by pass and in the same order, so that ExplicitPrinter.print(toCore(m)) is the compiler's --core output for the model of m.
    The explicit IR of a model in the full syntax, as the compiler gives it (clafer -m clafer), and its scopes.
     
    A token: its kind, its text exactly as written, and where it is.
    The kinds of tokens.