<commit_before>// @flow

import * as dom from './dom';
import TextContent from './textcontent';
import TextNodeVisitor from './textnodevisitor';
import TextNodeXpath from './textnodexpath';
import type { Marker } from './textcontent';

export type RangeDescriptor = {| marker: Marker, offset: number |};

export type RangeXpathDescriptor = {|
  start: { xpath: string, offset: number },
  end: { xpath: string, offset: number },
|};

/**
 * Holds a representation of a range between two text nodes
 *
 * @param {TextContent} content - text representation instance
 * @param {Object} start - descriptor of start of range
 * @param {Object} end - descriptor of end of range
 */
class Range {
  content: TextContent;
  start: RangeDescriptor;
  end: RangeDescriptor;

  /**
   * Create a range descriptor from a global offset.
   *
   * @param {Marker} marker - Text offset marker object
   * @param {number} offset - Global offset
   *
   * @returns {RangeDescriptor} Range descriptor */
  static descriptorAbs(marker: Marker, offset: number): RangeDescriptor {
    return {
      marker: marker,
      offset: offset - marker.offset,
    };
  }

  /**
   * Create a range descriptor from an offset relative to the start of the text node
   *
   * @param {Marker} marker - Text offset marker object
   * @param {number} offset - Relative offset from start of text node
   *
   * @returns {RangeDescriptor} Range descriptor
   */
  static descriptorRel(marker, offset): RangeDescriptor {
    return {
      marker: marker,
      offset,
    };
  }

  constructor(content: TextContent, start: RangeDescriptor, end: RangeDescriptor) {
    this.content = content;

    // Sanity check:
    if (start.marker.offset + start.offset > end.marker.offset + end.offset) {
      throw new Error('Invalid range: start > end');
    }

    this.start = start;
    this.end = end;<commit_msg>src: add missing type annotations<commit_after>// @flow

import * as dom from './dom';
import TextContent from './textcontent';
import TextNodeVisitor from './textnodevisitor';
import TextNodeXpath from './textnodexpath';
import type { Marker } from './textcontent';

export type RangeDescriptor = {| marker: Marker, offset: number |};

export type RangeXpathDescriptor = {|
  start: { xpath: string, offset: number },
  end: { xpath: string, offset: number },
|};

/**
 * Holds a representation of a range between two text nodes
 *
 * @param {TextContent} content - text representation instance
 * @param {Object} start - descriptor of start of range
 * @param {Object} end - descriptor of end of range
 */
class Range {
  content: TextContent;
  start: RangeDescriptor;
  end: RangeDescriptor;

  /**
   * Create a range descriptor from a global offset.
   *
   * @param {Marker} marker - Text offset marker object
   * @param {number} offset - Global offset
   *
   * @returns {RangeDescriptor} Range descriptor */
  static descriptorAbs(marker: Marker, offset: number): RangeDescriptor {
    return { marker, offset: offset - marker.offset };
  }

  /**
   * Create a range descriptor from an offset relative to the start of the text node
   *
   * @param {Marker} marker - Text offset marker object
   * @param {number} offset - Relative offset from start of text node
   *
   * @returns {RangeDescriptor} Range descriptor
   */
  static descriptorRel(marker: Marker, offset: number): RangeDescriptor {
    return { marker, offset };
  }

  constructor(content: TextContent, start: RangeDescriptor, end: RangeDescriptor) {
    this.content = content;

    // Sanity check:
    if (start.marker.offset + start.offset > end.marker.offset + end.offset) {
      throw new Error('Invalid range: start > end');
    }

    this.start = start;
    this.end = end;
{'fraction_non_alphanumeric': 0.11006963042313872, 'fraction_numerical': 0.0, 'mean_word_length': 3.388954171562867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7338636', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1019, 'n_words': 381}