Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

91
LINES

< > BotCompany Repo | #1000650 // Find insert statements in MySQL dump

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (3659L/25K/86K).

1  
!7
2  
3  
sinterface StringFunc {
4  
  S get(S s);
5  
}
6  
7  
static O in;
8  
static L<S> markedStrings;
9  
10  
p {
11  
  if (in == null) // may have been set by hotwire client
12  
    in = "create table `bla`(hello int);";
13  
  
14  
  if (args.length != 0) in = loadSnippet(args[0]);
15  
  
16  
  S s = [[
17  
    mysqltok input
18  
    find "insert" ... ";"
19  
  ]];
20  
  L<S> ll = toLinesFullTrim(s);
21  
  //System.out.println(ll);
22  
  
23  
  // remove comments
24  
  ll = map(ll, func(S s) -> S { s.replaceAll("//.*$", "").trim() });
25  
  
26  
  L<S> tok = null;
27  
  
28  
  for (S c : ll) {
29  
    if (eq(c, "mysqltok input"))
30  
      in = tok = mysqlTok((String) in);
31  
    else if (c.startsWith("find")) {
32  
      L<S> pat = javaTok(c);
33  
      pat.remove(0); pat.remove(0);
34  
      L<S> inp = cast in;
35  
      //System.out.println("inp: " + inp);
36  
      //System.out.println("pat: " + pat);
37  
      in = matchTokensList(inp, pat);
38  
      //System.out.println("Result: " + structure(in));
39  
    }
40  
  }
41  
  
42  
  if (in instanceof List) {
43  
    List<int[]> list = cast in;
44  
    markedStrings = getMarkedStrings(tok, list);
45  
    markTokens(tok, list);
46  
    in = join(tok);
47  
  
48  
    System.out.println("Markings found: " + size(list));
49  
    for (int[] ij : list) {
50  
      S bla = join(tok.subList(ij[0], ij[1]+1));
51  
      System.out.println("Got: " + bla);
52  
    }
53  
  }
54  
}
55  
56  
static List<String> getMarkedStrings(L<S> tok, L<int[]> markings) {
57  
  new L<S> result;
58  
  for (int i = 0; i < markings.size(); i++)
59  
    result.add(join(tok.subList(markings.get(i)[0], markings.get(i)[1])));
60  
  return result;
61  
}
62  
63  
static int size(Object o) {
64  
  return ((List) o).size();
65  
}
66  
67  
static void markTokens(L<S> tok, L<int[]> marks) {
68  
  System.out.println(tok.size());
69  
  for (int i = 0; i < tok.size(); i++) {
70  
    String t = tok.get(i);
71  
    if (isStartMark(i, marks))
72  
      t = "[[" + t;
73  
    if (isEndMark(i, marks))
74  
      t += "]]";
75  
    tok.set(i, t);
76  
  }
77  
}
78  
79  
static boolean isStartMark(int i, L<int[]> marks) {
80  
  for (int[] ij : marks)
81  
    if (ij[0] == i)
82  
      return true;
83  
  return false;
84  
}
85  
86  
static boolean isEndMark(int i, L<int[]> marks) {
87  
  for (int[] ij : marks)
88  
    if (ij[1] == i+1)
89  
      return true;
90  
  return false;
91  
}

Author comment

Began life as a copy of #1000642

download  show line numbers  debug dex  old transpilations   

Relations

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000650
Snippet name: Find insert statements in MySQL dump
Eternal ID of this version: #1000650/3
Text MD5: 574b4c0f573d4e849f23195702352cc2
Transpilation MD5: 17388beafe7eafadadfe59e77a4ea9a4
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-23 00:31:12
Source code size: 2166 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 744 / 1213
Version history: 2 change(s)
Referenced in: [show references]