Search in sources :

Example 1 with FTerminal

use of suite.node.parser.FactorizeResult.FTerminal in project suite by stupidsing.

the class RecursiveFactorizerTest method transform.

private FNode transform(FNode fn0) {
    FTerminal from = new FTerminal(To.chars("ic-compile-better-option"));
    FTerminal to = new FTerminal(To.chars("ic-new-compile-better-option"));
    Iterate<FNode> fun = fn_ -> fn_.equals(from) ? to : null;
    return transform(fn0, fun);
}
Also used : FNode(suite.node.parser.FactorizeResult.FNode) Read(suite.streamlet.Read) Singleton(suite.node.util.Singleton) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) FTree(suite.node.parser.FactorizeResult.FTree) FileUtil(suite.os.FileUtil) Nodify(suite.util.Nodify) Dict(suite.node.Dict) FPair(suite.node.parser.FactorizeResult.FPair) Reference(suite.node.Reference) Source(suite.util.FunUtil.Source) Assert.assertTrue(org.junit.Assert.assertTrue) TermOp(suite.node.io.TermOp) FTerminal(suite.node.parser.FactorizeResult.FTerminal) Test(org.junit.Test) To(suite.util.To) Tree(suite.node.Tree) Iterate(suite.util.FunUtil.Iterate) List(java.util.List) Rewrite(suite.node.util.Rewrite) Assert.assertFalse(org.junit.Assert.assertFalse) Atom(suite.node.Atom) Operator(suite.node.io.Operator) Assert.assertEquals(org.junit.Assert.assertEquals) Str(suite.node.Str) FNode(suite.node.parser.FactorizeResult.FNode) FTerminal(suite.node.parser.FactorizeResult.FTerminal)

Example 2 with FTerminal

use of suite.node.parser.FactorizeResult.FTerminal in project suite by stupidsing.

the class Ebnf method toFactorizeResult.

private FactorizeResult toFactorizeResult(char[] cs, int p0, int px, Ast ast) {
    var children = ast.children;
    var size = children.size();
    if (0 < size) {
        var frs = new ArrayList<FactorizeResult>();
        var pos = p0;
        for (var i = 0; i < size; i++) {
            var child = children.get(i);
            var pos0 = pos;
            pos = i != size - 1 ? child.end : px;
            frs.add(toFactorizeResult(cs, pos0, pos, child));
        }
        return FactorizeResult.merge(ast.entity, frs);
    } else {
        var pre = Chars.of(cs, p0, ast.start);
        var mid = Chars.of(cs, ast.start, ast.end);
        var post = Chars.of(cs, ast.end, px);
        return new FactorizeResult(pre, new FTerminal(mid), post);
    }
}
Also used : ArrayList(java.util.ArrayList) FTerminal(suite.node.parser.FactorizeResult.FTerminal) FactorizeResult(suite.node.parser.FactorizeResult)

Example 3 with FTerminal

use of suite.node.parser.FactorizeResult.FTerminal in project suite by stupidsing.

the class RecursiveFactorizer method term.

private FactorizeResult term(Chars chars) {
    var chars1 = chars.trim();
    var p0 = reverser.reverse(chars.start);
    var p1 = reverser.reverse(chars1.start);
    var p2 = reverser.reverse(chars1.end);
    var px = reverser.reverse(chars.end);
    return new FactorizeResult(Chars.of(in.cs, p0, p1), new FTerminal(Chars.of(in.cs, p1, p2)), Chars.of(in.cs, p2, px));
}
Also used : FTerminal(suite.node.parser.FactorizeResult.FTerminal)

Aggregations

FTerminal (suite.node.parser.FactorizeResult.FTerminal)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 Atom (suite.node.Atom)1 Dict (suite.node.Dict)1 Node (suite.node.Node)1 Reference (suite.node.Reference)1 Str (suite.node.Str)1 Tree (suite.node.Tree)1 Operator (suite.node.io.Operator)1 TermOp (suite.node.io.TermOp)1 FactorizeResult (suite.node.parser.FactorizeResult)1 FNode (suite.node.parser.FactorizeResult.FNode)1 FPair (suite.node.parser.FactorizeResult.FPair)1 FTree (suite.node.parser.FactorizeResult.FTree)1 Rewrite (suite.node.util.Rewrite)1