@atscript/core 0.1.97 → 0.1.99

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.
package/dist/index.d.ts CHANGED
@@ -47,6 +47,8 @@ declare class Token {
47
47
  constructor(_data: TLexicalToken);
48
48
  toString(): string;
49
49
  clone(replace: Partial<TLexicalToken>): Token;
50
+ /** The underlying lexical token (for re-iterating its children). */
51
+ get lexicalToken(): TLexicalToken;
50
52
  get text(): string;
51
53
  get type(): "number" | "annotation" | "comment" | "punctuation" | "identifier" | "text" | "block" | "unknown" | "regexp" | "query";
52
54
  get range(): {
@@ -108,6 +110,16 @@ declare class Token {
108
110
  * Parsed query expression tree (for query-type annotation arguments)
109
111
  */
110
112
  queryNode?: SemanticQueryNode;
113
+ /** The parsed tree of a backtick argument — whichever of the three it was parsed as. */
114
+ get backtickNode(): SemanticQueryNode | SemanticExprNode | SemanticOrderNode | undefined;
115
+ /**
116
+ * Parsed arithmetic expression (for expr-type annotation arguments)
117
+ */
118
+ exprNode?: SemanticExprNode;
119
+ /**
120
+ * Parsed ordering (for order-type annotation arguments)
121
+ */
122
+ orderNode?: SemanticOrderNode;
111
123
  }
112
124
 
113
125
  interface TPluginManagers {
@@ -520,6 +532,21 @@ declare class AtscriptDoc {
520
532
  private _annotateNodesByTarget;
521
533
  get text(): string;
522
534
  update(text: string, debug?: boolean): void;
535
+ /** Lexical backtick tokens already parsed by `registerAnnotation`. */
536
+ private parsedBacktickArgs;
537
+ /**
538
+ * Backtick arguments of annotations that never get registered (dangling at
539
+ * EOF, or followed by a syntax error) are still parsed for diagnostics — by
540
+ * the argument spec of the preceding annotation when it resolves, else as a
541
+ * query predicate.
542
+ */
543
+ private parseUnregisteredBacktickArgs;
544
+ /**
545
+ * Parse a backtick argument by its spec type: `expr` / `order` get their own
546
+ * grammar; anything else (unknown annotation, position beyond the spec) parses
547
+ * as a query predicate.
548
+ */
549
+ private parseBacktickArgAs;
523
550
  cleanup(): void;
524
551
  private registerNodes;
525
552
  resolvedAnnotations: Token[];
@@ -745,7 +772,8 @@ declare class SemanticQueryNode extends SemanticNode {
745
772
  sourceToken: Token;
746
773
  constructor();
747
774
  registerAtDocument(doc: AtscriptDoc): void;
748
- private propagateQueryArgToken;
775
+ /** Every field ref of the predicate (both sides of comparisons), in source order. */
776
+ fieldRefs(): SemanticQueryFieldRefNode[];
749
777
  }
750
778
  declare class SemanticQueryLogicalNode extends SemanticNode {
751
779
  operator: TQueryLogicalOperator;
@@ -777,6 +805,54 @@ declare class SemanticQueryValueListNode extends SemanticNode {
777
805
  constructor();
778
806
  registerAtDocument(doc: AtscriptDoc): void;
779
807
  }
808
+ type TExprBinaryOperator = '+' | '-' | '*' | '/';
809
+ type SemanticExprItemNode = SemanticExprBinaryNode | SemanticExprUnaryNode | SemanticExprCallNode | SemanticExprNumberNode | SemanticQueryFieldRefNode;
810
+ /** Root of a parsed `expr` argument (closed arithmetic over field refs). */
811
+ declare class SemanticExprNode extends SemanticNode {
812
+ expression: SemanticExprItemNode;
813
+ sourceToken: Token;
814
+ constructor();
815
+ /** Every field-ref leaf of the expression, in source order. */
816
+ fieldRefs(): SemanticQueryFieldRefNode[];
817
+ registerAtDocument(doc: AtscriptDoc): void;
818
+ }
819
+ declare class SemanticExprBinaryNode extends SemanticNode {
820
+ op: TExprBinaryOperator;
821
+ left: SemanticExprItemNode;
822
+ right: SemanticExprItemNode;
823
+ constructor();
824
+ }
825
+ declare class SemanticExprUnaryNode extends SemanticNode {
826
+ op: "neg";
827
+ operand: SemanticExprItemNode;
828
+ constructor();
829
+ }
830
+ declare class SemanticExprCallNode extends SemanticNode {
831
+ fn: "coalesce";
832
+ args: SemanticExprItemNode[];
833
+ constructor();
834
+ }
835
+ declare class SemanticExprNumberNode extends SemanticNode {
836
+ valueToken: Token;
837
+ /** Numeric value (sign already applied when split from a signed number token). */
838
+ value: number;
839
+ constructor();
840
+ }
841
+ interface TOrderItem {
842
+ ref: SemanticQueryFieldRefNode;
843
+ desc: boolean;
844
+ /** The `asc` / `desc` keyword token, when written. */
845
+ dirToken?: Token;
846
+ }
847
+ /** Root of a parsed `order` argument: `key (asc|desc)?, …`. */
848
+ declare class SemanticOrderNode extends SemanticNode {
849
+ items: TOrderItem[];
850
+ sourceToken: Token;
851
+ constructor();
852
+ /** Every order key, in source order. */
853
+ fieldRefs(): SemanticQueryFieldRefNode[];
854
+ registerAtDocument(doc: AtscriptDoc): void;
855
+ }
780
856
 
781
857
  declare class SemanticArrayNode extends SemanticNode {
782
858
  constructor();
@@ -933,17 +1009,28 @@ interface TQueryScope {
933
1009
  */
934
1010
  unqualifiedTarget: string | null;
935
1011
  }
1012
+ /** Annotation argument types written in backticks, each parsed by its own grammar. */
1013
+ type TBacktickArgKind = 'query' | 'expr' | 'order';
1014
+ /** Whether an annotation argument type is written in backticks (`query`, `expr`, `order`). */
1015
+ declare function isBacktickArgType(type: string | undefined): type is TBacktickArgKind;
936
1016
  interface TAnnotationArgument {
937
1017
  optional?: boolean;
938
1018
  name: string;
939
- type: 'string' | 'number' | 'boolean' | 'ref' | 'query';
1019
+ /**
1020
+ * - `query`: backtick predicate (`status = 'open' and Issue.overdue = true`)
1021
+ * - `expr`: backtick arithmetic over field refs (`openCount * 10 + coalesce(overdue, 0)`):
1022
+ * `+ - * /`, unary `-`, parentheses, numeric literals, `coalesce(a, b, …)`
1023
+ * - `order`: backtick ordering (`raisedAt desc, id`): field refs with optional `asc` / `desc`
1024
+ */
1025
+ type: 'string' | 'number' | 'boolean' | 'ref' | TBacktickArgKind;
940
1026
  description?: string;
941
1027
  values?: string[];
942
1028
  /**
943
- * Editor field scope of a `query` or `string` argument. Called with the argument token
944
- * and the document that holds it; return `undefined` when the scope cannot be determined.
945
- * - `query`: the types the backtick expression may reference (drives completion, hover,
946
- * go-to-definition, find-references and rename of its field refs).
1029
+ * Editor field scope of a `query`, `expr`, `order` or `string` argument. Called with the
1030
+ * argument token and the document that holds it; return `undefined` when the scope cannot
1031
+ * be determined.
1032
+ * - `query` / `expr` / `order`: the types the backtick expression may reference (drives
1033
+ * completion, hover, go-to-definition, find-references and rename of its field refs).
947
1034
  * - `string`: the argument is a (dotted) field path of `unqualifiedTarget` (`'amount'`,
948
1035
  * `'address.city'`) — same editor features on the string; `allowedTypes` is unused.
949
1036
  */
@@ -1185,14 +1272,35 @@ type TQueryCursorContext = {
1185
1272
  type: 'after-operator';
1186
1273
  } | {
1187
1274
  type: 'after-comparison';
1275
+ }
1276
+ /** `expr`: after a field, a number or `)` — an arithmetic operator follows. */
1277
+ | {
1278
+ type: 'after-operand';
1279
+ }
1280
+ /** `order`: after an order key — `asc`, `desc` or `,` follows. */
1281
+ | {
1282
+ type: 'after-order-key';
1283
+ }
1284
+ /** `order`: after `asc` / `desc` — `,` follows. */
1285
+ | {
1286
+ type: 'after-order-direction';
1188
1287
  };
1189
1288
  /**
1190
1289
  * Analyze text inside backticks up to cursor position
1191
1290
  * to determine what kind of completions to offer.
1192
1291
  * Uses lightweight text scanning, not full AST parsing,
1193
1292
  * so it works on incomplete/mid-typing input.
1293
+ *
1294
+ * `mode` selects the grammar of the argument (default `query`).
1194
1295
  */
1195
- declare function analyzeQueryCursorContext(textBeforeCursor: string): TQueryCursorContext;
1296
+ declare function analyzeQueryCursorContext(textBeforeCursor: string, mode?: TBacktickArgKind): TQueryCursorContext;
1297
+
1298
+ /** Vocabulary of `expr` / `order` arguments: arithmetic operators, functions, order directions. */
1299
+ declare const BACKTICK_ARG_VOCABULARY: {
1300
+ readonly arithmeticOps: readonly ["+", "-", "*", "/"];
1301
+ readonly functions: readonly ["coalesce"];
1302
+ readonly orderDirections: readonly ["asc", "desc"];
1303
+ };
1196
1304
 
1197
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1198
- export type { SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TDbConfig, TDbConfigDeclarative, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken };
1305
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1306
+ export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TBacktickArgKind, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken };