How to use the @argdown/core.isRuleNode function in @argdown/core

To help you get started, we’ve selected a few @argdown/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github christianvoigt / argdown / packages / argdown-language-server / src / providers / findNodesContainingPosition.ts View on Github external
.filter(n => {
      // Indent and Dedent are pseudo tokens that mess up the search because of their location information
      return (
        isRuleNode(n) ||
        (n.tokenType!.name !== TokenNames.INDENT &&
          n.tokenType!.name !== TokenNames.DEDENT)
      );
    })
    .filter(n => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findNodesContainingPosition.js View on Github external
.filter(n => {
        // Indent and Dedent are pseudo tokens that mess up the search because of their location information
        return (core_1.isRuleNode(n) ||
            (n.tokenType.tokenName !== core_1.TokenNames.INDENT &&
                n.tokenType.tokenName !== core_1.TokenNames.DEDENT));
    })
        .filter(n => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findNodesContainingPosition.js View on Github external
// acc & val start at the same line
            if (acc.startLine === line) {
                const valCharDistance = character - val.startColumn;
                const accCharDist = character - acc.startColumn;
                return valCharDistance < accCharDist && valCharDistance >= 0
                    ? val
                    : acc;
            }
            else {
                return val.startColumn > acc.startColumn ? val : acc;
            }
        }
    }, undefined);
    if (closestNode) {
        result.push(closestNode);
        if (core_1.isRuleNode(closestNode) &&
            closestNode.children &&
            closestNode.children.length > 0) {
            result.push(...exports.findNodesContainingPosition(closestNode.children, line, character));
        }
    }
    return result;
};
//# sourceMappingURL=findNodesContainingPosition.js.map
github christianvoigt / argdown / packages / argdown-language-server / src / providers / findNodesContainingPosition.ts View on Github external
// acc & val start at the same line
        if (acc.startLine === line) {
          const valCharDistance = character - val.startColumn!;
          const accCharDist = character - acc.startColumn!;
          return valCharDistance < accCharDist && valCharDistance >= 0
            ? val
            : acc;
        } else {
          return val.startColumn! > acc.startColumn! ? val : acc;
        }
      }
    }, undefined);
  if (closestNode) {
    result.push(closestNode);
    if (
      isRuleNode(closestNode) &&
      closestNode.children &&
      closestNode.children.length > 0
    ) {
      result.push(
        ...findNodesContainingPosition(closestNode.children, line, character)
      );
    }
  }
  return result;
};
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / utils.js View on Github external
exports.walkTree = (node, parentNode, childIndex, callback) => {
    callback(node, parentNode, childIndex);
    if (core_1.isRuleNode(node) && node.children && node.children.length > 0) {
        for (var i = 0; i < node.children.length; i++) {
            let child = node.children[i];
            exports.walkTree(child, node, i, callback);
        }
    }
};
//# sourceMappingURL=utils.js.map
github christianvoigt / argdown / packages / argdown-language-server / src / providers / utils.ts View on Github external
export const walkTree = (
  node: IAstNode,
  parentNode: any,
  childIndex: number,
  callback: (node: any, parentNode: any, childIndex: number) => void
) => {
  if (node) {
    callback(node, parentNode, childIndex);
    if (isRuleNode(node) && node.children && node.children.length > 0) {
      for (var i = 0; i < node.children.length; i++) {
        let child = node.children[i];
        walkTree(child, node, i, callback);
      }
    }
  }
};
github christianvoigt / argdown / packages / argdown-language-server / src / providers / DocumentSymbolPlugin.ts View on Github external
[RuleNames.PCS_STATEMENT + "Entry"]: (_request, _response, node) => {
        const symbol = {} as ArgdownSymbol;
        symbol.name = `(${node.statementNr}) [${node.statement!.title}]`;
        symbol.range = getRange(node);
        const firstChild =
          node.children && node.children.length > 0 ? node.children[0] : null;
        if (
          firstChild &&
          isRuleNode(firstChild) &&
          (firstChild.name === RuleNames.STATEMENT_DEFINITION ||
            firstChild.name === RuleNames.STATEMENT_REFERENCE)
        ) {
          symbol.selectionRange = getRange(firstChild);
        } else {
          symbol.selectionRange = symbol.range;
        }
        symbol.kind = SymbolKind.Variable;
        parentsStack.push(symbol);
      },
      [RuleNames.PCS_STATEMENT + "Exit"]: (_request, response) => {
github christianvoigt / argdown / packages / argdown-language-server / src / providers / DocumentSymbolPlugin.ts View on Github external
symbol.kind = SymbolKind.Variable;
  symbol.range = getRange(node);
  symbol.selectionRange = symbol.range;
  let relationMemberTitle = "";
  if (node.children && node.children.length > 1) {
    const secondChild = node.children![1];
    const firstGrandChild =
      isRuleNode(secondChild) &&
      secondChild.children &&
      secondChild.children.length > 0
        ? secondChild.children[0]
        : null;
    if (firstGrandChild) {
      symbol.selectionRange = getRange(firstGrandChild);
    }
    if (isRuleNode(secondChild)) {
      if (secondChild.argument) {
        relationMemberTitle = `<${secondChild.argument.title}>`;
      } else if (secondChild.statement) {
        relationMemberTitle = `[${secondChild.statement!.title}]`;
      }
    }
  }
  symbol.name = `${relationSymbol} ${relationMemberTitle}`;
  parentsStack.push(symbol);
};
const onRelationExit = (
github christianvoigt / argdown / packages / argdown-language-server / src / providers / DocumentSymbolPlugin.ts View on Github external
const onRelationEntry = (
  parentsStack: ArgdownSymbol[],
  node: IRuleNode,
  relationSymbol: string
) => {
  const symbol = {} as ArgdownSymbol;
  symbol.kind = SymbolKind.Variable;
  symbol.range = getRange(node);
  symbol.selectionRange = symbol.range;
  let relationMemberTitle = "";
  if (node.children && node.children.length > 1) {
    const secondChild = node.children![1];
    const firstGrandChild =
      isRuleNode(secondChild) &&
      secondChild.children &&
      secondChild.children.length > 0
        ? secondChild.children[0]
        : null;
    if (firstGrandChild) {
      symbol.selectionRange = getRange(firstGrandChild);
    }
    if (isRuleNode(secondChild)) {
      if (secondChild.argument) {
        relationMemberTitle = `<${secondChild.argument.title}>`;
      } else if (secondChild.statement) {
        relationMemberTitle = `[${secondChild.statement!.title}]`;
      }
    }
  }
  symbol.name = `${relationSymbol} ${relationMemberTitle}`;