// src/registry.ts
var tokenizers = /* @__PURE__ */ new Map();
var profiles = /* @__PURE__ */ new Map();
var patternCache = /* @__PURE__ */ new Map();
function registerLanguage(code, tokenizer, profile) {
  tokenizers.set(code, tokenizer);
  profiles.set(code, profile);
  patternCache.delete(code);
}

// src/tokenizers/base.ts
var TokenStreamImpl = class {
  constructor(tokens, language) {
    this.pos = 0;
    this.tokens = tokens;
    this.language = language;
  }
  peek(offset = 0) {
    const index = this.pos + offset;
    if (index < 0 || index >= this.tokens.length) {
      return null;
    }
    return this.tokens[index];
  }
  advance() {
    if (this.isAtEnd()) {
      throw new Error("Unexpected end of token stream");
    }
    return this.tokens[this.pos++];
  }
  isAtEnd() {
    return this.pos >= this.tokens.length;
  }
  mark() {
    return { position: this.pos };
  }
  reset(mark) {
    this.pos = mark.position;
  }
  position() {
    return this.pos;
  }
  /**
   * Get remaining tokens as an array.
   */
  remaining() {
    return this.tokens.slice(this.pos);
  }
  /**
   * Consume tokens while predicate is true.
   */
  takeWhile(predicate) {
    const result = [];
    while (!this.isAtEnd() && predicate(this.peek())) {
      result.push(this.advance());
    }
    return result;
  }
  /**
   * Skip tokens while predicate is true.
   */
  skipWhile(predicate) {
    while (!this.isAtEnd() && predicate(this.peek())) {
      this.advance();
    }
  }
};
function createPosition(start, end) {
  return { start, end };
}
function createToken(value, kind, position, normalizedOrOptions) {
  if (typeof normalizedOrOptions === "string") {
    return { value, kind, position, normalized: normalizedOrOptions };
  }
  if (normalizedOrOptions) {
    const { normalized: normalized2, stem, stemConfidence } = normalizedOrOptions;
    const token = { value, kind, position };
    if (normalized2 !== void 0) {
      token.normalized = normalized2;
    }
    if (stem !== void 0) {
      token.stem = stem;
      if (stemConfidence !== void 0) {
        token.stemConfidence = stemConfidence;
      }
    }
    return token;
  }
  return { value, kind, position };
}
function isWhitespace(char) {
  return /\s/.test(char);
}
function isSelectorStart(char) {
  return char === "#" || char === "." || char === "[" || char === "@" || char === "*" || char === "<";
}
function isQuote(char) {
  return char === '"' || char === "'" || char === "`" || char === "\u300C" || char === "\u300D";
}
function isDigit(char) {
  return /\d/.test(char);
}
function isAsciiLetter(char) {
  return /[a-zA-Z]/.test(char);
}
function isAsciiIdentifierChar(char) {
  return /[a-zA-Z0-9_-]/.test(char);
}
function createLatinCharClassifiers(letterPattern) {
  const isLetter = (char) => letterPattern.test(char);
  const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
  return { isLetter, isIdentifierChar };
}
function extractCssSelector(input, startPos) {
  if (startPos >= input.length) return null;
  const char = input[startPos];
  if (!isSelectorStart(char)) return null;
  let pos = startPos;
  let selector = "";
  if (char === "#" || char === ".") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
    if (pos < input.length && input[pos] === "." && char === "#") {
      const methodStart = pos + 1;
      let methodEnd = methodStart;
      while (methodEnd < input.length && isAsciiIdentifierChar(input[methodEnd])) {
        methodEnd++;
      }
      if (methodEnd < input.length && input[methodEnd] === "(") {
        return selector;
      }
    }
  } else if (char === "[") {
    let depth = 1;
    let inQuote = false;
    let quoteChar = null;
    let escaped = false;
    selector += input[pos++];
    while (pos < input.length && depth > 0) {
      const c = input[pos];
      selector += c;
      if (escaped) {
        escaped = false;
      } else if (c === "\\") {
        escaped = true;
      } else if (inQuote) {
        if (c === quoteChar) {
          inQuote = false;
          quoteChar = null;
        }
      } else {
        if (c === '"' || c === "'" || c === "`") {
          inQuote = true;
          quoteChar = c;
        } else if (c === "[") {
          depth++;
        } else if (c === "]") {
          depth--;
        }
      }
      pos++;
    }
    if (depth !== 0) return null;
  } else if (char === "@") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
  } else if (char === "*") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
  } else if (char === "<") {
    selector += input[pos++];
    if (pos >= input.length || !isAsciiLetter(input[pos])) return null;
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    while (pos < input.length) {
      const modChar = input[pos];
      if (modChar === ".") {
        selector += input[pos++];
        if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
          return null;
        }
        while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
          selector += input[pos++];
        }
      } else if (modChar === "#") {
        selector += input[pos++];
        if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
          return null;
        }
        while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
          selector += input[pos++];
        }
      } else if (modChar === "[") {
        let depth = 1;
        let inQuote = false;
        let quoteChar = null;
        let escaped = false;
        selector += input[pos++];
        while (pos < input.length && depth > 0) {
          const c = input[pos];
          selector += c;
          if (escaped) {
            escaped = false;
          } else if (c === "\\") {
            escaped = true;
          } else if (inQuote) {
            if (c === quoteChar) {
              inQuote = false;
              quoteChar = null;
            }
          } else {
            if (c === '"' || c === "'" || c === "`") {
              inQuote = true;
              quoteChar = c;
            } else if (c === "[") {
              depth++;
            } else if (c === "]") {
              depth--;
            }
          }
          pos++;
        }
        if (depth !== 0) return null;
      } else {
        break;
      }
    }
    while (pos < input.length && isWhitespace(input[pos])) {
      selector += input[pos++];
    }
    if (pos < input.length && input[pos] === "/") {
      selector += input[pos++];
      while (pos < input.length && isWhitespace(input[pos])) {
        selector += input[pos++];
      }
    }
    if (pos >= input.length || input[pos] !== ">") return null;
    selector += input[pos++];
  }
  return selector || null;
}
function isPossessiveMarker(input, pos) {
  if (pos >= input.length || input[pos] !== "'") return false;
  if (pos + 1 >= input.length) return false;
  const nextChar = input[pos + 1].toLowerCase();
  if (nextChar !== "s") return false;
  if (pos + 2 >= input.length) return true;
  const afterS = input[pos + 2];
  return isWhitespace(afterS) || afterS === "*" || !isAsciiIdentifierChar(afterS);
}
function extractStringLiteral(input, startPos) {
  if (startPos >= input.length) return null;
  const openQuote = input[startPos];
  if (!isQuote(openQuote)) return null;
  if (openQuote === "'" && isPossessiveMarker(input, startPos)) {
    return null;
  }
  const closeQuoteMap = {
    '"': '"',
    "'": "'",
    "`": "`",
    "\u300C": "\u300D"
  };
  const closeQuote = closeQuoteMap[openQuote];
  if (!closeQuote) return null;
  let pos = startPos + 1;
  let literal = openQuote;
  let escaped = false;
  while (pos < input.length) {
    const char = input[pos];
    literal += char;
    if (escaped) {
      escaped = false;
    } else if (char === "\\") {
      escaped = true;
    } else if (char === closeQuote) {
      return literal;
    }
    pos++;
  }
  return literal;
}
function isUrlStart(input, pos) {
  if (pos >= input.length) return false;
  const char = input[pos];
  const next = input[pos + 1] || "";
  const third = input[pos + 2] || "";
  if (char === "/" && next !== "/" && /[a-zA-Z0-9._-]/.test(next)) {
    return true;
  }
  if (char === "/" && next === "/" && /[a-zA-Z]/.test(third)) {
    return true;
  }
  if (char === "." && (next === "/" || next === "." && third === "/")) {
    return true;
  }
  const slice = input.slice(pos, pos + 8).toLowerCase();
  if (slice.startsWith("http://") || slice.startsWith("https://")) {
    return true;
  }
  return false;
}
function extractUrl(input, startPos) {
  if (!isUrlStart(input, startPos)) return null;
  let pos = startPos;
  let url = "";
  const urlChars = /[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;
  while (pos < input.length) {
    const char = input[pos];
    if (char === "#") {
      if (url.length > 0 && /[a-zA-Z0-9/.]$/.test(url)) {
        url += char;
        pos++;
        while (pos < input.length && /[a-zA-Z0-9_-]/.test(input[pos])) {
          url += input[pos++];
        }
      }
      break;
    }
    if (urlChars.test(char)) {
      url += char;
      pos++;
    } else {
      break;
    }
  }
  if (url.length < 2) return null;
  return url;
}
function extractNumber(input, startPos) {
  if (startPos >= input.length) return null;
  const char = input[startPos];
  if (!isDigit(char) && char !== "-" && char !== "+") return null;
  let pos = startPos;
  let number = "";
  if (input[pos] === "-" || input[pos] === "+") {
    number += input[pos++];
  }
  if (pos >= input.length || !isDigit(input[pos])) {
    return null;
  }
  while (pos < input.length && isDigit(input[pos])) {
    number += input[pos++];
  }
  if (pos < input.length && input[pos] === ".") {
    number += input[pos++];
    while (pos < input.length && isDigit(input[pos])) {
      number += input[pos++];
    }
  }
  if (pos < input.length) {
    const suffix = input.slice(pos, pos + 2);
    if (suffix === "ms") {
      number += "ms";
    } else if (input[pos] === "s" || input[pos] === "m" || input[pos] === "h") {
      number += input[pos];
    }
  }
  return number;
}
var _BaseTokenizer = class _BaseTokenizer {
  constructor() {
    /** Keywords derived from profile, sorted longest-first for greedy matching */
    this.profileKeywords = [];
    /** Map for O(1) keyword lookups by lowercase native word */
    this.profileKeywordMap = /* @__PURE__ */ new Map();
  }
  /**
   * Initialize keyword mappings from a language profile.
   * Builds a list of native→english mappings from:
   * - profile.keywords (primary + alternatives)
   * - profile.references (me, it, you, etc.)
   * - profile.roleMarkers (into, from, with, etc.)
   *
   * Results are sorted longest-first for greedy matching (important for non-space languages).
   * Extras take precedence over profile entries when there are duplicates.
   *
   * @param profile - Language profile containing keyword translations
   * @param extras - Additional keyword entries to include (literals, positional, events)
   */
  initializeKeywordsFromProfile(profile, extras = []) {
    const keywordMap = /* @__PURE__ */ new Map();
    if (profile.keywords) {
      for (const [normalized2, translation] of Object.entries(profile.keywords)) {
        keywordMap.set(translation.primary, {
          native: translation.primary,
          normalized: translation.normalized || normalized2
        });
        if (translation.alternatives) {
          for (const alt of translation.alternatives) {
            keywordMap.set(alt, {
              native: alt,
              normalized: translation.normalized || normalized2
            });
          }
        }
      }
    }
    if (profile.references) {
      for (const [normalized2, native] of Object.entries(profile.references)) {
        keywordMap.set(native, { native, normalized: normalized2 });
      }
    }
    if (profile.roleMarkers) {
      for (const [role, marker] of Object.entries(profile.roleMarkers)) {
        if (marker.primary) {
          keywordMap.set(marker.primary, { native: marker.primary, normalized: role });
        }
        if (marker.alternatives) {
          for (const alt of marker.alternatives) {
            keywordMap.set(alt, { native: alt, normalized: role });
          }
        }
      }
    }
    for (const extra of extras) {
      keywordMap.set(extra.native, extra);
    }
    this.profileKeywords = Array.from(keywordMap.values()).sort(
      (a, b) => b.native.length - a.native.length
    );
    this.profileKeywordMap = /* @__PURE__ */ new Map();
    for (const keyword of this.profileKeywords) {
      this.profileKeywordMap.set(keyword.native.toLowerCase(), keyword);
      const normalized2 = this.removeDiacritics(keyword.native);
      if (normalized2 !== keyword.native && !this.profileKeywordMap.has(normalized2.toLowerCase())) {
        this.profileKeywordMap.set(normalized2.toLowerCase(), keyword);
      }
    }
  }
  /**
   * Remove diacritical marks from a word for normalization.
   * Primarily for Arabic (shadda, fatha, kasra, damma, sukun, etc.)
   * but could be extended for other languages.
   *
   * @param word - Word to normalize
   * @returns Word without diacritics
   */
  removeDiacritics(word) {
    return word.replace(/[\u064B-\u0652\u0670]/g, "");
  }
  /**
   * Try to match a keyword from profile at the current position.
   * Uses longest-first greedy matching (important for non-space languages).
   *
   * @param input - Input string
   * @param pos - Current position
   * @returns Token if matched, null otherwise
   */
  tryProfileKeyword(input, pos) {
    for (const entry of this.profileKeywords) {
      if (input.slice(pos).startsWith(entry.native)) {
        return createToken(
          entry.native,
          "keyword",
          createPosition(pos, pos + entry.native.length),
          entry.normalized
        );
      }
    }
    return null;
  }
  /**
   * Check if the remaining input starts with any known keyword.
   * Useful for non-space languages to detect word boundaries.
   *
   * @param input - Input string
   * @param pos - Current position
   * @returns true if a keyword starts at this position
   */
  isKeywordStart(input, pos) {
    const remaining = input.slice(pos);
    return this.profileKeywords.some((entry) => remaining.startsWith(entry.native));
  }
  /**
   * Look up a keyword by native word (case-insensitive).
   * O(1) lookup using the keyword map.
   *
   * @param native - Native word to look up
   * @returns KeywordEntry if found, undefined otherwise
   */
  lookupKeyword(native) {
    return this.profileKeywordMap.get(native.toLowerCase());
  }
  /**
   * Check if a word is a known keyword (case-insensitive).
   * O(1) lookup using the keyword map.
   *
   * @param native - Native word to check
   * @returns true if the word is a keyword
   */
  isKeyword(native) {
    return this.profileKeywordMap.has(native.toLowerCase());
  }
  /**
   * Set the morphological normalizer for this tokenizer.
   */
  setNormalizer(normalizer) {
    this.normalizer = normalizer;
  }
  /**
   * Try to normalize a word using the morphological normalizer.
   * Returns null if no normalizer is set or normalization fails.
   *
   * Note: We don't check isNormalizable() here because the individual tokenizers
   * historically called normalize() directly without that check. The normalize()
   * method itself handles returning noChange() for words that can't be normalized.
   */
  tryNormalize(word) {
    if (!this.normalizer) return null;
    const result = this.normalizer.normalize(word);
    if (result.stem !== word && result.confidence >= 0.7) {
      return result;
    }
    return null;
  }
  /**
   * Try morphological normalization and keyword lookup.
   *
   * If the word can be normalized to a stem that matches a known keyword,
   * returns a keyword token with morphological metadata (stem, stemConfidence).
   *
   * This is the common pattern for handling conjugated verbs across languages:
   * 1. Normalize the word (e.g., "toggled" → "toggle")
   * 2. Look up the stem in the keyword map
   * 3. Create a token with both the original form and stem metadata
   *
   * @param word - The word to normalize and look up
   * @param startPos - Start position for the token
   * @param endPos - End position for the token
   * @returns Token if stem matches a keyword, null otherwise
   */
  tryMorphKeywordMatch(word, startPos, endPos) {
    const result = this.tryNormalize(word);
    if (!result) return null;
    const stemEntry = this.lookupKeyword(result.stem);
    if (!stemEntry) return null;
    const tokenOptions = {
      normalized: stemEntry.normalized,
      stem: result.stem,
      stemConfidence: result.confidence
    };
    return createToken(word, "keyword", createPosition(startPos, endPos), tokenOptions);
  }
  /**
   * Try to extract a CSS selector at the current position.
   */
  trySelector(input, pos) {
    const selector = extractCssSelector(input, pos);
    if (selector) {
      return createToken(selector, "selector", createPosition(pos, pos + selector.length));
    }
    return null;
  }
  /**
   * Try to extract an event modifier at the current position.
   * Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
   */
  tryEventModifier(input, pos) {
    if (input[pos] !== ".") {
      return null;
    }
    const match = input.slice(pos).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);
    if (!match) {
      return null;
    }
    const fullMatch = match[0].replace(/(\s|\.)$/, "");
    const modifierName = fullMatch.slice(1).split("(")[0];
    const value = match[1];
    const token = createToken(
      fullMatch,
      "event-modifier",
      createPosition(pos, pos + fullMatch.length)
    );
    return {
      ...token,
      metadata: {
        modifierName,
        value: value ? modifierName === "queue" ? value : parseInt(value, 10) : void 0
      }
    };
  }
  /**
   * Try to extract a string literal at the current position.
   */
  tryString(input, pos) {
    const literal = extractStringLiteral(input, pos);
    if (literal) {
      return createToken(literal, "literal", createPosition(pos, pos + literal.length));
    }
    return null;
  }
  /**
   * Try to extract a number at the current position.
   */
  tryNumber(input, pos) {
    const number = extractNumber(input, pos);
    if (number) {
      return createToken(number, "literal", createPosition(pos, pos + number.length));
    }
    return null;
  }
  /**
   * Try to match a time unit from a list of patterns.
   *
   * @param input - Input string
   * @param pos - Position after the number
   * @param timeUnits - Array of time unit mappings (native pattern → standard suffix)
   * @param skipWhitespace - Whether to skip whitespace before time unit (default: false)
   * @returns Object with matched suffix and new position, or null if no match
   */
  tryMatchTimeUnit(input, pos, timeUnits, skipWhitespace = false) {
    let unitPos = pos;
    if (skipWhitespace) {
      while (unitPos < input.length && isWhitespace(input[unitPos])) {
        unitPos++;
      }
    }
    const remaining = input.slice(unitPos);
    for (const unit of timeUnits) {
      const candidate = remaining.slice(0, unit.length);
      const matches = unit.caseInsensitive ? candidate.toLowerCase() === unit.pattern.toLowerCase() : candidate === unit.pattern;
      if (matches) {
        if (unit.notFollowedBy) {
          const nextChar = remaining[unit.length] || "";
          if (nextChar === unit.notFollowedBy) continue;
        }
        if (unit.checkBoundary) {
          const nextChar = remaining[unit.length] || "";
          if (isAsciiIdentifierChar(nextChar)) continue;
        }
        return { suffix: unit.suffix, endPos: unitPos + unit.length };
      }
    }
    return null;
  }
  /**
   * Parse a base number (sign, integer, decimal) without time units.
   * Returns the number string and end position.
   *
   * @param input - Input string
   * @param startPos - Start position
   * @param allowSign - Whether to allow +/- sign (default: true)
   * @returns Object with number string and end position, or null
   */
  parseBaseNumber(input, startPos, allowSign = true) {
    let pos = startPos;
    let number = "";
    if (allowSign && (input[pos] === "-" || input[pos] === "+")) {
      number += input[pos++];
    }
    if (pos >= input.length || !isDigit(input[pos])) {
      return null;
    }
    while (pos < input.length && isDigit(input[pos])) {
      number += input[pos++];
    }
    if (pos < input.length && input[pos] === ".") {
      number += input[pos++];
      while (pos < input.length && isDigit(input[pos])) {
        number += input[pos++];
      }
    }
    if (!number || number === "-" || number === "+") return null;
    return { number, endPos: pos };
  }
  /**
   * Try to extract a number with native language time units.
   *
   * This is a template method that handles the common pattern:
   * 1. Parse the base number (sign, integer, decimal)
   * 2. Try to match native language time units
   * 3. Fall back to standard time units (ms, s, m, h)
   *
   * @param input - Input string
   * @param pos - Start position
   * @param nativeTimeUnits - Language-specific time unit mappings
   * @param options - Configuration options
   * @returns Token if number found, null otherwise
   */
  tryNumberWithTimeUnits(input, pos, nativeTimeUnits, options = {}) {
    const { allowSign = true, skipWhitespace = false } = options;
    const baseResult = this.parseBaseNumber(input, pos, allowSign);
    if (!baseResult) return null;
    let { number, endPos } = baseResult;
    const allUnits = [...nativeTimeUnits, ..._BaseTokenizer.STANDARD_TIME_UNITS];
    const timeMatch = this.tryMatchTimeUnit(input, endPos, allUnits, skipWhitespace);
    if (timeMatch) {
      number += timeMatch.suffix;
      endPos = timeMatch.endPos;
    }
    return createToken(number, "literal", createPosition(pos, endPos));
  }
  /**
   * Try to extract a URL at the current position.
   * Handles /path, ./path, ../path, //domain.com, http://, https://
   */
  tryUrl(input, pos) {
    const url = extractUrl(input, pos);
    if (url) {
      return createToken(url, "url", createPosition(pos, pos + url.length));
    }
    return null;
  }
  /**
   * Try to extract a variable reference (:varname) at the current position.
   * In hyperscript, :x refers to a local variable named x.
   */
  tryVariableRef(input, pos) {
    if (input[pos] !== ":") return null;
    if (pos + 1 >= input.length) return null;
    if (!isAsciiIdentifierChar(input[pos + 1])) return null;
    let endPos = pos + 1;
    while (endPos < input.length && isAsciiIdentifierChar(input[endPos])) {
      endPos++;
    }
    const varRef = input.slice(pos, endPos);
    return createToken(varRef, "identifier", createPosition(pos, endPos));
  }
  /**
   * Try to extract an operator or punctuation token at the current position.
   * Handles two-character operators (==, !=, etc.) and single-character operators.
   */
  tryOperator(input, pos) {
    const twoChar = input.slice(pos, pos + 2);
    if (["==", "!=", "<=", ">=", "&&", "||", "->"].includes(twoChar)) {
      return createToken(twoChar, "operator", createPosition(pos, pos + 2));
    }
    const oneChar = input[pos];
    if (["<", ">", "!", "+", "-", "*", "/", "="].includes(oneChar)) {
      return createToken(oneChar, "operator", createPosition(pos, pos + 1));
    }
    if (["(", ")", "{", "}", ",", ";", ":"].includes(oneChar)) {
      return createToken(oneChar, "punctuation", createPosition(pos, pos + 1));
    }
    return null;
  }
  /**
   * Try to match a multi-character particle from a list.
   *
   * Used by languages like Japanese, Korean, and Chinese that have
   * multi-character particles (e.g., Japanese から, まで, より).
   *
   * @param input - Input string
   * @param pos - Current position
   * @param particles - Array of multi-character particles to match
   * @returns Token if matched, null otherwise
   */
  tryMultiCharParticle(input, pos, particles) {
    for (const particle of particles) {
      if (input.slice(pos, pos + particle.length) === particle) {
        return createToken(particle, "particle", createPosition(pos, pos + particle.length));
      }
    }
    return null;
  }
};
/**
 * Configuration for native language time units.
 * Maps patterns to their standard suffix (ms, s, m, h).
 */
_BaseTokenizer.STANDARD_TIME_UNITS = [
  { pattern: "ms", suffix: "ms", length: 2 },
  { pattern: "s", suffix: "s", length: 1, checkBoundary: true },
  { pattern: "m", suffix: "m", length: 1, checkBoundary: true, notFollowedBy: "s" },
  { pattern: "h", suffix: "h", length: 1, checkBoundary: true }
];
var BaseTokenizer = _BaseTokenizer;

// src/tokenizers/morphology/types.ts
function noChange(word) {
  return { stem: word, confidence: 1 };
}
function normalized(stem, confidence, metadata) {
  if (metadata) {
    return { stem, confidence, metadata };
  }
  return { stem, confidence };
}

// src/tokenizers/morphology/italian-normalizer.ts
function isItalianSpecificLetter(char) {
  return /[àèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]/.test(char);
}
function looksLikeItalianVerb(word) {
  const lower = word.toLowerCase();
  if (lower.endsWith("are") || lower.endsWith("ere") || lower.endsWith("ire")) return true;
  if (lower.endsWith("ando") || lower.endsWith("endo")) return true;
  if (lower.endsWith("ato") || lower.endsWith("uto") || lower.endsWith("ito")) return true;
  if (lower.endsWith("arsi") || lower.endsWith("ersi") || lower.endsWith("irsi")) return true;
  for (const char of word) {
    if (isItalianSpecificLetter(char)) return true;
  }
  return false;
}
var REFLEXIVE_SUFFIXES = ["si", "mi", "ti", "ci", "vi"];
var ARE_ENDINGS = [
  // Gerund (-ando)
  { ending: "ando", stem: "are", confidence: 0.88, type: "gerund" },
  // Past participle (-ato)
  { ending: "ato", stem: "are", confidence: 0.88, type: "participle" },
  { ending: "ata", stem: "are", confidence: 0.88, type: "participle" },
  { ending: "ati", stem: "are", confidence: 0.88, type: "participle" },
  { ending: "ate", stem: "are", confidence: 0.88, type: "participle" },
  // Present indicative
  { ending: "o", stem: "are", confidence: 0.75, type: "present" },
  // io
  { ending: "i", stem: "are", confidence: 0.72, type: "present" },
  // tu
  { ending: "a", stem: "are", confidence: 0.75, type: "present" },
  // lui/lei
  { ending: "iamo", stem: "are", confidence: 0.85, type: "present" },
  // noi
  { ending: "ate", stem: "are", confidence: 0.85, type: "present" },
  // voi
  { ending: "ano", stem: "are", confidence: 0.85, type: "present" },
  // loro
  // Imperfect
  { ending: "avo", stem: "are", confidence: 0.88, type: "past" },
  // io
  { ending: "avi", stem: "are", confidence: 0.88, type: "past" },
  // tu
  { ending: "ava", stem: "are", confidence: 0.88, type: "past" },
  // lui/lei
  { ending: "avamo", stem: "are", confidence: 0.88, type: "past" },
  // noi
  { ending: "avate", stem: "are", confidence: 0.88, type: "past" },
  // voi
  { ending: "avano", stem: "are", confidence: 0.88, type: "past" },
  // loro
  // Preterite (passato remoto)
  { ending: "ai", stem: "are", confidence: 0.85, type: "past" },
  // io
  { ending: "asti", stem: "are", confidence: 0.88, type: "past" },
  // tu
  { ending: "\xF2", stem: "are", confidence: 0.85, type: "past" },
  // lui/lei
  { ending: "ammo", stem: "are", confidence: 0.88, type: "past" },
  // noi
  { ending: "aste", stem: "are", confidence: 0.88, type: "past" },
  // voi
  { ending: "arono", stem: "are", confidence: 0.88, type: "past" },
  // loro
  // Subjunctive present
  { ending: "i", stem: "are", confidence: 0.72, type: "subjunctive" },
  // io/tu/lui (ambiguous)
  { ending: "ino", stem: "are", confidence: 0.82, type: "subjunctive" },
  // loro
  // Imperative
  { ending: "a", stem: "are", confidence: 0.75, type: "imperative" },
  // tu
  // Infinitive
  { ending: "are", stem: "are", confidence: 0.92, type: "dictionary" }
];
var ERE_ENDINGS = [
  // Gerund (-endo)
  { ending: "endo", stem: "ere", confidence: 0.88, type: "gerund" },
  // Past participle (-uto)
  { ending: "uto", stem: "ere", confidence: 0.85, type: "participle" },
  { ending: "uta", stem: "ere", confidence: 0.85, type: "participle" },
  { ending: "uti", stem: "ere", confidence: 0.85, type: "participle" },
  { ending: "ute", stem: "ere", confidence: 0.85, type: "participle" },
  // Present indicative
  { ending: "o", stem: "ere", confidence: 0.72, type: "present" },
  // io
  { ending: "i", stem: "ere", confidence: 0.72, type: "present" },
  // tu
  { ending: "e", stem: "ere", confidence: 0.72, type: "present" },
  // lui/lei
  { ending: "iamo", stem: "ere", confidence: 0.85, type: "present" },
  // noi
  { ending: "ete", stem: "ere", confidence: 0.85, type: "present" },
  // voi
  { ending: "ono", stem: "ere", confidence: 0.82, type: "present" },
  // loro
  // Imperfect
  { ending: "evo", stem: "ere", confidence: 0.88, type: "past" },
  // io
  { ending: "evi", stem: "ere", confidence: 0.88, type: "past" },
  // tu
  { ending: "eva", stem: "ere", confidence: 0.88, type: "past" },
  // lui/lei
  { ending: "evamo", stem: "ere", confidence: 0.88, type: "past" },
  // noi
  { ending: "evate", stem: "ere", confidence: 0.88, type: "past" },
  // voi
  { ending: "evano", stem: "ere", confidence: 0.88, type: "past" },
  // loro
  // Preterite
  { ending: "ei", stem: "ere", confidence: 0.85, type: "past" },
  // io
  { ending: "etti", stem: "ere", confidence: 0.85, type: "past" },
  // io (variant)
  { ending: "esti", stem: "ere", confidence: 0.88, type: "past" },
  // tu
  { ending: "\xE9", stem: "ere", confidence: 0.85, type: "past" },
  // lui/lei
  { ending: "ette", stem: "ere", confidence: 0.85, type: "past" },
  // lui/lei (variant)
  { ending: "emmo", stem: "ere", confidence: 0.88, type: "past" },
  // noi
  { ending: "este", stem: "ere", confidence: 0.88, type: "past" },
  // voi
  { ending: "erono", stem: "ere", confidence: 0.88, type: "past" },
  // loro
  { ending: "ettero", stem: "ere", confidence: 0.88, type: "past" },
  // loro (variant)
  // Infinitive
  { ending: "ere", stem: "ere", confidence: 0.92, type: "dictionary" }
];
var IRE_ENDINGS = [
  // Gerund (-endo)
  { ending: "endo", stem: "ire", confidence: 0.85, type: "gerund" },
  // Past participle (-ito)
  { ending: "ito", stem: "ire", confidence: 0.85, type: "participle" },
  { ending: "ita", stem: "ire", confidence: 0.85, type: "participle" },
  { ending: "iti", stem: "ire", confidence: 0.85, type: "participle" },
  { ending: "ite", stem: "ire", confidence: 0.85, type: "participle" },
  // Present indicative (standard)
  { ending: "o", stem: "ire", confidence: 0.7, type: "present" },
  // io
  { ending: "i", stem: "ire", confidence: 0.7, type: "present" },
  // tu
  { ending: "e", stem: "ire", confidence: 0.7, type: "present" },
  // lui/lei
  { ending: "iamo", stem: "ire", confidence: 0.85, type: "present" },
  // noi
  { ending: "ite", stem: "ire", confidence: 0.85, type: "present" },
  // voi
  { ending: "ono", stem: "ire", confidence: 0.78, type: "present" },
  // loro
  // Present indicative (-isco verbs)
  { ending: "isco", stem: "ire", confidence: 0.85, type: "present" },
  // io
  { ending: "isci", stem: "ire", confidence: 0.85, type: "present" },
  // tu
  { ending: "isce", stem: "ire", confidence: 0.85, type: "present" },
  // lui/lei
  { ending: "iscono", stem: "ire", confidence: 0.88, type: "present" },
  // loro
  // Imperfect
  { ending: "ivo", stem: "ire", confidence: 0.88, type: "past" },
  // io
  { ending: "ivi", stem: "ire", confidence: 0.88, type: "past" },
  // tu
  { ending: "iva", stem: "ire", confidence: 0.88, type: "past" },
  // lui/lei
  { ending: "ivamo", stem: "ire", confidence: 0.88, type: "past" },
  // noi
  { ending: "ivate", stem: "ire", confidence: 0.88, type: "past" },
  // voi
  { ending: "ivano", stem: "ire", confidence: 0.88, type: "past" },
  // loro
  // Preterite
  { ending: "ii", stem: "ire", confidence: 0.85, type: "past" },
  // io
  { ending: "isti", stem: "ire", confidence: 0.88, type: "past" },
  // tu
  { ending: "\xEC", stem: "ire", confidence: 0.85, type: "past" },
  // lui/lei
  { ending: "immo", stem: "ire", confidence: 0.88, type: "past" },
  // noi
  { ending: "iste", stem: "ire", confidence: 0.88, type: "past" },
  // voi
  { ending: "irono", stem: "ire", confidence: 0.88, type: "past" },
  // loro
  // Infinitive
  { ending: "ire", stem: "ire", confidence: 0.92, type: "dictionary" }
];
var ALL_ENDINGS = [...ARE_ENDINGS, ...ERE_ENDINGS, ...IRE_ENDINGS].sort(
  (a, b) => b.ending.length - a.ending.length
);
var ItalianMorphologicalNormalizer = class {
  constructor() {
    this.language = "it";
  }
  /**
   * Check if a word might be an Italian verb that can be normalized.
   */
  isNormalizable(word) {
    if (word.length < 3) return false;
    return looksLikeItalianVerb(word);
  }
  /**
   * Normalize an Italian word to its infinitive form.
   */
  normalize(word) {
    const lower = word.toLowerCase();
    if (lower.endsWith("are") || lower.endsWith("ere") || lower.endsWith("ire")) {
      if (!REFLEXIVE_SUFFIXES.some(
        (s) => lower.endsWith(s + "are") || lower.endsWith(s + "ere") || lower.endsWith(s + "ire")
      )) {
        return noChange(word);
      }
    }
    const reflexiveResult = this.tryReflexiveNormalization(lower);
    if (reflexiveResult) return reflexiveResult;
    const conjugationResult = this.tryConjugationNormalization(lower);
    if (conjugationResult) return conjugationResult;
    return noChange(word);
  }
  /**
   * Try to normalize a reflexive verb.
   * Reflexive verbs end with -si, -mi, -ti, -ci, -vi attached to infinitive.
   *
   * In Italian, reflexive infinitives drop the final -e before attaching the pronoun:
   *   mostrare + si → mostrarsi (not mostraresi)
   *   nascondere + si → nascondersi
   *
   * Examples:
   *   mostrarsi → mostrare
   *   nascondersi → nascondere
   */
  tryReflexiveNormalization(word) {
    for (const suffix of REFLEXIVE_SUFFIXES) {
      if (word.endsWith(suffix)) {
        const withoutReflexive = word.slice(0, -suffix.length);
        if (withoutReflexive.endsWith("ar") || withoutReflexive.endsWith("er") || withoutReflexive.endsWith("ir")) {
          const infinitive = withoutReflexive + "e";
          return normalized(infinitive, 0.88, {
            removedSuffixes: [suffix],
            conjugationType: "reflexive"
          });
        }
        if (withoutReflexive.endsWith("are") || withoutReflexive.endsWith("ere") || withoutReflexive.endsWith("ire")) {
          return normalized(withoutReflexive, 0.88, {
            removedSuffixes: [suffix],
            conjugationType: "reflexive"
          });
        }
        const innerResult = this.tryConjugationNormalization(withoutReflexive);
        if (innerResult && innerResult.stem !== withoutReflexive) {
          return normalized(innerResult.stem, innerResult.confidence * 0.95, {
            removedSuffixes: [suffix, ...innerResult.metadata?.removedSuffixes || []],
            conjugationType: "reflexive"
          });
        }
      }
    }
    return null;
  }
  /**
   * Try to normalize a conjugated verb to its infinitive.
   */
  tryConjugationNormalization(word) {
    for (const rule of ALL_ENDINGS) {
      if (word.endsWith(rule.ending)) {
        const stemBase = word.slice(0, -rule.ending.length);
        if (stemBase.length < 2) continue;
        const infinitive = stemBase + rule.stem;
        return normalized(infinitive, rule.confidence, {
          removedSuffixes: [rule.ending],
          conjugationType: rule.type
        });
      }
    }
    return null;
  }
};
var italianMorphologicalNormalizer = new ItalianMorphologicalNormalizer();

// src/generators/profiles/italian.ts
var italianProfile = {
  code: "it",
  name: "Italian",
  nativeName: "Italiano",
  direction: "ltr",
  wordOrder: "SVO",
  markingStrategy: "preposition",
  usesSpaces: true,
  // Infinitive is standard for Italian software UI (Salvare, Annullare, Aprire)
  // This matches macOS, Windows, and web app conventions
  defaultVerbForm: "infinitive",
  verb: {
    position: "start",
    subjectDrop: true
  },
  references: {
    me: "io",
    // "I/me"
    it: "esso",
    // "it"
    you: "tu",
    // "you"
    result: "risultato",
    event: "evento",
    target: "obiettivo",
    body: "corpo"
  },
  possessive: {
    marker: "di",
    // Italian uses "di" for general possession
    markerPosition: "before-property",
    usePossessiveAdjectives: true,
    specialForms: {
      me: "mio",
      // "my" (possessive adjective)
      it: "suo",
      // "its"
      you: "tuo"
      // "your"
    },
    keywords: {
      // "my" variants (masculine/feminine singular/plural)
      mio: "me",
      mia: "me",
      miei: "me",
      mie: "me",
      // "your" variants
      tuo: "you",
      tua: "you",
      tuoi: "you",
      tue: "you",
      // "its/his/her" variants
      suo: "it",
      sua: "it",
      suoi: "it",
      sue: "it"
    }
  },
  roleMarkers: {
    destination: { primary: "in", alternatives: ["su", "a"], position: "before" },
    source: { primary: "da", alternatives: ["di"], position: "before" },
    patient: { primary: "", position: "before" },
    style: { primary: "con", position: "before" }
  },
  keywords: {
    // Class/Attribute operations
    toggle: { primary: "commutare", alternatives: ["alternare", "cambiare"], normalized: "toggle" },
    add: { primary: "aggiungere", alternatives: ["aggiungi"], normalized: "add" },
    remove: { primary: "rimuovere", alternatives: ["eliminare", "togliere"], normalized: "remove" },
    // Content operations
    put: { primary: "mettere", alternatives: ["inserire"], normalized: "put" },
    append: { primary: "aggiungere", normalized: "append" },
    prepend: { primary: "anteporre", normalized: "prepend" },
    take: { primary: "prendere", normalized: "take" },
    make: { primary: "fare", alternatives: ["creare"], normalized: "make" },
    clone: { primary: "clonare", alternatives: ["copiare"], normalized: "clone" },
    swap: { primary: "scambiare", alternatives: ["cambiare"], normalized: "swap" },
    morph: { primary: "trasformare", alternatives: ["convertire"], normalized: "morph" },
    // Variable operations
    set: { primary: "impostare", alternatives: ["definire"], normalized: "set" },
    get: { primary: "ottenere", alternatives: ["prendere"], normalized: "get" },
    increment: { primary: "incrementare", alternatives: ["aumentare"], normalized: "increment" },
    decrement: { primary: "decrementare", alternatives: ["diminuire"], normalized: "decrement" },
    log: { primary: "registrare", normalized: "log" },
    // Visibility
    show: { primary: "mostrare", alternatives: ["visualizzare"], normalized: "show" },
    hide: { primary: "nascondere", normalized: "hide" },
    transition: { primary: "transizione", alternatives: ["animare"], normalized: "transition" },
    // Events
    on: { primary: "su", alternatives: ["quando", "al"], normalized: "on" },
    trigger: { primary: "scatenare", alternatives: ["attivare"], normalized: "trigger" },
    send: { primary: "inviare", normalized: "send" },
    // DOM focus
    focus: { primary: "focalizzare", normalized: "focus" },
    blur: { primary: "sfuocare", normalized: "blur" },
    // Navigation
    go: { primary: "andare", alternatives: ["navigare", "vai"], normalized: "go" },
    // Async
    wait: { primary: "aspettare", alternatives: ["attendere"], normalized: "wait" },
    fetch: { primary: "recuperare", normalized: "fetch" },
    settle: { primary: "stabilizzare", normalized: "settle" },
    // Control flow
    if: { primary: "se", normalized: "if" },
    when: { primary: "quando", normalized: "when" },
    where: { primary: "dove", normalized: "where" },
    else: { primary: "altrimenti", normalized: "else" },
    repeat: { primary: "ripetere", normalized: "repeat" },
    for: { primary: "per", normalized: "for" },
    while: { primary: "mentre", normalized: "while" },
    continue: { primary: "continuare", normalized: "continue" },
    halt: { primary: "fermare", normalized: "halt" },
    throw: { primary: "lanciare", normalized: "throw" },
    call: { primary: "chiamare", normalized: "call" },
    return: { primary: "ritornare", normalized: "return" },
    then: { primary: "allora", alternatives: ["poi", "quindi"], normalized: "then" },
    and: { primary: "e", alternatives: ["anche"], normalized: "and" },
    end: { primary: "fine", normalized: "end" },
    // Advanced
    js: { primary: "js", normalized: "js" },
    async: { primary: "asincrono", normalized: "async" },
    tell: { primary: "dire", normalized: "tell" },
    default: { primary: "predefinito", normalized: "default" },
    init: { primary: "inizializzare", alternatives: ["inizia"], normalized: "init" },
    behavior: { primary: "comportamento", normalized: "behavior" },
    install: { primary: "installare", normalized: "install" },
    measure: { primary: "misurare", normalized: "measure" },
    // Modifiers
    into: { primary: "in", alternatives: ["dentro"], normalized: "into" },
    before: { primary: "prima", normalized: "before" },
    after: { primary: "dopo", normalized: "after" },
    // Common event names (for event handler patterns)
    click: { primary: "clic", alternatives: ["clicca"], normalized: "click" },
    hover: { primary: "passaggio", alternatives: ["sorvolo"], normalized: "hover" },
    submit: { primary: "invio", alternatives: ["inviare"], normalized: "submit" },
    input: { primary: "inserimento", alternatives: ["input"], normalized: "input" },
    change: { primary: "cambio", alternatives: ["cambiamento"], normalized: "change" },
    // Event modifiers
    until: { primary: "fino", normalized: "until" },
    event: { primary: "evento", normalized: "event" },
    from: { primary: "da", alternatives: ["di"], normalized: "from" }
  },
  eventHandler: {
    keyword: { primary: "su", alternatives: ["al", "quando"], normalized: "on" },
    sourceMarker: { primary: "da", alternatives: ["di"], position: "before" },
    conditionalKeyword: { primary: "quando", alternatives: ["se"] },
    // Event marker: al (at/upon), used in SVO pattern
    // Pattern: al [event] [verb] [patient] su [destination?]
    // Example: al clic commutare .active su #button
    eventMarker: { primary: "al", alternatives: ["allo", "alla"], position: "before" },
    temporalMarkers: ["quando", "al"]
    // temporal conjunctions (when)
  }
};

// src/tokenizers/italian.ts
var { isLetter: isItalianLetter, isIdentifierChar: isItalianIdentifierChar } = createLatinCharClassifiers(/[a-zA-ZàèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]/);
var ITALIAN_TIME_UNITS = [
  { pattern: "millisecondi", suffix: "ms", length: 12, caseInsensitive: true },
  { pattern: "millisecondo", suffix: "ms", length: 12, caseInsensitive: true },
  { pattern: "secondi", suffix: "s", length: 7, caseInsensitive: true },
  { pattern: "secondo", suffix: "s", length: 7, caseInsensitive: true },
  { pattern: "minuti", suffix: "m", length: 6, caseInsensitive: true },
  { pattern: "minuto", suffix: "m", length: 6, caseInsensitive: true },
  { pattern: "ore", suffix: "h", length: 3, caseInsensitive: true },
  { pattern: "ora", suffix: "h", length: 3, caseInsensitive: true }
];
var PREPOSITIONS = /* @__PURE__ */ new Set([
  "in",
  // in, into
  "a",
  // to, at
  "di",
  // of, from
  "da",
  // from, by
  "con",
  // with
  "su",
  // on
  "per",
  // for
  "tra",
  // between
  "fra",
  // between (variant)
  "dopo",
  // after
  "prima",
  // before
  "dentro",
  // inside
  "fuori",
  // outside
  "sopra",
  // above
  "sotto",
  // under
  // Articulated prepositions
  "al",
  // a + il
  "allo",
  // a + lo
  "alla",
  // a + la
  "ai",
  // a + i
  "agli",
  // a + gli
  "alle",
  // a + le
  "del",
  // di + il
  "dello",
  // di + lo
  "della",
  // di + la
  "dei",
  // di + i
  "degli",
  // di + gli
  "delle",
  // di + le
  "dal",
  // da + il
  "dallo",
  // da + lo
  "dalla",
  // da + la
  "dai",
  // da + i
  "dagli",
  // da + gli
  "dalle",
  // da + le
  "nel",
  // in + il
  "nello",
  // in + lo
  "nella",
  // in + la
  "nei",
  // in + i
  "negli",
  // in + gli
  "nelle",
  // in + le
  "sul",
  // su + il
  "sullo",
  // su + lo
  "sulla",
  // su + la
  "sui",
  // su + i
  "sugli",
  // su + gli
  "sulle"
  // su + le
]);
var ITALIAN_EXTRAS = [
  // Values/Literals
  { native: "vero", normalized: "true" },
  { native: "falso", normalized: "false" },
  { native: "nullo", normalized: "null" },
  { native: "indefinito", normalized: "undefined" },
  // Positional
  { native: "primo", normalized: "first" },
  { native: "prima", normalized: "first" },
  { native: "ultimo", normalized: "last" },
  { native: "ultima", normalized: "last" },
  { native: "prossimo", normalized: "next" },
  { native: "successivo", normalized: "next" },
  { native: "precedente", normalized: "previous" },
  { native: "vicino", normalized: "closest" },
  { native: "padre", normalized: "parent" },
  // Events
  { native: "clic", normalized: "click" },
  { native: "click", normalized: "click" },
  { native: "fare clic", normalized: "click" },
  { native: "input", normalized: "input" },
  { native: "cambio", normalized: "change" },
  { native: "invio", normalized: "submit" },
  { native: "tasto gi\xF9", normalized: "keydown" },
  { native: "tasto su", normalized: "keyup" },
  { native: "mouse sopra", normalized: "mouseover" },
  { native: "mouse fuori", normalized: "mouseout" },
  { native: "fuoco", normalized: "focus" },
  { native: "sfuocatura", normalized: "blur" },
  { native: "caricamento", normalized: "load" },
  { native: "scorrimento", normalized: "scroll" },
  // References
  { native: "io", normalized: "me" },
  { native: "me", normalized: "me" },
  { native: "destinazione", normalized: "target" },
  // Time units
  { native: "secondo", normalized: "s" },
  { native: "secondi", normalized: "s" },
  { native: "millisecondo", normalized: "ms" },
  { native: "millisecondi", normalized: "ms" },
  { native: "minuto", normalized: "m" },
  { native: "minuti", normalized: "m" },
  { native: "ora", normalized: "h" },
  { native: "ore", normalized: "h" },
  // Multi-word phrases
  { native: "fino a", normalized: "until" },
  { native: "prima di", normalized: "before" },
  { native: "dopo di", normalized: "after" },
  { native: "dentro di", normalized: "into" },
  { native: "fuori di", normalized: "out" },
  // Override profile conflicts (aggiungere is both add and append in profile, prefer add)
  { native: "aggiungere", normalized: "add" },
  // Imperative forms (profile has infinitives)
  { native: "aggiungi", normalized: "add" },
  { native: "rimuovi", normalized: "remove" },
  { native: "elimina", normalized: "remove" },
  { native: "togli", normalized: "remove" },
  { native: "metti", normalized: "put" },
  { native: "inserisci", normalized: "put" },
  { native: "prendi", normalized: "take" },
  { native: "fai", normalized: "make" },
  { native: "crea", normalized: "make" },
  { native: "clona", normalized: "clone" },
  { native: "copia", normalized: "clone" },
  { native: "imposta", normalized: "set" },
  { native: "ottieni", normalized: "get" },
  { native: "incrementa", normalized: "increment" },
  { native: "aumenta", normalized: "increment" },
  { native: "decrementa", normalized: "decrement" },
  { native: "diminuisci", normalized: "decrement" },
  { native: "registra", normalized: "log" },
  { native: "mostra", normalized: "show" },
  { native: "visualizza", normalized: "show" },
  { native: "nascondi", normalized: "hide" },
  { native: "anima", normalized: "transition" },
  { native: "scatena", normalized: "trigger" },
  { native: "attiva", normalized: "trigger" },
  { native: "invia", normalized: "send" },
  { native: "focalizza", normalized: "focus" },
  { native: "sfuoca", normalized: "blur" },
  { native: "vai", normalized: "go" },
  { native: "naviga", normalized: "go" },
  { native: "aspetta", normalized: "wait" },
  { native: "attendi", normalized: "wait" },
  { native: "recupera", normalized: "fetch" },
  { native: "stabilizza", normalized: "settle" },
  { native: "ripeti", normalized: "repeat" },
  { native: "continua", normalized: "continue" },
  { native: "ferma", normalized: "halt" },
  { native: "lancia", normalized: "throw" },
  { native: "chiama", normalized: "call" },
  { native: "ritorna", normalized: "return" },
  { native: "inizializza", normalized: "init" },
  { native: "installa", normalized: "install" },
  { native: "misura", normalized: "measure" },
  // Logical/conditional
  { native: "e", normalized: "and" },
  { native: "o", normalized: "or" },
  { native: "non", normalized: "not" },
  { native: "\xE8", normalized: "is" },
  { native: "esiste", normalized: "exists" },
  { native: "vuoto", normalized: "empty" },
  // Synonyms not in profile
  { native: "toggle", normalized: "toggle" },
  { native: "di", normalized: "tell" }
];
var ItalianTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "it";
    this.direction = "ltr";
    this.initializeKeywordsFromProfile(italianProfile, ITALIAN_EXTRAS);
    this.normalizer = new ItalianMorphologicalNormalizer();
  }
  tokenize(input) {
    const tokens = [];
    let pos = 0;
    while (pos < input.length) {
      if (isWhitespace(input[pos])) {
        pos++;
        continue;
      }
      if (isSelectorStart(input[pos])) {
        const modifierToken = this.tryEventModifier(input, pos);
        if (modifierToken) {
          tokens.push(modifierToken);
          pos = modifierToken.position.end;
          continue;
        }
        const selectorToken = this.trySelector(input, pos);
        if (selectorToken) {
          tokens.push(selectorToken);
          pos = selectorToken.position.end;
          continue;
        }
      }
      if (isQuote(input[pos])) {
        const stringToken = this.tryString(input, pos);
        if (stringToken) {
          tokens.push(stringToken);
          pos = stringToken.position.end;
          continue;
        }
      }
      if (isUrlStart(input, pos)) {
        const urlToken = this.tryUrl(input, pos);
        if (urlToken) {
          tokens.push(urlToken);
          pos = urlToken.position.end;
          continue;
        }
      }
      if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
        const numberToken = this.extractItalianNumber(input, pos);
        if (numberToken) {
          tokens.push(numberToken);
          pos = numberToken.position.end;
          continue;
        }
      }
      const varToken = this.tryVariableRef(input, pos);
      if (varToken) {
        tokens.push(varToken);
        pos = varToken.position.end;
        continue;
      }
      const phraseToken = this.tryMultiWordPhrase(input, pos);
      if (phraseToken) {
        tokens.push(phraseToken);
        pos = phraseToken.position.end;
        continue;
      }
      if (isItalianLetter(input[pos])) {
        const wordToken = this.extractItalianWord(input, pos);
        if (wordToken) {
          tokens.push(wordToken);
          pos = wordToken.position.end;
          continue;
        }
      }
      const operatorToken = this.tryOperator(input, pos);
      if (operatorToken) {
        tokens.push(operatorToken);
        pos = operatorToken.position.end;
        continue;
      }
      pos++;
    }
    return new TokenStreamImpl(tokens, "it");
  }
  classifyToken(token) {
    const lower = token.toLowerCase();
    if (PREPOSITIONS.has(lower)) return "particle";
    if (this.isKeyword(lower)) return "keyword";
    if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
    if (token.startsWith('"') || token.startsWith("'")) return "literal";
    if (/^\d/.test(token)) return "literal";
    if (["==", "!=", "<=", ">=", "<", ">", "&&", "||", "!"].includes(token)) return "operator";
    return "identifier";
  }
  /**
   * Try to match multi-word phrases that function as single units.
   * Multi-word phrases are included in profileKeywords and sorted longest-first,
   * so they'll be matched before their constituent words.
   */
  tryMultiWordPhrase(input, pos) {
    for (const entry of this.profileKeywords) {
      if (!entry.native.includes(" ")) continue;
      const phrase = entry.native;
      const candidate = input.slice(pos, pos + phrase.length).toLowerCase();
      if (candidate === phrase.toLowerCase()) {
        const nextPos = pos + phrase.length;
        if (nextPos >= input.length || isWhitespace(input[nextPos]) || !isItalianLetter(input[nextPos])) {
          return createToken(
            input.slice(pos, pos + phrase.length),
            "keyword",
            createPosition(pos, nextPos),
            entry.normalized
          );
        }
      }
    }
    return null;
  }
  /**
   * Extract an Italian word.
   *
   * Uses morphological normalization to handle:
   * - Reflexive verbs (mostrarsi → mostrare)
   * - Verb conjugations (alternando → alternare)
   */
  extractItalianWord(input, startPos) {
    let pos = startPos;
    let word = "";
    while (pos < input.length && isItalianIdentifierChar(input[pos])) {
      word += input[pos++];
    }
    if (!word) return null;
    const lower = word.toLowerCase();
    if (PREPOSITIONS.has(lower)) {
      return createToken(word, "particle", createPosition(startPos, pos));
    }
    const keywordEntry = this.lookupKeyword(lower);
    if (keywordEntry) {
      return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
    }
    const morphToken = this.tryMorphKeywordMatch(lower, startPos, pos);
    if (morphToken) return morphToken;
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract a number, including Italian time unit suffixes.
   */
  extractItalianNumber(input, startPos) {
    return this.tryNumberWithTimeUnits(input, startPos, ITALIAN_TIME_UNITS, {
      allowSign: true,
      skipWhitespace: true
    });
  }
};
var italianTokenizer = new ItalianTokenizer();

// src/languages/it.ts
registerLanguage("it", italianTokenizer, italianProfile);
export {
  italianProfile,
  italianTokenizer
};
//# sourceMappingURL=it.js.map