Search in sources :

Example 1 with CompModule

use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.

the class OurSyntaxWidget method doNav.

private void doNav() {
    try {
        String text = pane.getText();
        int[] sel = getCurrentWordSelection(text);
        Pos pos = Pos.toPos(text, sel[0], sel[1]);
        if (pos == null)
            return;
        String currentWord = getCurrentWord();
        if (currentWord == null)
            return;
        CompModule module = getModule();
        if (module == null)
            return;
        Expr expr = module.find(pos);
        if (expr != null) {
            Clause clause = expr.referenced();
            if (clause != null) {
                Pos where = clause.pos();
                if (where.sameFile(module.pos()))
                    select(where);
                else {
                    OurSyntaxWidget ow = parent.open(where);
                    if (ow != null) {
                        ow.select(where);
                    }
                }
            }
        }
    } catch (Exception e) {
    // Ignore, this is a best effort thingy
    }
}
Also used : CompModule(edu.mit.csail.sdg.parser.CompModule) Expr(edu.mit.csail.sdg.ast.Expr) Clause(edu.mit.csail.sdg.ast.Clause) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with CompModule

use of edu.mit.csail.sdg.parser.CompModule 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 3 with CompModule

use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.

the class OurSyntaxWidget method getModule.

CompModule getModule() {
    try {
        A4Reporter reporter = new A4Reporter();
        CompModule module = this.module;
        if (module == null)
            module = CompUtil.parseEverything_fromString(reporter, pane.getText());
        this.module = module;
        return module;
    } catch (Err e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : CompModule(edu.mit.csail.sdg.parser.CompModule)

Example 4 with CompModule

use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.

the class AlloyModelsTest method minimalAlloyDoc.

@Test
public void minimalAlloyDoc() throws Exception {
    CompModule world = CompUtil.parseEverything_fromString(A4Reporter.NOP, "sig Foo  {} \n" + "run {  1 < #Int } for 10 int\n");
    A4Options options = new A4Options();
    options.unrolls = 10;
    for (Command command : world.getAllCommands()) {
        A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
        while (ans.satisfiable()) {
            String hc = "Answer: " + ans.toString().hashCode();
            System.out.println(hc);
            ans = ans.next();
        }
        return;
    }
}
Also used : CompModule(edu.mit.csail.sdg.parser.CompModule) Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) A4Solution(edu.mit.csail.sdg.translator.A4Solution) Test(org.junit.Test)

Example 5 with CompModule

use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.

the class ExampleCompilingFromSource method compileModuleAndRun.

public static void compileModuleAndRun(String model) throws Err {
    A4Reporter rep = new A4Reporter();
    // parse model from string
    CompModule world = CompUtil.parseEverything_fromString(rep, model);
    ConstList<Command> commands = world.getAllCommands();
    if (commands.size() != 1)
        throw new ErrorAPI("Must specify exactly one command; number of commands found: " + commands.size());
    Command cmd = commands.get(0);
    A4Options opt = new A4Options();
    opt.solver = A4Options.SatSolver.SAT4J;
    // solve
    A4Solution sol = TranslateAlloyToKodkod.execute_command(rep, world.getAllSigs(), cmd, opt);
    // print solution
    System.out.println(sol);
    for (Sig sig : world.getAllReachableSigs()) {
        System.out.println("traversing sig: " + sig);
        SafeList<Field> fields = sig.getFields();
        for (Field field : fields) {
            System.out.println("  traversing field: " + field);
            A4TupleSet ts = (sol.eval(field));
            for (A4Tuple t : ts) {
                System.out.print("    [");
                for (int i = 0; i < t.arity(); i++) System.out.print(t.atom(i) + " ");
                System.out.println("]");
            }
        }
    }
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet) Sig(edu.mit.csail.sdg.ast.Sig) Field(edu.mit.csail.sdg.ast.Sig.Field) A4Tuple(edu.mit.csail.sdg.translator.A4Tuple) CompModule(edu.mit.csail.sdg.parser.CompModule) Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Aggregations

CompModule (edu.mit.csail.sdg.parser.CompModule)5 Clause (edu.mit.csail.sdg.ast.Clause)2 Command (edu.mit.csail.sdg.ast.Command)2 Expr (edu.mit.csail.sdg.ast.Expr)2 A4Options (edu.mit.csail.sdg.translator.A4Options)2 A4Solution (edu.mit.csail.sdg.translator.A4Solution)2 BadLocationException (javax.swing.text.BadLocationException)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)1 ExprBad (edu.mit.csail.sdg.ast.ExprBad)1 ExprConstant (edu.mit.csail.sdg.ast.ExprConstant)1 Sig (edu.mit.csail.sdg.ast.Sig)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)1 A4TupleSet (edu.mit.csail.sdg.translator.A4TupleSet)1 Test (org.junit.Test)1