@spyglassmc/mcfunction 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
1
  import * as core from '@spyglassmc/core';
2
+ import type { CommandMacroNode } from '../node/index.js';
2
3
  export declare function register(meta: core.MetaRegistry): void;
4
+ export declare const macro: core.Colorizer<CommandMacroNode>;
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,10 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  export function register(meta) {
3
+ meta.registerColorizer('mcfunction:command_macro', macro);
3
4
  meta.registerColorizer('mcfunction:command_child/literal', core.colorizer.literal);
4
5
  meta.registerColorizer('mcfunction:command_child/trailing', core.colorizer.error);
5
6
  }
7
+ export const macro = (node, ctx) => {
8
+ return [core.ColorToken.create(node, 'string')];
9
+ };
6
10
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@ import * as core from '@spyglassmc/core';
2
2
  import type { McfunctionNode } from '../node/index.js';
3
3
  import { CommandNode } from '../node/index.js';
4
4
  import type { ArgumentTreeNode, RootTreeNode } from '../tree/index.js';
5
- export declare type MockNodesGetter = (treeNode: ArgumentTreeNode, range: core.RangeLike) => core.Arrayable<core.AstNode>;
5
+ export type MockNodesGetter = (treeNode: ArgumentTreeNode, range: core.RangeLike) => core.Arrayable<core.AstNode>;
6
6
  /**
7
7
  * @param getMockNodes A function that returns a mock AST Node from given {@link ArgumentTreeNode}. These mock nodes
8
8
  * will be used for completing the argument.
@@ -1,4 +1,5 @@
1
1
  import * as core from '@spyglassmc/core';
2
+ import { CommandMacroNode } from '../node/index.js';
2
3
  import { CommandNode } from '../node/index.js';
3
4
  import { categorizeTreeChildren, CommandTreeRegistry, redirect, resolveParentTreeNode, } from '../tree/index.js';
4
5
  /**
@@ -9,7 +10,7 @@ export function entry(commandTreeName, getMockNodes) {
9
10
  return (node, ctx) => {
10
11
  const tree = CommandTreeRegistry.instance.get(commandTreeName);
11
12
  const childNode = core.AstNode.findChild(node, ctx.offset, true);
12
- if (core.CommentNode.is(childNode)) {
13
+ if (core.CommentNode.is(childNode) || CommandMacroNode.is(childNode)) {
13
14
  return [];
14
15
  }
15
16
  else {
@@ -7,6 +7,12 @@ export declare namespace CommandNode {
7
7
  function is(node: core.AstNode): node is CommandNode;
8
8
  function mock(range: core.RangeLike): CommandNode;
9
9
  }
10
+ export interface CommandMacroNode extends core.AstNode {
11
+ type: 'mcfunction:command_macro';
12
+ }
13
+ export declare namespace CommandMacroNode {
14
+ function is<T extends core.DeepReadonly<core.AstNode> | undefined>(obj: T): obj is core.InheritReadonly<CommandMacroNode, T>;
15
+ }
10
16
  export interface CommandChildNode extends core.AstNode {
11
17
  type: 'mcfunction:command_child';
12
18
  /**
@@ -15,6 +15,14 @@ export var CommandNode;
15
15
  }
16
16
  CommandNode.mock = mock;
17
17
  })(CommandNode || (CommandNode = {}));
18
+ export var CommandMacroNode;
19
+ (function (CommandMacroNode) {
20
+ function is(obj) {
21
+ return obj?.type ===
22
+ 'mcfunction:command_macro';
23
+ }
24
+ CommandMacroNode.is = is;
25
+ })(CommandMacroNode || (CommandMacroNode = {}));
18
26
  export var CommandChildNode;
19
27
  (function (CommandChildNode) {
20
28
  function is(node) {
@@ -1,6 +1,6 @@
1
1
  import type * as core from '@spyglassmc/core';
2
- import type { CommandNode } from './command.js';
3
- export interface McfunctionNode extends core.SequenceNode<CommandNode | core.CommentNode> {
2
+ import type { CommandMacroNode, CommandNode } from './command.js';
3
+ export interface McfunctionNode extends core.SequenceNode<CommandNode | CommandMacroNode | core.CommentNode> {
4
4
  type: 'mcfunction:entry';
5
5
  }
6
6
  export declare namespace McfunctionNode {
@@ -7,6 +7,6 @@ import type { ArgumentTreeNode } from '../tree/index.js';
7
7
  *
8
8
  * @returns The parser corresponding to that tree node, or `undefined` if such parser doesn't exist.
9
9
  */
10
- export declare type ArgumentParserGetter = (treeNode: ArgumentTreeNode) => core.Parser | undefined;
10
+ export type ArgumentParserGetter = (treeNode: ArgumentTreeNode) => core.Parser | undefined;
11
11
  export declare function argumentTreeNodeToString(name: string, treeNode: ArgumentTreeNode): string;
12
12
  //# sourceMappingURL=argument.d.ts.map
@@ -16,6 +16,14 @@ export function entry(commandTreeName, argument) {
16
16
  if (src.peek() === '#') {
17
17
  result = comment(src, ctx);
18
18
  }
19
+ else if (src.peek() === '$') {
20
+ const start = src.cursor;
21
+ src.skipLine();
22
+ result = {
23
+ type: 'mcfunction:command_macro',
24
+ range: core.Range.create(start, src),
25
+ };
26
+ }
19
27
  else {
20
28
  result = command(CommandTreeRegistry.instance.get(commandTreeName), argument)(src, ctx);
21
29
  }
@@ -22,11 +22,11 @@ export interface LiteralTreeNode extends BaseTreeNode {
22
22
  export interface RootTreeNode extends BaseTreeNode {
23
23
  type: 'root';
24
24
  }
25
- export declare type TreeNode = ArgumentTreeNode | LiteralTreeNode | RootTreeNode;
26
- declare type RecursivePartial<T> = T extends object ? {
25
+ export type TreeNode = ArgumentTreeNode | LiteralTreeNode | RootTreeNode;
26
+ type RecursivePartial<T> = T extends object ? {
27
27
  [K in keyof T]?: RecursivePartial<T[K]>;
28
28
  } : T;
29
- export declare type PartialTreeNode = RecursivePartial<TreeNode>;
30
- export declare type PartialRootTreeNode = RecursivePartial<RootTreeNode>;
29
+ export type PartialTreeNode = RecursivePartial<TreeNode>;
30
+ export type PartialRootTreeNode = RecursivePartial<RootTreeNode>;
31
31
  export {};
32
32
  //# sourceMappingURL=type.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcfunction",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@spyglassmc/core": "0.4.1",
29
- "@spyglassmc/locales": "0.3.1"
28
+ "@spyglassmc/core": "0.4.3",
29
+ "@spyglassmc/locales": "0.3.3"
30
30
  }
31
31
  }