HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/node_modules/chevrotain/src/parse/cst/cst.ts
import { CstNode, CstNodeLocation, IToken } from "../../../api"

/**
 * This nodeLocation tracking is not efficient and should only be used
 * when error recovery is enabled or the Token Vector contains virtual Tokens
 * (e.g, Python Indent/Outdent)
 * As it executes the calculation for every single terminal/nonTerminal
 * and does not rely on the fact the token vector is **sorted**
 */
export function setNodeLocationOnlyOffset(
  currNodeLocation: CstNodeLocation,
  newLocationInfo: IToken
): void {
  // First (valid) update for this cst node
  if (isNaN(currNodeLocation.startOffset) === true) {
    // assumption1: Token location information is either NaN or a valid number
    // assumption2: Token location information is fully valid if it exist
    // (both start/end offsets exist and are numbers).
    currNodeLocation.startOffset = newLocationInfo.startOffset
    currNodeLocation.endOffset = newLocationInfo.endOffset
  }
  // Once the startOffset has been updated with a valid number it should never receive
  // any farther updates as the Token vector is sorted.
  // We still have to check this this condition for every new possible location info
  // because with error recovery enabled we may encounter invalid tokens (NaN location props)
  else if (currNodeLocation.endOffset < newLocationInfo.endOffset === true) {
    currNodeLocation.endOffset = newLocationInfo.endOffset
  }
}

/**
 * This nodeLocation tracking is not efficient and should only be used
 * when error recovery is enabled or the Token Vector contains virtual Tokens
 * (e.g, Python Indent/Outdent)
 * As it executes the calculation for every single terminal/nonTerminal
 * and does not rely on the fact the token vector is **sorted**
 */
export function setNodeLocationFull(
  currNodeLocation: CstNodeLocation,
  newLocationInfo: CstNodeLocation
): void {
  // First (valid) update for this cst node
  if (isNaN(currNodeLocation.startOffset) === true) {
    // assumption1: Token location information is either NaN or a valid number
    // assumption2: Token location information is fully valid if it exist
    // (all start/end props exist and are numbers).
    currNodeLocation.startOffset = newLocationInfo.startOffset
    currNodeLocation.startColumn = newLocationInfo.startColumn
    currNodeLocation.startLine = newLocationInfo.startLine
    currNodeLocation.endOffset = newLocationInfo.endOffset
    currNodeLocation.endColumn = newLocationInfo.endColumn
    currNodeLocation.endLine = newLocationInfo.endLine
  }
  // Once the start props has been updated with a valid number it should never receive
  // any farther updates as the Token vector is sorted.
  // We still have to check this this condition for every new possible location info
  // because with error recovery enabled we may encounter invalid tokens (NaN location props)
  else if (currNodeLocation.endOffset < newLocationInfo.endOffset === true) {
    currNodeLocation.endOffset = newLocationInfo.endOffset
    currNodeLocation.endColumn = newLocationInfo.endColumn
    currNodeLocation.endLine = newLocationInfo.endLine
  }
}

export function addTerminalToCst(
  node: CstNode,
  token: IToken,
  tokenTypeName: string
): void {
  if (node.children[tokenTypeName] === undefined) {
    node.children[tokenTypeName] = [token]
  } else {
    node.children[tokenTypeName].push(token)
  }
}

export function addNoneTerminalToCst(
  node: CstNode,
  ruleName: string,
  ruleResult: any
): void {
  if (node.children[ruleName] === undefined) {
    node.children[ruleName] = [ruleResult]
  } else {
    node.children[ruleName].push(ruleResult)
  }
}