Package xtc.tree

Examples of xtc.tree.Location


   * @return The corresponding location.
   */
  public final Location location(final int index) {
    final Column c = column(index);

    return new Location(c.file, c.line, c.column, index, yyCount - 1);
  }
View Full Code Here


   * @param index The index.
   */
  public final void setLocation(final Locatable locatable, final int index) {
    if ((null != locatable) && (! locatable.hasLocation())) {
      Column c = column(index);
      locatable.setLocation(new Location(c.file, c.line, c.column, index, yyCount - 1));
    }
  }
View Full Code Here

   * @return The result of applying the actions.
   */
  protected final <T extends Locatable> T apply(Pair<Action<T>> actions,
                                                T seed, final int index) {
    if (! actions.isEmpty()) {
      final Location loc = location(index);

      do {
        seed    = actions.head().run(seed);
        seed.setLocation(loc);
        actions = actions.tail();
View Full Code Here

      String plainText = textMapping.getPlainText();
      replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
    }

    final List<RuleMatchApplication> ruleMatchApplications = new ArrayList<RuleMatchApplication>();
    final Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1)// not zero-based!
    final Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);

    /*System.out.println("=========");
    System.out.println(textMapping.getMapping());
    System.out.println("=========");
    System.out.println(textMapping.getPlainText());
View Full Code Here

  public WrappedT toWrapped() {
    return this;
  }

  public boolean hasLocation(boolean forward) {
    Location loc = super.getLocation(false);
    return null != loc ? true : forward ? type.hasLocation(true) : false;
  }
View Full Code Here

    Location loc = super.getLocation(false);
    return null != loc ? true : forward ? type.hasLocation(true) : false;
  }

  public Location getLocation(boolean forward) {
    Location loc = super.getLocation(false);
    return null != loc ? loc : forward ? type.getLocation(true) : null;
  }
View Full Code Here

   * @param el The element to wrap.
   * @return The wrapped element.
   */
  protected Element wrap(Element el) {
    Element  result  = new VoidedElement(el);
    Location loc     = el.getLocation();
    result.setLocation(loc);

    if (runtime.test("optionVerbose")) {
      System.err.println("[Voiding expression at " + loc.line + ":" +
                         loc.column + " in " + analyzer.current().qName + "]");
View Full Code Here

      String plainText = textMapping.getPlainText();
      replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
    }

    final List<RuleMatchApplication> ruleMatchApplications = new ArrayList<>();
    final Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1)// not zero-based!
    final Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);

    /*System.out.println("=========");
    System.out.println(textMapping.getMapping());
    System.out.println("=========");
    System.out.println(textMapping.getPlainText());
View Full Code Here

   */
  public Location getOriginalTextPositionFor(int plainTextPosition) {
    if (plainTextPosition < 1) {
      throw new RuntimeException("plainTextPosition must be > 0 - its value starts at 1");
    }
    final Location origPosition = mapping.get(plainTextPosition);
    if (origPosition != null) {
      //System.out.println("mapping " + plainTextPosition + " to " + origPosition + " [direct]");
      return origPosition;
    }
    int minDiff = Integer.MAX_VALUE;
    Location bestMatch = null;
    //Integer bestMaybeClosePosition = null;
    // algorithm: find the closest lower position
    for (Map.Entry<Integer, Location> entry : mapping.entrySet()) {
      int maybeClosePosition = entry.getKey();
      if (plainTextPosition > maybeClosePosition) {
        int diff = plainTextPosition - maybeClosePosition;
        if (diff >= 0 && diff < minDiff) {
          bestMatch = entry.getValue();
          //bestMaybeClosePosition = maybeClosePosition;
          minDiff = diff;
        }
      }
    }
    if (bestMatch == null) {
      throw new RuntimeException("Could not map " + plainTextPosition + " to original position. Mapping: " + mapping);
    }
    // we assume that when we have found the closest match there's a one-to-one mapping
    // in this region, thus we can add 'minDiff' to get the exact position:
    //System.out.println("mapping " + plainTextPosition + " to line " + bestMatch.line + ", column " +
    //        bestMatch.column + "+" +  minDiff + ", bestMatch was: " + bestMaybeClosePosition +"=>"+ bestMatch);
    return new Location(bestMatch.file, bestMatch.line, bestMatch.column + minDiff);
  }
View Full Code Here

  }

  private List<WikipediaRuleMatch> toWikipediaRuleMatches(String content, PlainTextMapping filteredContent, List<RuleMatch> ruleMatches, AtomFeedItem item) {
    List<WikipediaRuleMatch> result = new ArrayList<>();
    for (RuleMatch ruleMatch : ruleMatches) {
      Location fromPos = filteredContent.getOriginalTextPositionFor(ruleMatch.getFromPos() + 1);
      Location toPos = filteredContent.getOriginalTextPositionFor(ruleMatch.getToPos() + 1);
      int origFrom = LocationHelper.absolutePositionFor(fromPos, content);
      int origTo = LocationHelper.absolutePositionFor(toPos, content);
      String errorContext = contextTools.getContext(origFrom, origTo, content);
      result.add(new WikipediaRuleMatch(language, ruleMatch, errorContext, item));
    }
View Full Code Here

TOP

Related Classes of xtc.tree.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.