Search in sources :

Example 1 with FactorizeResult

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

the class EbnfTest method rewrite.

private FactorizeResult rewrite(Ebnf ebnf, String entity, String from, String to, FactorizeResult fr0) {
    FactorizeResult frfrom = ebnf.parseFNode(from, entity);
    FactorizeResult frto = ebnf.parseFNode(to, entity);
    return FactorizeResult.rewrite(frfrom, frto, fr0);
}
Also used : FactorizeResult(suite.node.parser.FactorizeResult)

Example 2 with FactorizeResult

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

the class EbnfTest method testRefactor.

@Test
public void testRefactor() throws IOException {
    String sql0 = "SELECT 0 FROM DUAL WHERE COL1 = 1 AND COL2 IN (SELECT 1 FROM DUAL) ORDER BY COL DESC";
    Ebnf ebnf = new Ebnf(new FileReader("src/main/ebnf/sql.ebnf"));
    FactorizeResult fr = rewrite(// 
    ebnf, // 
    "intersect-select", // 
    "SELECT .0 FROM DUAL", // 
    "SELECT .0 FROM DUAL WHERE COL2 = 1", ebnf.parseFNode(sql0, "sql"));
    String sql1 = fr.unparse();
    assertEquals(sql1, "SELECT 0 FROM DUAL WHERE COL1 = 1 AND COL2 IN (SELECT 1 FROM DUAL WHERE COL2 = 1) ORDER BY COL DESC");
}
Also used : FileReader(java.io.FileReader) FactorizeResult(suite.node.parser.FactorizeResult) Test(org.junit.Test)

Example 3 with FactorizeResult

use of suite.node.parser.FactorizeResult 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)

Aggregations

FactorizeResult (suite.node.parser.FactorizeResult)3 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FTerminal (suite.node.parser.FactorizeResult.FTerminal)1