コード例 #1
0
 /**
  * Add the new mapping to this expander.
  *
  * @param mapping
  */
 public void addDSLMapping(final DSLMapping mapping) {
   for (DSLMappingEntry entry : mapping.getEntries()) {
     if (DSLMappingEntry.KEYWORD.equals(entry.getSection())) {
       this.keywords.add(entry);
     } else if (DSLMappingEntry.CONDITION.equals(entry.getSection())) {
       this.condition.add(entry);
     } else if (DSLMappingEntry.CONSEQUENCE.equals(entry.getSection())) {
       this.consequence.add(entry);
     } else {
       // if any, then add to them both condition and consequence
       this.condition.add(entry);
       this.consequence.add(entry);
     }
   }
   if (mapping.getOption("result")) showResult = true;
   if (mapping.getOption("steps")) showSteps = true;
   if (mapping.getOption("keyword")) showThen = true;
   if (mapping.getOption("when")) showWhen = true;
   if (mapping.getOption("then")) showThen = true;
 }
コード例 #2
0
  @Override
  public boolean parseAndLoad(Reader dsl) throws IOException {
    List<ParserError> errors = new ArrayList<ParserError>();
    String text = readFile(dsl);
    dsl = new StringReader(text);

    try {
      DSLMapping mapping = buildFileMapping(errors, dsl);
      mapping.setOptions(optionSet);
      setMapping(mapping);
      List<ParserError> moderr = new ArrayList<ParserError>();
      for (ParserError err : errors) {
        int row = err.getRow();
        int col = err.getCol();
        if (row > 0) {
          int len;
          while ((len = lineLengths.get(row)) < col) {
            col -= len + 1;
            row++;
          }
        }
        moderr.add(new ParserError(err.getMessage(), row, col));
      }
      errors = moderr;
    } catch (Exception e) {
      final String msg = "Error parsing DSL mapping: " + e.getMessage();
      ParserError parserError = new ParserError(msg, -1, 0);
      errors.add(parserError);
    }
    setErrors(errors);

    //        for( ParserError err: errors ){
    //            logger.error( "[" + err.getRow() + "," + err.getCol() + "]: " + err.getMessage()
    // );
    //        }

    return errors.isEmpty();
  }