private void checkInvocations(CommonTree node) {
    if (exceptionClass != ""
        && node.getType() == 4
        && !forward
        && node.getText() != exceptionClass) {
      exceptionVariable = node.getText();
    }

    if (exceptionVariable != "" && node.getType() == FORWARDCURLYBRACKET) {
      this.forward = true;
    }

    if ((forward) && (node.getType() == IDENTIFIER) && (node.getText()).equals(exceptionVariable)) {
      foundExceptionVariable = true;
    }

    if (foundExceptionVariable && node.getType() == DOT) {
      foundDot = true;
    }

    if (foundExceptionVariable && foundDot && node.getType() == IDENTIFIER) {
      foundDot = false;
      foundExceptionVariable = false;
      CSharpData data = new CSharpData();
      data.setClassName(belongsToClass);
      data.setLineNumber(node.getLine());
      data.setInvocationTo(exceptionClass);
      data.setInvocationName(node.getText());
      allInvocations.add(data);
    }
  }
Exemplo n.º 2
0
  private void cond_gen(CommonTree tr, int[] label_num) {
    String cond = null;
    String code = null;
    String[] left_res_type = {null, null, null};
    String[] right_res_type = {null, null, null};
    label_num[0] = label_index++;

    //		System.out.println("TEST cond_gen 1: " + getCh(tr,0) + " "+getCh(tr,1));

    op_gen(getCh(tr, 0), left_res_type);
    op_gen(getCh(tr, 1), right_res_type);
    if (tr.getType() == MicroParser.GT) cond = "LE ";
    else if (tr.getType() == MicroParser.LT) cond = "GE ";
    else if (tr.getType() == MicroParser.EQ) cond = "NE ";
    else cond = tr.getToken().getText();
    code =
        cond
            + left_res_type[2]
            + " "
            + right_res_type[2]
            + " label"
            + Integer.toString(label_num[0]);
    link(code);
    //		System.out.println( "TEST cond gen 2: " + code );

  }
Exemplo n.º 3
0
  // Execute a CLI Statement
  public void executeCLIStmt(String stmt)
      throws TException, NotFoundException, InvalidRequestException, UnavailableException,
          TimedOutException, IllegalAccessException, ClassNotFoundException,
          InstantiationException {
    CommonTree ast = null;

    ast = CliCompiler.compileQuery(stmt);

    try {
      switch (ast.getType()) {
        case CliParser.NODE_EXIT:
          cleanupAndExit();
          break;
        case CliParser.NODE_THRIFT_GET:
          executeGet(ast);
          break;
        case CliParser.NODE_HELP:
          printCmdHelp();
          break;
        case CliParser.NODE_THRIFT_SET:
          executeSet(ast);
          break;
        case CliParser.NODE_THRIFT_DEL:
          executeDelete(ast);
          break;
        case CliParser.NODE_THRIFT_COUNT:
          executeCount(ast);
          break;
        case CliParser.NODE_SHOW_CLUSTER_NAME:
          executeShowProperty(ast, "cluster name");
          break;
        case CliParser.NODE_SHOW_CONFIG_FILE:
          executeShowProperty(ast, "config file");
          break;
        case CliParser.NODE_SHOW_VERSION:
          executeShowProperty(ast, "version");
          break;
        case CliParser.NODE_SHOW_TABLES:
          executeShowTables(ast);
          break;
        case CliParser.NODE_DESCRIBE_TABLE:
          executeDescribeTable(ast);
          break;
        case CliParser.NODE_CONNECT:
          executeConnect(ast);
          break;
        case CliParser.NODE_NO_OP:
          // comment lines come here; they are treated as no ops.
          break;
        default:
          css_.err.println("Invalid Statement (Type: " + ast.getType() + ")");
          break;
      }
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException("Unable to encode string as UTF-8", e);
    }
  }
Exemplo n.º 4
0
  @Test
  public void parseTest() throws Exception {

    // the same as regex()

    String[] tests = {
      "",
      "\\da",
      "(?<!s)[b]",
      "\\2(?=c)",
      "\\d",
      "e?foo",
      "xxyyf?+",
      "MUg??",
      "[aaaaaa]h*",
      "[^|]++i*+",
      "aaaj*?",
      "aaak+",
      "aaal++",
      "bbbm+?",
      "bbbn{42}",
      "CCCo{42,888}",
      "Dp{42,888}+",
      "Eq{42,888}?",
      "Fr{42,}",
      "Gs{42,}+",
      "HHHt{42,}?"
    };

    for (String test : tests) {

      PCREParser parser = getParser(test);
      PCREParser.regex_return value = parser.regex();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.ALTERNATIVE));
    }

    tests = new String[] {"|", "(?!a)|(?<=b)", "a|b|c|d"};

    for (String test : tests) {

      PCREParser parser = getParser(test);
      PCREParser.regex_return value = parser.regex();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.OR));
    }
  }
Exemplo n.º 5
0
  @Test
  public void backreference_or_octalTest() throws Exception {

    Object[][] tests = {
      {"\\41", "!"},
      {"\\041", "!"}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      String expected = (String) test[1];

      PCREParser parser = getParser(input);
      PCREParser.backreference_or_octal_return value = parser.backreference_or_octal();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.LITERAL));
      assertThat(tree.getText(), is(expected));
    }

    tests =
        new Object[][] {
          {"\\1", "1"},
          {"\\9", "9"}
        };

    for (Object[] test : tests) {

      String input = (String) test[0];
      String expected = (String) test[1];

      PCREParser parser = getParser(input);
      PCREParser.backreference_or_octal_return value = parser.backreference_or_octal();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.NUMBERED_BACKREFERENCE));

      assertThat(tree.getChildCount(), is(1));

      CommonTree numberNode = (CommonTree) tree.getChild(0);

      assertThat(numberNode.getType(), is(PCRELexer.NUMBER));
      assertThat(numberNode.getText(), is(expected));
    }
  }
Exemplo n.º 6
0
 private void setExceptionClass(CommonTree tree) {
   if (tree != null) {
     for (int index = 0; index < tree.getChildCount(); index++) {
       if (tree.getType() == typeIdentifierNode) {
         this.exceptionClass = this.parserUniquename((CommonTree) tree);
       } else if (tree.getType() == 156) {
         this.exceptionClass = this.parserUniquename((CommonTree) tree.getChild(0));
       } else {
         setExceptionClass((CommonTree) tree.getChild(index));
       }
     }
   }
 }
  private void checkMethodType(CommonTree methodTree) {
    if (methodTree.getType() == JavaParser.CONSTRUCTOR_DECL) {
      declaredReturnType = "";
      isConstructor = true;
      name = getClassOfUniqueName(belongsToClass);

    } else if (methodTree.getType() == JavaParser.VOID_METHOD_DECL) {
      declaredReturnType = "";
      isConstructor = false;
    } else if (methodTree.getType() == JavaParser.FUNCTION_METHOD_DECL) {
      isConstructor = false;
    } else {
      logger.warn("MethodGenerator aangeroepen maar geen herkenbaar type methode");
    }
  }
Exemplo n.º 8
0
 private String parserUniquename(CommonTree tree) {
   String path = "";
   if (tree.getType() == JavaParser.DOT) {
     path += packageClassPath(tree);
   } else if (tree.getType() == JavaParser.QUALIFIED_TYPE_IDENT) {
     int childcount = tree.getChildCount();
     for (int iterator = 0; iterator < childcount; iterator++) {
       path += !path.equals("") ? "." : "";
       path += tree.getChild(iterator).toString();
     }
   } else {
     path = tree.toString();
   }
   return path;
 }
Exemplo n.º 9
0
  private void executeCount(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    int childCount = ast.getChildCount();
    assert (childCount == 1);

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    ColumnParent colParent;

    if (columnSpecCnt == 0) {
      colParent = createColumnParent(columnFamily, null);
    } else {
      assert (columnSpecCnt == 1);
      colParent =
          createColumnParent(
              columnFamily, CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8"));
    }

    int count = thriftClient_.get_count(tableName, key, colParent, ConsistencyLevel.ONE);
    css_.out.printf("%d columns\n", count);
  }
Exemplo n.º 10
0
  @Test
  public void look_aroundTest() throws Exception {

    Object[][] tests = {
      {"(?=a)", PCRELexer.LOOK_AHEAD},
      {"(?!b)", PCRELexer.NEGATIVE_LOOK_AHEAD},
      {"(?<=c)", PCRELexer.LOOK_BEHIND},
      {"(?<!d)", PCRELexer.NEGATIVE_LOOK_BEHIND}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.look_around_return value = parser.look_around();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 11
0
  private int getElementOffset(CommonTree tree) {
    switch (tree.getType()) {
      case ANTLRParser.MODE:
      case ANTLRParser.ASSIGN:
      case ANTLRParser.RULE:
        if (tree.getChildCount() > 0 && tree.getChild(0) instanceof CommonTree) {
          CommonTree child = (CommonTree) tree.getChild(0);
          if (child.getToken() instanceof CommonToken) {
            CommonToken token = (CommonToken) child.getToken();
            return token.getStartIndex();
          }
        }

        break;

      case ANTLRParser.ID:
        break;

      default:
        throw new UnsupportedOperationException();
    }

    if (tree.getToken() instanceof CommonToken) {
      return ((CommonToken) tree.getToken()).getStartIndex();
    }

    return 0;
  }
Exemplo n.º 12
0
  @Test
  public void subroutine_referenceTest() throws Exception {

    Object[][] tests = {
      {"(?R)", PCRELexer.NUMBERED_REFERENCE_ABSOLUTE},
      {"(?123)", PCRELexer.NUMBERED_REFERENCE_ABSOLUTE},
      {"(?+123)", PCRELexer.NUMBERED_REFERENCE_RELATIVE_PLUS},
      {"(?-123)", PCRELexer.NUMBERED_REFERENCE_RELATIVE_MINUS},
      {"(?&name)", PCRELexer.NAMED_REFERENCE_PERL},
      {"(?P>name)", PCRELexer.NAMED_REFERENCE_PYTHON},
      {"\\g<name>", PCRELexer.NAMED_REFERENCE_ONIGURUMA},
      {"\\g'name'", PCRELexer.NAMED_REFERENCE_ONIGURUMA},
      {"\\g<123>", PCRELexer.NUMBERED_REFERENCE_ABSOLUTE_ONIGURUMA},
      {"\\g'123'", PCRELexer.NUMBERED_REFERENCE_ABSOLUTE_ONIGURUMA},
      {"\\g<+123>", PCRELexer.NUMBERED_REFERENCE_RELATIVE_PLUS},
      {"\\g'+123'", PCRELexer.NUMBERED_REFERENCE_RELATIVE_PLUS},
      {"\\g<-123>", PCRELexer.NUMBERED_REFERENCE_RELATIVE_MINUS},
      {"\\g'-123'", PCRELexer.NUMBERED_REFERENCE_RELATIVE_MINUS}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.subroutine_reference_return value = parser.subroutine_reference();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 13
0
  @Test
  public void backtrack_controlTest() throws Exception {

    Object[][] tests = {
      {"(*ACCEPT)", PCRELexer.BACKTACK_CONTROL_ACCEPT},
      {"(*FAIL)", PCRELexer.BACKTACK_CONTROL_FAIL},
      {"(*MARK:NAME)", PCRELexer.BACKTACK_CONTROL_MARK_NAME},
      {"(*COMMIT)", PCRELexer.BACKTACK_CONTROL_COMMIT},
      {"(*PRUNE)", PCRELexer.BACKTACK_CONTROL_PRUNE},
      {"(*PRUNE:NAME)", PCRELexer.BACKTACK_CONTROL_PRUNE_NAME},
      {"(*SKIP)", PCRELexer.BACKTACK_CONTROL_SKIP},
      {"(*SKIP:NAME)", PCRELexer.BACKTACK_CONTROL_SKIP_NAME},
      {"(*THEN)", PCRELexer.BACKTACK_CONTROL_THEN},
      {"(*THEN:NAME)", PCRELexer.BACKTACK_CONTROL_THEN_NAME}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.backtrack_control_return value = parser.backtrack_control();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 14
0
  @Test
  public void optionTest() throws Exception {

    Object[][] tests = {
      {"(*NO_START_OPT)", PCRELexer.OPTIONS_NO_START_OPT},
      {"(*UTF8)", PCRELexer.OPTIONS_UTF8},
      {"(*UTF16)", PCRELexer.OPTIONS_UTF16},
      {"(*UCP)", PCRELexer.OPTIONS_UCP},
      {"(?mis)", PCRELexer.OPTIONS},
      {"(?-Jx)", PCRELexer.OPTIONS},
      {"(?m-isx)", PCRELexer.OPTIONS}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.option_return value = parser.option();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 15
0
  @Test
  public void newline_conventionTest() throws Exception {

    Object[][] tests = {
      {"(*CR)", PCRELexer.NEWLINE_CONVENTION_CR},
      {"(*LF)", PCRELexer.NEWLINE_CONVENTION_LF},
      {"(*CRLF)", PCRELexer.NEWLINE_CONVENTION_CRLF},
      {"(*ANYCRLF)", PCRELexer.NEWLINE_CONVENTION_ANYCRLF},
      {"(*ANY)", PCRELexer.NEWLINE_CONVENTION_ANY},
      {"(*BSR_ANYCRLF)", PCRELexer.NEWLINE_CONVENTION_BSR_ANYCRLF},
      {"(*BSR_UNICODE)", PCRELexer.NEWLINE_CONVENTION_BSR_UNICODE}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.newline_convention_return value = parser.newline_convention();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 16
0
  @Test
  public void conditionalTest() throws Exception {

    Object[][] tests = {
      {"(?(123)a)", PCRELexer.REFERENCE_CONDITION_ABSOLUTE},
      {"(?(+123)a)", PCRELexer.REFERENCE_CONDITION_RELATIVE_PLUS},
      {"(?(-123)a)", PCRELexer.REFERENCE_CONDITION_RELATIVE_MINUS},
      {"(?(<name>)a)", PCRELexer.NAMED_REFERENCE_CONDITION_PERL},
      {"(?('name')a)", PCRELexer.NAMED_REFERENCE_CONDITION_PERL},
      {"(?(name)a)", PCRELexer.NAMED_REFERENCE_CONDITION},
      {"(?(R)a)", PCRELexer.OVERALL_RECURSION_CONDITION},
      {"(?(R123)a)", PCRELexer.SPECIFIC_GROUP_RECURSION_CONDITION},
      {"(?(R&name)a)", PCRELexer.SPECIFIC_RECURSION_CONDITION},
      {"(?(DEFINE)a)", PCRELexer.DEFINE},
      {"(?(assert)a)", PCRELexer.ASSERT},
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.conditional_return value = parser.conditional();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(expected));
    }
  }
Exemplo n.º 17
0
  @Test
  public void cc_atomTest() throws Exception {

    String[] ranges = {"0-9", "\\]-$", "---", "[-["};

    for (String range : ranges) {

      PCREParser parser = getParser(range);
      PCREParser.cc_atom_return value = parser.cc_atom();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getChildCount(), is(2));
      assertThat(tree.getType(), is(PCRELexer.RANGE));
    }

    String[] tests = ("a b c [[:digit:]] \\d * $ ?").split("\\s+");

    for (String test : tests) {

      PCREParser parser = getParser(test);
      PCREParser.cc_atom_return value = parser.cc_atom();

      assertThat(value, notNullValue());
    }
  }
Exemplo n.º 18
0
  @Test
  public void character_classTest() throws Exception {

    String[] tests = {"[^\\da-z]", "[^^]", "[^]^]", "[^\\]^]"};

    for (String test : tests) {

      PCREParser parser = getParser(test);
      PCREParser.character_class_return value = parser.character_class();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.NEGATED_CHARACTER_CLASS));
    }

    tests = new String[] {"[\\da-z]", "[\\^]", "[]^]", "[\\]^]"};

    for (String test : tests) {

      PCREParser parser = getParser(test);
      PCREParser.character_class_return value = parser.character_class();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getType(), is(PCRELexer.CHARACTER_CLASS));
    }

    PCREParser parser = getParser("[]-\\]]"); // valid range!
    PCREParser.character_class_return value = parser.character_class();

    assertThat(value, notNullValue());

    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getChildCount(), is(1));
    assertThat(tree.getType(), is(PCRELexer.CHARACTER_CLASS));

    CommonTree rangeNode = (CommonTree) tree.getChild(0);
    assertThat(rangeNode.getChildCount(), is(2));
    assertThat(rangeNode.getType(), is(PCRELexer.RANGE));
  }
Exemplo n.º 19
0
  @Test
  public void captureTest() throws Exception {

    // named captures

    final String name = "Just_A_Name";

    Object[][] tests = {
      {String.format("(?<%s>regex)", name), PCRELexer.NAMED_CAPTURING_GROUP_PERL},
      {String.format("(?'%s'regex)", name), PCRELexer.NAMED_CAPTURING_GROUP_PERL},
      {String.format("(?P<%s>regex)", name), PCRELexer.NAMED_CAPTURING_GROUP_PYTHON}
    };

    for (Object[] test : tests) {

      String input = (String) test[0];
      Integer expected = (Integer) test[1];

      PCREParser parser = getParser(input);
      PCREParser.capture_return value = parser.capture();

      assertThat(value, notNullValue());

      CommonTree tree = (CommonTree) value.getTree();

      assertThat(tree.getChildCount(), is(2));
      assertThat(tree.getType(), is(expected));

      CommonTree nameChild = (CommonTree) tree.getChild(0);

      assertThat(nameChild.getText(), is(name));
    }

    // numbered captures

    PCREParser parser = getParser("(regex)");
    PCREParser.capture_return value = parser.capture();

    assertThat(value, notNullValue());

    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getType(), is(PCRELexer.CAPTURING_GROUP));
  }
Exemplo n.º 20
0
  private void executeDelete(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    int childCount = ast.getChildCount();
    assert (childCount == 1);

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    byte[] superColumnName = null;
    byte[] columnName = null;
    boolean isSuper;

    try {
      if (!(getCFMetaData(tableName).containsKey(columnFamily))) {
        css_.out.println("No such column family: " + columnFamily);
        return;
      }

      isSuper =
          getCFMetaData(tableName).get(columnFamily).get("Type").equals("Super") ? true : false;
    } catch (NotFoundException nfe) {
      css_.out.printf("No such keyspace: %s\n", tableName);
      return;
    }

    if ((columnSpecCnt < 0) || (columnSpecCnt > 2)) {
      css_.out.println("Invalid row, super column, or column specification.");
      return;
    }

    if (columnSpecCnt == 1) {
      // table.cf['key']['column']
      if (isSuper) superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      else columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
    } else if (columnSpecCnt == 2) {
      // table.cf['key']['column']['column']
      superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
    }

    thriftClient_.remove(
        tableName,
        key,
        createColumnPath(columnFamily, superColumnName, columnName),
        timestampMicros(),
        ConsistencyLevel.ONE);
    css_.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column"));
  }
Exemplo n.º 21
0
 private String getPrimaryKeyFieldName(CommonTree whereNode) {
   String result = null;
   CommonTree operation = (CommonTree) whereNode.getChild(0);
   if (MySQL51Parser.EQUALS == operation.getType()) {
     result = operation.getChild(0).getChild(0).getText();
   } else {
     throw new ClusterJUserException("Cannot find primary key in WHERE clause.");
   }
   return result;
 }
  private String checkForExceptionClass(CommonTree node) {
    if (exceptionClass == null) {
      exceptionClass = "";
    }

    if (node.getType() == IDENTIFIER && exceptionClass.isEmpty()) {
      exceptionClass = node.getText();
    }
    return exceptionClass;
  }
Exemplo n.º 23
0
  @Test
  public void numberTest() throws Exception {

    String source = "4567";
    PCREParser parser = getParser(source + " ... ");

    PCREParser.number_return value = parser.number();
    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getChildCount(), is(0));
    assertThat(tree.getType(), is(PCRELexer.NUMBER));
    assertThat(tree.getText(), is(source));
  }
Exemplo n.º 24
0
  @Test
  public void literalTest() throws Exception {

    PCREParser parser = getParser("]");
    PCREParser.literal_return value = parser.literal();

    assertThat(value, notNullValue());

    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getChildCount(), is(0));
    assertThat(tree.getType(), is(PCRELexer.LITERAL));
  }
Exemplo n.º 25
0
  @Test
  public void nameTest() throws Exception {

    String source = "justAname";
    PCREParser parser = getParser(source + " ... ");

    PCREParser.name_return value = parser.name();
    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getChildCount(), is(0));
    assertThat(tree.getType(), is(PCRELexer.NAME));
    assertThat(tree.getText(), is(source));
  }
Exemplo n.º 26
0
  @Test
  public void commentTest() throws Exception {

    String comment = "just a [a-z]+ comment";
    PCREParser parser = getParser(String.format("(?#%s)regex", comment));
    PCREParser.comment_return value = parser.comment();

    assertThat(value, notNullValue());

    CommonTree tree = (CommonTree) value.getTree();

    assertThat(tree.getType(), is(PCRELexer.COMMENT));
    assertThat(tree.getText(), is(comment));
  }
Exemplo n.º 27
0
  // Execute SET statement
  private void executeSet(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    assert (ast.getChildCount() == 2) : "serious parsing error (this is a bug).";

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
    String value = CliUtils.unescapeSQLString(ast.getChild(1).getText());

    byte[] superColumnName = null;
    byte[] columnName = null;

    // table.cf['key']
    if (columnSpecCnt == 0) {
      css_.err.println("No column name specified, (type 'help' or '?' for help on syntax).");
      return;
    }
    // table.cf['key']['column'] = 'value'
    else if (columnSpecCnt == 1) {
      // get the column name
      columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
    }
    // table.cf['key']['super_column']['column'] = 'value'
    else {
      assert (columnSpecCnt == 2) : "serious parsing error (this is a bug).";

      // get the super column and column names
      superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
    }

    // do the insert
    thriftClient_.insert(
        tableName,
        key,
        createColumnPath(columnFamily, superColumnName, columnName),
        value.getBytes(),
        timestampMicros(),
        ConsistencyLevel.ONE);

    css_.out.println("Value inserted.");
  }
Exemplo n.º 28
0
  public static Object parseValue(CommonTree val) {
    switch (val.getType()) {
      case UIQueryParser.STRING:
        {
          String textWithPings = val.getText();
          String text = textWithPings.substring(1, textWithPings.length() - 1);
          text = text.replaceAll("\\\\'", "'");
          return text;
        }
      case UIQueryParser.INT:
        return Integer.parseInt(val.getText(), 10);
      case UIQueryParser.BOOL:
        {
          String text = val.getText();
          return Boolean.parseBoolean(text);
        }
      case UIQueryParser.NIL:
        return null;

      default:
        throw new IllegalArgumentException(
            "Unable to parse value type:" + val.getType() + " text " + val.getText());
    }
  }
 public static Expression getExpression(CommonTree Child, Model MyModel) {
   Expression returnMe = null;
   int Type = Child.getType();
   if (Type == Constants.NOT
       || Type == Constants.CAST_EXPRESSION
       || Type == Constants.MINUS
       || Type == Constants.PLUS
       || Type == Constants.POWER_EXPRESSION
       || Type == Constants.TIMES
       || Type == Constants.MOD
       || Type == Constants.DIV
       || Type == Constants.AND
       || Type == Constants.OR
       || Type == Constants.NOT_EQUALS
       || Type == Constants.GTE
       || Type == Constants.LT
       || Type == Constants.GT
       || Type == Constants.EQUALS
       || Type == Constants.LTE
       || Type == Constants.INCREMENT
       || Type == Constants.DECREMENT) {
     if (Type != Constants.CAST_EXPRESSION)
       returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
     else { // We must be attempting to cast move one step farther into tree.
       if (Child.getChildCount() > 0) {
         Type = ((CommonTree) Child.getChild(0)).getType();
         returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
       }
     }
   } else if (Type == Constants.DOUBLE) {
     returnMe = new TypeFloat(new Float(Child.toString()));
   } else if (Type == Constants.STRING_LITERAL) {
     returnMe = new TypeString(Child.toString().substring(1, Child.toString().length() - 1));
   } else if (Type == Constants.INTEGER_LITERAL) {
     returnMe = new TypeInteger(new Integer(Child.toString()));
   } else if (Type == Constants.BOOLEAN_LITERAL) {
     returnMe = new TypeBoolean(new Boolean(Child.toString()));
   } else if (Type == Constants.IDENTIFIER) {
     returnMe = new TypeIdentifier(Child.toString());
   } else if (Type == Constants.ARRAY_IDENTIFIER) {
     returnMe = new TypeIdentifier(Child, MyModel);
   } else if (Type == Constants.ARRAY_DECLARE) {
     returnMe = new ArrayDeclareExpression(Child, MyModel);
   } else if (Type == Constants.PROCEDURE) {
     returnMe = new ProcedureExpression(Child, MyModel);
   }
   return (returnMe);
 }
 public boolean usingCheck(CommonTree tree, boolean usage) {
   int type = tree.getType();
   if (type == USING) {
     usage = startUsing();
   }
   if (usage && type != USING) {
     aUsingPart(tree);
   }
   if (usage && type == SEMICOLON && !tempUsingName.equals("")) {
     setIndentLevel();
   }
   if (usage && type == SEMICOLON) {
     usage = false;
   }
   return usage;
 }