@malloydata/malloy 0.0.22-dev230117223957 → 0.0.22-dev230119001546

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,7 +1,8 @@
1
1
  import * as model from "../../model/malloy_types";
2
+ import { AtomicFieldType, ExpressionType, FieldTypeDef, Fragment, TimeFieldType, TimestampUnit } from "../../model/malloy_types";
2
3
  import { FieldSpace, QuerySpace, LookupResult } from "../field-space";
3
4
  import { MalloyTranslation, ModelDataRequest } from "../parse-malloy";
4
- import { ConstantSubExpression, ExpressionDef, FieldDeclaration } from "./index";
5
+ import { Comparison, ExprValue } from "./ast-types";
5
6
  export declare class ErrorFactory {
6
7
  static get structDef(): model.StructDef;
7
8
  static isErrorStructDef(s: model.StructDef): boolean;
@@ -518,4 +519,143 @@ export declare class SampleProperty extends MalloyElement {
518
519
  constructor(sample: model.Sampling);
519
520
  sampling(): model.Sampling;
520
521
  }
522
+ /**
523
+ * Root node for any element in an expression. These essentially
524
+ * create a sub-tree in the larger AST. Expression nodes know
525
+ * how to write themselves as SQL (or rather, generate the
526
+ * template for SQL required by the query writer)
527
+ */
528
+ export declare abstract class ExpressionDef extends MalloyElement {
529
+ abstract elementType: string;
530
+ granular(): boolean;
531
+ /**
532
+ * Returns the "translation" or template for SQL generation. When asking
533
+ * for a tranlsation you may pass the types you can accept, allowing
534
+ * the translation code a chance to convert to match your expectations
535
+ * @param space Namespace for looking up field references
536
+ */
537
+ abstract getExpression(fs: FieldSpace): ExprValue;
538
+ legalChildTypes: import("./ast-types").FragType[];
539
+ /**
540
+ * Some operators want to give the right hand value a chance to
541
+ * rewrite itself. This requests a translation for a rewrite,
542
+ * or returns undefined if that request should be denied.
543
+ * @param fs FieldSpace
544
+ * @returns Translated expression or undefined
545
+ */
546
+ requestExpression(fs: FieldSpace): ExprValue | undefined;
547
+ defaultFieldName(): string | undefined;
548
+ /**
549
+ * Check an expression for type compatibility
550
+ * @param _eNode currently unused, will be used to get error location
551
+ * @param eVal ...list of expressions that must match legalChildTypes
552
+ */
553
+ typeCheck(eNode: ExpressionDef, eVal: ExprValue): boolean;
554
+ /**
555
+ * This is the operation which makes partial comparison and value trees work
556
+ * The default implemention merely constructs LEFT OP RIGHT, but specialized
557
+ * nodes like alternation trees or or partial comparison can control how
558
+ * the appplication gets generated
559
+ * @param fs The symbol table
560
+ * @param op The operator being applied
561
+ * @param expr The "other" (besdies 'this') value
562
+ * @returns The translated expression
563
+ */
564
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
565
+ }
566
+ export declare class ConstantSubExpression extends ExpressionDef {
567
+ readonly expr: ExpressionDef;
568
+ elementType: string;
569
+ private cfs?;
570
+ constructor(expr: ExpressionDef);
571
+ getExpression(_fs: FieldSpace): ExprValue;
572
+ private get constantFs();
573
+ constantValue(): ExprValue;
574
+ constantCondition(type: AtomicFieldType): ExprValue;
575
+ apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
576
+ requestExpression(fs: FieldSpace): ExprValue | undefined;
577
+ }
578
+ export declare class FieldDeclaration extends MalloyElement {
579
+ readonly expr: ExpressionDef;
580
+ readonly defineName: string;
581
+ readonly exprSrc?: string | undefined;
582
+ elementType: string;
583
+ isMeasure?: boolean;
584
+ constructor(expr: ExpressionDef, defineName: string, exprSrc?: string | undefined);
585
+ fieldDef(fs: FieldSpace, exprName: string): FieldTypeDef;
586
+ queryFieldDef(exprFS: FieldSpace, exprName: string): FieldTypeDef;
587
+ }
588
+ /**
589
+ * All of the magic of malloy expressions eventually flows to here,
590
+ * where an operator is applied to two values. Depending on the
591
+ * operator and value types this may involve transformations of
592
+ * the values or even the operator.
593
+ * @param fs FieldSpace for the symbols
594
+ * @param left Left value
595
+ * @param op The operator
596
+ * @param right Right Value
597
+ * @returns ExprValue of the expression
598
+ */
599
+ export declare function applyBinary(fs: FieldSpace, left: ExpressionDef, op: string, right: ExpressionDef): ExprValue;
600
+ export declare abstract class BinaryBoolean<opType extends string> extends ExpressionDef {
601
+ readonly left: ExpressionDef;
602
+ readonly op: opType;
603
+ readonly right: ExpressionDef;
604
+ elementType: string;
605
+ legalChildTypes: import("./ast-types").FragType[];
606
+ constructor(left: ExpressionDef, op: opType, right: ExpressionDef);
607
+ getExpression(fs: FieldSpace): ExprValue;
608
+ }
609
+ export declare class ExprCompare extends BinaryBoolean<Comparison> {
610
+ elementType: string;
611
+ constructor(left: ExpressionDef, op: Comparison, right: ExpressionDef);
612
+ getExpression(fs: FieldSpace): ExprValue;
613
+ }
614
+ /**
615
+ * GranularTime is a moment in time which ALSO has a "granularity"
616
+ * commonly this are created by applying ".datePart" to an expression
617
+ * 1) They have a value, which is the moment in time
618
+ * 2) When used in a comparison, they act like a range, for the
619
+ * duration of 1 unit of granularity
620
+ */
621
+ export declare class ExprGranularTime extends ExpressionDef {
622
+ readonly expr: ExpressionDef;
623
+ readonly units: TimestampUnit;
624
+ readonly truncate: boolean;
625
+ elementType: string;
626
+ legalChildTypes: import("./ast-types").FragType[];
627
+ constructor(expr: ExpressionDef, units: TimestampUnit, truncate: boolean);
628
+ granular(): boolean;
629
+ getExpression(fs: FieldSpace): ExprValue;
630
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
631
+ protected timestampRange(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
632
+ protected dateRange(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
633
+ }
634
+ export declare class TypeMistmatch extends Error {
635
+ }
636
+ export declare class ExprDuration extends ExpressionDef {
637
+ readonly n: ExpressionDef;
638
+ readonly timeframe: TimestampUnit;
639
+ elementType: string;
640
+ legalChildTypes: import("./ast-types").FragType[];
641
+ constructor(n: ExpressionDef, timeframe: TimestampUnit);
642
+ apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
643
+ getExpression(_fs: FieldSpace): ExprValue;
644
+ }
645
+ export declare class ExprTime extends ExpressionDef {
646
+ elementType: string;
647
+ readonly translationValue: ExprValue;
648
+ constructor(timeType: TimeFieldType, value: Fragment[] | string, expressionType?: ExpressionType);
649
+ getExpression(_fs: FieldSpace): ExprValue;
650
+ static fromValue(timeType: TimeFieldType, expr: ExprValue): ExprTime;
651
+ }
652
+ export declare class Range extends ExpressionDef {
653
+ readonly first: ExpressionDef;
654
+ readonly last: ExpressionDef;
655
+ elementType: string;
656
+ constructor(first: ExpressionDef, last: ExpressionDef);
657
+ apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
658
+ requestExpression(_fs: FieldSpace): ExprValue | undefined;
659
+ getExpression(_fs: FieldSpace): ExprValue;
660
+ }
521
661
  export {};