Search in sources :

Example 1 with ExprBad

use of edu.mit.csail.sdg.ast.ExprBad in project org.alloytools.alloy by AlloyTools.

the class OurSyntaxWidget method getTooltip.

public String getTooltip(MouseEvent event) {
    try {
        int offset = pane.viewToModel(event.getPoint());
        CompModule module = getModule();
        if (module == null)
            return null;
        String text = pane.getText();
        Pos pos = Pos.toPos(text, offset, offset + 1);
        Expr expr = module.find(pos);
        if (expr instanceof ExprBad) {
            return expr.toString();
        }
        if (expr != null) {
            Clause referenced = expr.referenced();
            if (referenced != null) {
                String s = referenced.explain();
                String table = "<html><pre>" + s + "</pre></html>";
                s = table.replaceAll("\n", "<br/>");
                return s;
            } else if (expr instanceof ExprConstant) {
                String token = pos.substring(text);
                if (token != null) {
                    String match = expr.toString();
                    if (!Objects.equals(token, match))
                        return match;
                }
            }
        }
    } catch (Exception e) {
    // e.printStackTrace();
    // ignore compile errors etc.
    }
    return null;
}
Also used : ExprBad(edu.mit.csail.sdg.ast.ExprBad) CompModule(edu.mit.csail.sdg.parser.CompModule) Expr(edu.mit.csail.sdg.ast.Expr) Clause(edu.mit.csail.sdg.ast.Clause) ExprConstant(edu.mit.csail.sdg.ast.ExprConstant) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with ExprBad

use of edu.mit.csail.sdg.ast.ExprBad in project org.alloytools.alloy by AlloyTools.

the class Macro method instantiate.

/**
 * Instantiate it.
 *
 * @param warnings - the list that will receive any warning we generate; can be
 *            null if we wish to ignore warnings
 */
Expr instantiate(Context cx, List<ErrorWarning> warnings) throws Err {
    if (cx.unrolls <= 0) {
        Pos p = span();
        return new ExprBad(p, toString(), new ErrorType(p, "Macro substitution too deep; possibly indicating an infinite recursion."));
    }
    if (params.size() != args.size())
        return this;
    Context cx2 = new Context(realModule, warnings, cx.unrolls - 1);
    for (int n = params.size(), i = 0; i < n; i++) {
        Expr tmp = args.get(i);
        if (!(tmp instanceof Macro))
            tmp = tmp.resolve(tmp.type(), warnings);
        cx2.put(params.get(i).label, tmp);
    }
    return cx2.check(body);
}
Also used : Context(edu.mit.csail.sdg.parser.CompModule.Context) ExprBad(edu.mit.csail.sdg.ast.ExprBad) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Expr(edu.mit.csail.sdg.ast.Expr) Pos(edu.mit.csail.sdg.alloy4.Pos)

Aggregations

Expr (edu.mit.csail.sdg.ast.Expr)2 ExprBad (edu.mit.csail.sdg.ast.ExprBad)2 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)1 Pos (edu.mit.csail.sdg.alloy4.Pos)1 Clause (edu.mit.csail.sdg.ast.Clause)1 ExprConstant (edu.mit.csail.sdg.ast.ExprConstant)1 CompModule (edu.mit.csail.sdg.parser.CompModule)1 Context (edu.mit.csail.sdg.parser.CompModule.Context)1 BadLocationException (javax.swing.text.BadLocationException)1