@hamelin.sh/compiler 0.2.3-prerelease.20250910T133135 → 0.2.3

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/main.d.ts CHANGED
@@ -2927,6 +2927,8 @@ declare class HamelinListener implements ParseTreeListener {
2927
2927
  exitEveryRule(node: ParserRuleContext): void;
2928
2928
  }
2929
2929
 
2930
+ declare const hamelinGrammar = "grammar Hamelin;\n\nqueryEOF\n : query EOF\n ;\n\ncommandEOF\n : command EOF\n ;\n\nexpressionEOF\n : expression EOF\n ;\n\nidentifierEOF\n : identifier EOF\n ;\n\nsimpleIdentifierEOF\n : simpleIdentifier EOF\n ;\n\nquery\n : (WITH simpleIdentifier ASSIGN pipeline)+ pipeline #withQuery\n | pipeline #standaloneQuery\n | expression #expressionQuery\n ;\n\npipeline\n : command ( PIPE command )* #pipelineAlt\n ;\n\ncommand\n : LET_COMMAND assignment (COMMA assignment)* COMMA? #letCommand\n | WHERE_COMMAND expression #whereCommand\n | SELECT_COMMAND assignmentClause (COMMA assignmentClause)* COMMA? #selectCommand\n | DROP_COMMAND selection (COMMA selection)* COMMA? #dropCommand\n | FROM_COMMAND fromClause (COMMA fromClause)* COMMA? #fromCommand\n | UNION_COMMAND fromClause (COMMA fromClause)* COMMA? #unionCommand\n | LIMIT_COMMAND expression #limitCommand\n | PARSE_COMMAND src=expression? string\n AS? identifier (COMMA identifier)* COMMA? NODROP? #parseCommand\n | WITHIN_COMMAND expression #withinCommand\n | AGG_COMMAND (assignmentClause (COMMA assignmentClause)*)? COMMA?\n (BY groupClause (COMMA groupClause)*)? COMMA?\n (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA? #aggCommand\n | SORT BY? sortExpression (COMMA sortExpression)* COMMA? #sortCommand\n | WINDOW_COMMAND assignmentClause (COMMA assignmentClause)* COMMA?\n (BY groupClause (COMMA groupClause)*)? COMMA?\n (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA?\n (WITHIN_COMMAND within=expression)? #windowCommand\n | APPEND_COMMAND tableReference (DISTINCT_BY selection (COMMA selection)*)? COMMA? #appendCommand\n | (JOIN_COMMAND | LOOKUP_COMMAND) fromClause (ON on=expression)? #joinCommand\n | EXPLODE_COMMAND assignmentClause #explodeCommand\n | (UNNEST_COMMAND | ROWS_COMMAND) expression #unnestCommand\n | NEST_COMMAND identifier #nestCommand\n | MATCH_COMMAND pattern+\n (WHEN matchDefine (COMMA matchDefine)*)? COMMA?\n (BY groupClause (COMMA groupClause)*)? COMMA?\n (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA? #matchCommand\n ;\n\nassignmentClause: assignment | expression;\ngroupClause: assignmentClause;\nassignment: identifier ASSIGN expression;\nmatchDefine: simpleIdentifier ASSIGN expression;\nselection: identifier;\nsortExpression: expression (ASC | DESC)?;\ntableAlias: simpleIdentifier ASSIGN tableReference;\nfromClause: tableAlias | tableReference;\n\nexpression\n // Keep this list in precedence order (important!)\n : operator=(MINUS | PLUS) expression #unaryPrefixOperator\n | expression (SECOND_TRUNC | MINUTE_TRUNC | HOUR_TRUNC | DAY_TRUNC | WEEK_TRUNC |\n MONTH_TRUNC | QUARTER_TRUNC | YEAR_TRUNC) #tsTrunc\n | left=expression operator=DOT right=simpleIdentifier #deref\n | value=expression LBRACKET index=expression RBRACKET #indexAccess\n | left=expression operator=(ASTERISK | SLASH | PERCENT) right=expression #binaryOperator\n | left=expression operator=(PLUS | MINUS) right=expression #binaryOperator\n | operator=RANGE expression #unaryPrefixOperator\n | expression operator=RANGE #unaryPostfixOperator\n | left=expression operator=RANGE right=expression #binaryOperator\n | left=expression operator=AS right=hamelintype #cast\n | left=expression\n operator=(EQ | NEQ | LT | LTE | GT | GTE | IS | ISNOT | IN) right=expression #binaryOperator\n | operator=NOT expression #unaryPrefixOperator\n | left=expression operator=AND right=expression #binaryOperator\n | left=expression operator=OR right=expression #binaryOperator\n\n // Complex Literals\n | left=expression operator=COLON right=expression #pairLiteral\n | LCURLY simpleIdentifier COLON expression\n (COMMA simpleIdentifier COLON expression)* COMMA? RCURLY #structLiteral\n | LPARENS ((expression COMMA) |\n (expression COMMA expression (COMMA expression)* COMMA?)) RPARENS #tupleLiteral\n | LBRACKET (expression (COMMA expression)* COMMA?)? RBRACKET #arrayLiteral\n\n // Function Calls\n | functionName=simpleIdentifier\n LPARENS (namedArgument (COMMA namedArgument)* COMMA?)? RPARENS #functionCall\n | functionName=simpleIdentifier LPARENS\n positionalArgument (COMMA positionalArgument)*\n (COMMA namedArgument)* COMMA? RPARENS #functionCall\n\n // Primitive Literals\n | NULL #nullLiteral\n | number #numericLiteral\n | TRUE #booleanLiteral\n | FALSE #booleanLiteral\n | string #stringLiteral\n | BINARY_LITERAL #binaryLiteral\n | RANGE #unboundRangeLiteral\n | (NANOSECOND_INTERVAL | MICROSECOND_INTERVAL | MILLISECOND_INTERVAL |\n SECOND_INTERVAL | MINUTE_INTERVAL | HOUR_INTERVAL | DAY_INTERVAL |\n WEEK_INTERVAL | MONTH_INTERVAL | QUARTER_INTERVAL | YEAR_INTERVAL) #intervalLiteral\n | ROWS_LITERAL #rowsLiteral\n | (SECOND_TRUNC | MINUTE_TRUNC | HOUR_TRUNC | DAY_TRUNC | WEEK_TRUNC |\n MONTH_TRUNC | QUARTER_TRUNC | YEAR_TRUNC) #tsTruncTimestampLiteral\n\n // Environment references\n | columnReference #columnReferenceAlt\n\n // Keep this at the bottom to use it the mechanism that query authors have to specify precedence.\n | LPARENS expression RPARENS #parenthesizedExpression\n ;\n\nhamelintype\n : simpleIdentifier LPARENS hamelintype (COMMA hamelintype)* COMMA? RPARENS #parameterizedType\n | simpleIdentifier LPARENS INTEGER_VALUE (COMMA INTEGER_VALUE)* COMMA? RPARENS #typeWithArguments\n | LCURLY simpleIdentifier COLON hamelintype\n (COMMA simpleIdentifier COLON hamelintype)* COMMA? RCURLY #structType\n | LPARENS hamelintype (COMMA hamelintype )* COMMA? RPARENS #tupleType\n | simpleIdentifier #simpleType\n ;\n\npattern\n : fromClause quantifier? #quantified\n | LPARENS pattern+ RPARENS quantifier #nested\n ;\n\nquantifier\n : ASTERISK #AnyNumber\n | PLUS #AtLeastOne\n | QUESTIONMARK #ZeroOrOne\n | LCURLY INTEGER_VALUE RCURLY #Exactly\n ;\n\ncolumnReference\n : simpleIdentifier\n ;\n\ntableReference\n : identifier\n ;\n\nidentifier\n : simpleIdentifier\n | simpleIdentifier (DOT simpleIdentifier)+\n ;\n\nsimpleIdentifier\n : IDENTIFIER #unquotedIdentifier\n | BACKQUOTED_IDENTIFIER #backQuotedIdentifier\n ;\n\nstring\n : SINGLE_QUOTED_STRING #basicSingleQuotedStringLiteral\n | DOUBLE_QUOTED_STRING #basicDoubleQuotedStringLiteral\n | value=SINGLE_QUOTED_UNICODE_STRING (UESCAPE uesc=SINGLE_QUOTED_STRING)? #unicodeSingleQuotedStringLiteral\n | value=DOUBLE_QUOTED_UNICODE_STRING (UESCAPE uesc=DOUBLE_QUOTED_STRING)? #unicodeDoubleQuotedStringLiteral\n ;\n\nnumber\n : value=DECIMAL_VALUE #decimalLiteral\n | value=DOUBLE_VALUE #scientificLiteral\n | value=INTEGER_VALUE #integerLiteral\n ;\n\npositionalArgument\n : expression\n ;\n\nnamedArgument\n : simpleIdentifier ASSIGN expression\n ;\n\n//\n// COMMANDS\n//\n\nLET_COMMAND: 'LET' | 'let';\nWHERE_COMMAND: 'WHERE' | 'where';\nSELECT_COMMAND: 'SELECT' | 'select';\nDROP_COMMAND: 'DROP' | 'drop';\nFROM_COMMAND: 'FROM' | 'from';\nUNION_COMMAND: 'UNION' | 'union';\nLIMIT_COMMAND: 'LIMIT' | 'limit';\nPARSE_COMMAND: 'PARSE' | 'parse';\nWITHIN_COMMAND: 'WITHIN' | 'within';\nAGG_COMMAND: 'AGG' | 'agg';\nWINDOW_COMMAND: 'WINDOW' | 'window';\nAPPEND_COMMAND: 'APPEND' | 'append';\nJOIN_COMMAND: 'JOIN' | 'join';\nLOOKUP_COMMAND: 'LOOKUP' | 'lookup';\nEXPLODE_COMMAND: 'EXPLODE' | 'explode';\nUNNEST_COMMAND: 'UNNEST' | 'unnest';\nNEST_COMMAND: 'NEST' | 'nest';\nROWS_COMMAND: 'ROWS' | 'rows';\nMATCH_COMMAND: 'MATCH' | 'match';\n\nAS: 'AS' | 'as';\nNODROP: 'NODROP' | 'nodrop';\n\n//\n// Operators\n//\n\nPLUS: '+';\nMINUS: '-';\nASTERISK: '*';\nSLASH: '/';\nPERCENT: '%';\nLCURLY: '{';\nRCURLY: '}';\nCOLON: ':';\nQUESTIONMARK: '?';\n\nEQ: '==';\nNEQ: '!=';\nLT: '<';\nLTE: '<=';\nGT: '>';\nGTE: '>=';\nRANGE: '..';\n\nASSIGN: '=';\n\n//\n// Keywords\n//\n\nAND: 'AND' | 'and';\nFALSE: 'FALSE' | 'false';\nIS: 'IS' | 'is';\nNOT: 'NOT' | 'not';\nISNOT: 'IS NOT' | 'is not';\nIN: 'IN' | 'in';\nNULL: 'NULL' | 'null';\nOR: 'OR' | 'or';\nTRUE: 'TRUE' | 'true';\nUESCAPE: 'UESCAPE' | 'uescape';\nWITH: 'WITH' | 'with';\nBY: 'BY' | 'by';\nSORT: 'SORT' | 'sort';\nASC: 'ASC' | 'asc';\nDESC: 'DESC' | 'desc';\nDISTINCT_BY: 'DISTINCT BY' | 'distinct by';\nON: 'ON' | 'on';\nWHEN: 'WHEN' | 'when';\n\n//\n// Symbols\n//\n\nCOMMA: ',';\nPIPE: '|';\nLPARENS: '(';\nRPARENS: ')';\nDOT: '.';\nLBRACKET: '[';\nRBRACKET: ']';\n\n//\n// Literals\n//\n\nSINGLE_QUOTED_STRING\n : '\\'' ( ~'\\'' | '\\'\\'')* '\\''\n ;\nDOUBLE_QUOTED_STRING\n : '\"' ( ~'\"' | '\"\"')* '\"'\n ;\n\nSINGLE_QUOTED_UNICODE_STRING\n : 'U&\\'' ( ~'\\'' | '\\'\\'')* '\\'' // Unicode string with default escape character: U&'Hello winter \\2603 !'\n ;\n\nDOUBLE_QUOTED_UNICODE_STRING\n : 'U&\"' ( ~'\"' | '\"\"')* '\"' // Unicode string with custom escape character: U&'Hello winter #2603 !' UESCAPE '#'\n ;\n\n// Note: we allow any character inside the binary literal and validate\n// its a correct literal when the AST is being constructed. This\n// allows us to provide more meaningful error messages to the user\nBINARY_LITERAL\n : 'x\\'' (~'\\'')* '\\''\n ;\n\nNANOSECOND_INTERVAL\n : DECIMAL_INTEGER 'ns'\n ;\n\nMICROSECOND_INTERVAL\n : DECIMAL_INTEGER 'us'\n ;\n\nMILLISECOND_INTERVAL\n : DECIMAL_INTEGER 'ms'\n ;\n\nSECOND_INTERVAL\n : DECIMAL_INTEGER ('s' | 'sec' | 'secs' | 'second' | 'seconds')\n ;\n\nMINUTE_INTERVAL\n : DECIMAL_INTEGER ('m' | 'min' | 'mins' | 'minute' | 'minutes')\n ;\n\nHOUR_INTERVAL\n : DECIMAL_INTEGER ('h' | 'hr' | 'hrs' | 'hour' | 'hours')\n ;\n\nDAY_INTERVAL\n : DECIMAL_INTEGER ('d' | 'day' | 'days')\n ;\n\nWEEK_INTERVAL\n : DECIMAL_INTEGER ('w' | 'week' | 'weeks')\n ;\n\nMONTH_INTERVAL\n : DECIMAL_INTEGER ('mon' | 'month' | 'months')\n ;\n\nQUARTER_INTERVAL\n : DECIMAL_INTEGER ('q' | 'qtr' | 'qtrs' | 'quarter' | 'quarters')\n ;\n\nYEAR_INTERVAL\n : DECIMAL_INTEGER ('y' | 'yr' | 'yrs' | 'year' | 'years')\n ;\n\nROWS_LITERAL\n : DECIMAL_INTEGER ('r' | 'row' | 'rows')\n ;\n\nSECOND_TRUNC\n : '@' ('s' | 'sec' | 'secs' | 'second' | 'seconds')\n ;\n\nMINUTE_TRUNC\n : '@' ('m' | 'min' | 'mins' | 'minute' | 'minutes')\n ;\n\nHOUR_TRUNC\n : '@' ('h' | 'hr' | 'hrs' | 'hour' | 'hours')\n ;\n\nDAY_TRUNC\n : '@' ('d' | 'day' | 'days')\n ;\n\nWEEK_TRUNC\n : '@' ('w' | 'week' | 'weeks')\n ;\n\nMONTH_TRUNC\n : '@' ('mon' | 'month' | 'months')\n ;\n\nQUARTER_TRUNC\n : '@' ('q' | 'qtr' | 'qtrs' | 'quarter' | 'quarters')\n ;\n\nYEAR_TRUNC\n : '@' ('y' | 'yr' | 'yrs' | 'year' | 'years')\n ;\n\nINTEGER_VALUE\n : DECIMAL_INTEGER\n | HEXADECIMAL_INTEGER\n | OCTAL_INTEGER\n | BINARY_INTEGER\n ;\n\nDECIMAL_VALUE\n : DECIMAL_INTEGER '.' DECIMAL_INTEGER\n | '.' DECIMAL_INTEGER\n ;\n\nDOUBLE_VALUE\n : DIGIT+ ('.' DIGIT*)? EXPONENT\n | '.' DIGIT+ EXPONENT\n ;\n\nIDENTIFIER\n : [a-zA-Z_][a-zA-Z_0-9]*\n ;\n\nBACKQUOTED_IDENTIFIER\n : '`' ( ~'`' | '``' )* '`'\n ;\n\nfragment DECIMAL_INTEGER\n : DIGIT ('_'? DIGIT)*\n ;\n\nfragment HEXADECIMAL_INTEGER\n : '0x' ('_'? (DIGIT | [A-F]))+\n ;\n\nfragment OCTAL_INTEGER\n : '0o' ('_'? [0-7])+\n ;\n\nfragment BINARY_INTEGER\n : '0b' ('_'? [01])+\n ;\n\nfragment EXPONENT\n : 'e' [+-]? DIGIT+\n ;\n\nfragment DIGIT\n : [0-9]\n ;\n\n//\n// Comments and whitespace\n//\n\nSIMPLE_COMMENT\n : '//' ~[\\r\\n]* '\\r'? '\\n'? -> channel(HIDDEN)\n ;\n\nBRACKETED_COMMENT\n : '/*' .*? '*/' -> channel(HIDDEN)\n ;\n\nWS\n : [ \\r\\n\\t]+ -> skip\n ;\n";
2931
+
2930
2932
  declare const getDatasetsFromQuery: (catalog: Catalog, hamelinInput: string) => Promise<QueryDatasetsResult>;
2931
2933
 
2932
2934
  declare const getFunctionDescriptions: () => Promise<FunctionDescription[]>;
@@ -2947,4 +2949,4 @@ declare const getSorts: (hamelinQuery: string) => QuerySort[];
2947
2949
 
2948
2950
  declare const sampleCatalog: Catalog;
2949
2951
 
2950
- export { AggCommandContext, AnyNumberContext, AppendCommandContext, ArrayLiteralContext, AssignmentClauseContext, AssignmentContext, AtLeastOneContext, BackQuotedIdentifierContext, BasicDoubleQuotedStringLiteralContext, BasicSingleQuotedStringLiteralContext, BinaryLiteralContext, BinaryOperatorContext, BooleanLiteralContext, CastContext, type Catalog, CatalogProvider, type Column, ColumnReferenceAltContext, ColumnReferenceContext, CommandContext, CommandEOFContext, type CompileQueryResult, Compiler, type Completion, type CompletionItem, type CompletionItemKind, type Context, type ContextualCompletion, type ContextualResult, type ContextualTranslationError, type ContextualTranslationErrors, type DMLTranslation, DecimalLiteralContext, DerefContext, DropCommandContext, ExactlyContext, ExplodeCommandContext, ExpressionContext, ExpressionEOFContext, ExpressionQueryContext, FromClauseContext, FromCommandContext, FunctionCallContext, type FunctionDescription, GroupClauseContext, HamelinLexer, HamelinListener, HamelinParser, type HamelinType, HamelinVisitor, HamelintypeContext, IdentifierContext, IdentifierEOFContext, IndexAccessContext, type InitInput, type InitOutput, IntegerLiteralContext, IntervalLiteralContext, JoinCommandContext, type LanguageArea, LetCommandContext, type Level, LimitCommandContext, MatchCommandContext, MatchDefineContext, NamedArgumentContext, NestCommandContext, NestedContext, NullLiteralContext, NumberContext, NumericLiteralContext, PairLiteralContext, ParameterizedTypeContext, ParenthesizedExpressionContext, ParseCommandContext, PatternContext, PipelineAltContext, PipelineContext, PositionalArgumentContext, QuantifiedContext, QuantifierContext, QueryContext, type QueryDatasetsResult, QueryEOFContext, type QuerySort, type QueryTranslation, RowsLiteralContext, ScientificLiteralContext, SelectCommandContext, SelectionContext, SimpleIdentifierContext, SimpleIdentifierEOFContext, SimpleTypeContext, SortCommandContext, SortExpressionContext, type Stage, StandaloneQueryContext, type StatementTranslation, StringContext, StringLiteralContext, StructLiteralContext, StructTypeContext, type SyncInitInput, TableAliasContext, TableReferenceContext, type Translation, type TranslationError, type TranslationErrors, TsTruncContext, TsTruncTimestampLiteralContext, TupleLiteralContext, TupleTypeContext, TypeWithArgumentsContext, UnaryPostfixOperatorContext, UnaryPrefixOperatorContext, UnboundRangeLiteralContext, UnicodeDoubleQuotedStringLiteralContext, UnicodeSingleQuotedStringLiteralContext, UnionCommandContext, UnnestCommandContext, UnquotedIdentifierContext, WhereCommandContext, WindowCommandContext, WithQueryContext, WithinCommandContext, ZeroOrOneContext, compileHamelin, createCompiler, getDatasetsFromQuery, getFunctionDescriptions, getLimits, getSorts, initSync, sampleCatalog };
2952
+ export { AggCommandContext, AnyNumberContext, AppendCommandContext, ArrayLiteralContext, AssignmentClauseContext, AssignmentContext, AtLeastOneContext, BackQuotedIdentifierContext, BasicDoubleQuotedStringLiteralContext, BasicSingleQuotedStringLiteralContext, BinaryLiteralContext, BinaryOperatorContext, BooleanLiteralContext, CastContext, type Catalog, CatalogProvider, type Column, ColumnReferenceAltContext, ColumnReferenceContext, CommandContext, CommandEOFContext, type CompileQueryResult, Compiler, type Completion, type CompletionItem, type CompletionItemKind, type Context, type ContextualCompletion, type ContextualResult, type ContextualTranslationError, type ContextualTranslationErrors, type DMLTranslation, DecimalLiteralContext, DerefContext, DropCommandContext, ExactlyContext, ExplodeCommandContext, ExpressionContext, ExpressionEOFContext, ExpressionQueryContext, FromClauseContext, FromCommandContext, FunctionCallContext, type FunctionDescription, GroupClauseContext, HamelinLexer, HamelinListener, HamelinParser, type HamelinType, HamelinVisitor, HamelintypeContext, IdentifierContext, IdentifierEOFContext, IndexAccessContext, type InitInput, type InitOutput, IntegerLiteralContext, IntervalLiteralContext, JoinCommandContext, type LanguageArea, LetCommandContext, type Level, LimitCommandContext, MatchCommandContext, MatchDefineContext, NamedArgumentContext, NestCommandContext, NestedContext, NullLiteralContext, NumberContext, NumericLiteralContext, PairLiteralContext, ParameterizedTypeContext, ParenthesizedExpressionContext, ParseCommandContext, PatternContext, PipelineAltContext, PipelineContext, PositionalArgumentContext, QuantifiedContext, QuantifierContext, QueryContext, type QueryDatasetsResult, QueryEOFContext, type QuerySort, type QueryTranslation, RowsLiteralContext, ScientificLiteralContext, SelectCommandContext, SelectionContext, SimpleIdentifierContext, SimpleIdentifierEOFContext, SimpleTypeContext, SortCommandContext, SortExpressionContext, type Stage, StandaloneQueryContext, type StatementTranslation, StringContext, StringLiteralContext, StructLiteralContext, StructTypeContext, type SyncInitInput, TableAliasContext, TableReferenceContext, type Translation, type TranslationError, type TranslationErrors, TsTruncContext, TsTruncTimestampLiteralContext, TupleLiteralContext, TupleTypeContext, TypeWithArgumentsContext, UnaryPostfixOperatorContext, UnaryPrefixOperatorContext, UnboundRangeLiteralContext, UnicodeDoubleQuotedStringLiteralContext, UnicodeSingleQuotedStringLiteralContext, UnionCommandContext, UnnestCommandContext, UnquotedIdentifierContext, WhereCommandContext, WindowCommandContext, WithQueryContext, WithinCommandContext, ZeroOrOneContext, compileHamelin, createCompiler, getDatasetsFromQuery, getFunctionDescriptions, getLimits, getSorts, hamelinGrammar, initSync, sampleCatalog };
package/dist/main.js CHANGED
@@ -26319,6 +26319,452 @@ var HamelinVisitor = class extends AbstractParseTreeVisitor {
26319
26319
  visitNamedArgument;
26320
26320
  };
26321
26321
 
26322
+ // src/generated/hamelin-grammar-string.ts
26323
+ var hamelinGrammar = `grammar Hamelin;
26324
+
26325
+ queryEOF
26326
+ : query EOF
26327
+ ;
26328
+
26329
+ commandEOF
26330
+ : command EOF
26331
+ ;
26332
+
26333
+ expressionEOF
26334
+ : expression EOF
26335
+ ;
26336
+
26337
+ identifierEOF
26338
+ : identifier EOF
26339
+ ;
26340
+
26341
+ simpleIdentifierEOF
26342
+ : simpleIdentifier EOF
26343
+ ;
26344
+
26345
+ query
26346
+ : (WITH simpleIdentifier ASSIGN pipeline)+ pipeline #withQuery
26347
+ | pipeline #standaloneQuery
26348
+ | expression #expressionQuery
26349
+ ;
26350
+
26351
+ pipeline
26352
+ : command ( PIPE command )* #pipelineAlt
26353
+ ;
26354
+
26355
+ command
26356
+ : LET_COMMAND assignment (COMMA assignment)* COMMA? #letCommand
26357
+ | WHERE_COMMAND expression #whereCommand
26358
+ | SELECT_COMMAND assignmentClause (COMMA assignmentClause)* COMMA? #selectCommand
26359
+ | DROP_COMMAND selection (COMMA selection)* COMMA? #dropCommand
26360
+ | FROM_COMMAND fromClause (COMMA fromClause)* COMMA? #fromCommand
26361
+ | UNION_COMMAND fromClause (COMMA fromClause)* COMMA? #unionCommand
26362
+ | LIMIT_COMMAND expression #limitCommand
26363
+ | PARSE_COMMAND src=expression? string
26364
+ AS? identifier (COMMA identifier)* COMMA? NODROP? #parseCommand
26365
+ | WITHIN_COMMAND expression #withinCommand
26366
+ | AGG_COMMAND (assignmentClause (COMMA assignmentClause)*)? COMMA?
26367
+ (BY groupClause (COMMA groupClause)*)? COMMA?
26368
+ (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA? #aggCommand
26369
+ | SORT BY? sortExpression (COMMA sortExpression)* COMMA? #sortCommand
26370
+ | WINDOW_COMMAND assignmentClause (COMMA assignmentClause)* COMMA?
26371
+ (BY groupClause (COMMA groupClause)*)? COMMA?
26372
+ (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA?
26373
+ (WITHIN_COMMAND within=expression)? #windowCommand
26374
+ | APPEND_COMMAND tableReference (DISTINCT_BY selection (COMMA selection)*)? COMMA? #appendCommand
26375
+ | (JOIN_COMMAND | LOOKUP_COMMAND) fromClause (ON on=expression)? #joinCommand
26376
+ | EXPLODE_COMMAND assignmentClause #explodeCommand
26377
+ | (UNNEST_COMMAND | ROWS_COMMAND) expression #unnestCommand
26378
+ | NEST_COMMAND identifier #nestCommand
26379
+ | MATCH_COMMAND pattern+
26380
+ (WHEN matchDefine (COMMA matchDefine)*)? COMMA?
26381
+ (BY groupClause (COMMA groupClause)*)? COMMA?
26382
+ (SORT BY? sortExpression (COMMA sortExpression)*)? COMMA? #matchCommand
26383
+ ;
26384
+
26385
+ assignmentClause: assignment | expression;
26386
+ groupClause: assignmentClause;
26387
+ assignment: identifier ASSIGN expression;
26388
+ matchDefine: simpleIdentifier ASSIGN expression;
26389
+ selection: identifier;
26390
+ sortExpression: expression (ASC | DESC)?;
26391
+ tableAlias: simpleIdentifier ASSIGN tableReference;
26392
+ fromClause: tableAlias | tableReference;
26393
+
26394
+ expression
26395
+ // Keep this list in precedence order (important!)
26396
+ : operator=(MINUS | PLUS) expression #unaryPrefixOperator
26397
+ | expression (SECOND_TRUNC | MINUTE_TRUNC | HOUR_TRUNC | DAY_TRUNC | WEEK_TRUNC |
26398
+ MONTH_TRUNC | QUARTER_TRUNC | YEAR_TRUNC) #tsTrunc
26399
+ | left=expression operator=DOT right=simpleIdentifier #deref
26400
+ | value=expression LBRACKET index=expression RBRACKET #indexAccess
26401
+ | left=expression operator=(ASTERISK | SLASH | PERCENT) right=expression #binaryOperator
26402
+ | left=expression operator=(PLUS | MINUS) right=expression #binaryOperator
26403
+ | operator=RANGE expression #unaryPrefixOperator
26404
+ | expression operator=RANGE #unaryPostfixOperator
26405
+ | left=expression operator=RANGE right=expression #binaryOperator
26406
+ | left=expression operator=AS right=hamelintype #cast
26407
+ | left=expression
26408
+ operator=(EQ | NEQ | LT | LTE | GT | GTE | IS | ISNOT | IN) right=expression #binaryOperator
26409
+ | operator=NOT expression #unaryPrefixOperator
26410
+ | left=expression operator=AND right=expression #binaryOperator
26411
+ | left=expression operator=OR right=expression #binaryOperator
26412
+
26413
+ // Complex Literals
26414
+ | left=expression operator=COLON right=expression #pairLiteral
26415
+ | LCURLY simpleIdentifier COLON expression
26416
+ (COMMA simpleIdentifier COLON expression)* COMMA? RCURLY #structLiteral
26417
+ | LPARENS ((expression COMMA) |
26418
+ (expression COMMA expression (COMMA expression)* COMMA?)) RPARENS #tupleLiteral
26419
+ | LBRACKET (expression (COMMA expression)* COMMA?)? RBRACKET #arrayLiteral
26420
+
26421
+ // Function Calls
26422
+ | functionName=simpleIdentifier
26423
+ LPARENS (namedArgument (COMMA namedArgument)* COMMA?)? RPARENS #functionCall
26424
+ | functionName=simpleIdentifier LPARENS
26425
+ positionalArgument (COMMA positionalArgument)*
26426
+ (COMMA namedArgument)* COMMA? RPARENS #functionCall
26427
+
26428
+ // Primitive Literals
26429
+ | NULL #nullLiteral
26430
+ | number #numericLiteral
26431
+ | TRUE #booleanLiteral
26432
+ | FALSE #booleanLiteral
26433
+ | string #stringLiteral
26434
+ | BINARY_LITERAL #binaryLiteral
26435
+ | RANGE #unboundRangeLiteral
26436
+ | (NANOSECOND_INTERVAL | MICROSECOND_INTERVAL | MILLISECOND_INTERVAL |
26437
+ SECOND_INTERVAL | MINUTE_INTERVAL | HOUR_INTERVAL | DAY_INTERVAL |
26438
+ WEEK_INTERVAL | MONTH_INTERVAL | QUARTER_INTERVAL | YEAR_INTERVAL) #intervalLiteral
26439
+ | ROWS_LITERAL #rowsLiteral
26440
+ | (SECOND_TRUNC | MINUTE_TRUNC | HOUR_TRUNC | DAY_TRUNC | WEEK_TRUNC |
26441
+ MONTH_TRUNC | QUARTER_TRUNC | YEAR_TRUNC) #tsTruncTimestampLiteral
26442
+
26443
+ // Environment references
26444
+ | columnReference #columnReferenceAlt
26445
+
26446
+ // Keep this at the bottom to use it the mechanism that query authors have to specify precedence.
26447
+ | LPARENS expression RPARENS #parenthesizedExpression
26448
+ ;
26449
+
26450
+ hamelintype
26451
+ : simpleIdentifier LPARENS hamelintype (COMMA hamelintype)* COMMA? RPARENS #parameterizedType
26452
+ | simpleIdentifier LPARENS INTEGER_VALUE (COMMA INTEGER_VALUE)* COMMA? RPARENS #typeWithArguments
26453
+ | LCURLY simpleIdentifier COLON hamelintype
26454
+ (COMMA simpleIdentifier COLON hamelintype)* COMMA? RCURLY #structType
26455
+ | LPARENS hamelintype (COMMA hamelintype )* COMMA? RPARENS #tupleType
26456
+ | simpleIdentifier #simpleType
26457
+ ;
26458
+
26459
+ pattern
26460
+ : fromClause quantifier? #quantified
26461
+ | LPARENS pattern+ RPARENS quantifier #nested
26462
+ ;
26463
+
26464
+ quantifier
26465
+ : ASTERISK #AnyNumber
26466
+ | PLUS #AtLeastOne
26467
+ | QUESTIONMARK #ZeroOrOne
26468
+ | LCURLY INTEGER_VALUE RCURLY #Exactly
26469
+ ;
26470
+
26471
+ columnReference
26472
+ : simpleIdentifier
26473
+ ;
26474
+
26475
+ tableReference
26476
+ : identifier
26477
+ ;
26478
+
26479
+ identifier
26480
+ : simpleIdentifier
26481
+ | simpleIdentifier (DOT simpleIdentifier)+
26482
+ ;
26483
+
26484
+ simpleIdentifier
26485
+ : IDENTIFIER #unquotedIdentifier
26486
+ | BACKQUOTED_IDENTIFIER #backQuotedIdentifier
26487
+ ;
26488
+
26489
+ string
26490
+ : SINGLE_QUOTED_STRING #basicSingleQuotedStringLiteral
26491
+ | DOUBLE_QUOTED_STRING #basicDoubleQuotedStringLiteral
26492
+ | value=SINGLE_QUOTED_UNICODE_STRING (UESCAPE uesc=SINGLE_QUOTED_STRING)? #unicodeSingleQuotedStringLiteral
26493
+ | value=DOUBLE_QUOTED_UNICODE_STRING (UESCAPE uesc=DOUBLE_QUOTED_STRING)? #unicodeDoubleQuotedStringLiteral
26494
+ ;
26495
+
26496
+ number
26497
+ : value=DECIMAL_VALUE #decimalLiteral
26498
+ | value=DOUBLE_VALUE #scientificLiteral
26499
+ | value=INTEGER_VALUE #integerLiteral
26500
+ ;
26501
+
26502
+ positionalArgument
26503
+ : expression
26504
+ ;
26505
+
26506
+ namedArgument
26507
+ : simpleIdentifier ASSIGN expression
26508
+ ;
26509
+
26510
+ //
26511
+ // COMMANDS
26512
+ //
26513
+
26514
+ LET_COMMAND: 'LET' | 'let';
26515
+ WHERE_COMMAND: 'WHERE' | 'where';
26516
+ SELECT_COMMAND: 'SELECT' | 'select';
26517
+ DROP_COMMAND: 'DROP' | 'drop';
26518
+ FROM_COMMAND: 'FROM' | 'from';
26519
+ UNION_COMMAND: 'UNION' | 'union';
26520
+ LIMIT_COMMAND: 'LIMIT' | 'limit';
26521
+ PARSE_COMMAND: 'PARSE' | 'parse';
26522
+ WITHIN_COMMAND: 'WITHIN' | 'within';
26523
+ AGG_COMMAND: 'AGG' | 'agg';
26524
+ WINDOW_COMMAND: 'WINDOW' | 'window';
26525
+ APPEND_COMMAND: 'APPEND' | 'append';
26526
+ JOIN_COMMAND: 'JOIN' | 'join';
26527
+ LOOKUP_COMMAND: 'LOOKUP' | 'lookup';
26528
+ EXPLODE_COMMAND: 'EXPLODE' | 'explode';
26529
+ UNNEST_COMMAND: 'UNNEST' | 'unnest';
26530
+ NEST_COMMAND: 'NEST' | 'nest';
26531
+ ROWS_COMMAND: 'ROWS' | 'rows';
26532
+ MATCH_COMMAND: 'MATCH' | 'match';
26533
+
26534
+ AS: 'AS' | 'as';
26535
+ NODROP: 'NODROP' | 'nodrop';
26536
+
26537
+ //
26538
+ // Operators
26539
+ //
26540
+
26541
+ PLUS: '+';
26542
+ MINUS: '-';
26543
+ ASTERISK: '*';
26544
+ SLASH: '/';
26545
+ PERCENT: '%';
26546
+ LCURLY: '{';
26547
+ RCURLY: '}';
26548
+ COLON: ':';
26549
+ QUESTIONMARK: '?';
26550
+
26551
+ EQ: '==';
26552
+ NEQ: '!=';
26553
+ LT: '<';
26554
+ LTE: '<=';
26555
+ GT: '>';
26556
+ GTE: '>=';
26557
+ RANGE: '..';
26558
+
26559
+ ASSIGN: '=';
26560
+
26561
+ //
26562
+ // Keywords
26563
+ //
26564
+
26565
+ AND: 'AND' | 'and';
26566
+ FALSE: 'FALSE' | 'false';
26567
+ IS: 'IS' | 'is';
26568
+ NOT: 'NOT' | 'not';
26569
+ ISNOT: 'IS NOT' | 'is not';
26570
+ IN: 'IN' | 'in';
26571
+ NULL: 'NULL' | 'null';
26572
+ OR: 'OR' | 'or';
26573
+ TRUE: 'TRUE' | 'true';
26574
+ UESCAPE: 'UESCAPE' | 'uescape';
26575
+ WITH: 'WITH' | 'with';
26576
+ BY: 'BY' | 'by';
26577
+ SORT: 'SORT' | 'sort';
26578
+ ASC: 'ASC' | 'asc';
26579
+ DESC: 'DESC' | 'desc';
26580
+ DISTINCT_BY: 'DISTINCT BY' | 'distinct by';
26581
+ ON: 'ON' | 'on';
26582
+ WHEN: 'WHEN' | 'when';
26583
+
26584
+ //
26585
+ // Symbols
26586
+ //
26587
+
26588
+ COMMA: ',';
26589
+ PIPE: '|';
26590
+ LPARENS: '(';
26591
+ RPARENS: ')';
26592
+ DOT: '.';
26593
+ LBRACKET: '[';
26594
+ RBRACKET: ']';
26595
+
26596
+ //
26597
+ // Literals
26598
+ //
26599
+
26600
+ SINGLE_QUOTED_STRING
26601
+ : '\\'' ( ~'\\'' | '\\'\\'')* '\\''
26602
+ ;
26603
+ DOUBLE_QUOTED_STRING
26604
+ : '"' ( ~'"' | '""')* '"'
26605
+ ;
26606
+
26607
+ SINGLE_QUOTED_UNICODE_STRING
26608
+ : 'U&\\'' ( ~'\\'' | '\\'\\'')* '\\'' // Unicode string with default escape character: U&'Hello winter \\2603 !'
26609
+ ;
26610
+
26611
+ DOUBLE_QUOTED_UNICODE_STRING
26612
+ : 'U&"' ( ~'"' | '""')* '"' // Unicode string with custom escape character: U&'Hello winter #2603 !' UESCAPE '#'
26613
+ ;
26614
+
26615
+ // Note: we allow any character inside the binary literal and validate
26616
+ // its a correct literal when the AST is being constructed. This
26617
+ // allows us to provide more meaningful error messages to the user
26618
+ BINARY_LITERAL
26619
+ : 'x\\'' (~'\\'')* '\\''
26620
+ ;
26621
+
26622
+ NANOSECOND_INTERVAL
26623
+ : DECIMAL_INTEGER 'ns'
26624
+ ;
26625
+
26626
+ MICROSECOND_INTERVAL
26627
+ : DECIMAL_INTEGER 'us'
26628
+ ;
26629
+
26630
+ MILLISECOND_INTERVAL
26631
+ : DECIMAL_INTEGER 'ms'
26632
+ ;
26633
+
26634
+ SECOND_INTERVAL
26635
+ : DECIMAL_INTEGER ('s' | 'sec' | 'secs' | 'second' | 'seconds')
26636
+ ;
26637
+
26638
+ MINUTE_INTERVAL
26639
+ : DECIMAL_INTEGER ('m' | 'min' | 'mins' | 'minute' | 'minutes')
26640
+ ;
26641
+
26642
+ HOUR_INTERVAL
26643
+ : DECIMAL_INTEGER ('h' | 'hr' | 'hrs' | 'hour' | 'hours')
26644
+ ;
26645
+
26646
+ DAY_INTERVAL
26647
+ : DECIMAL_INTEGER ('d' | 'day' | 'days')
26648
+ ;
26649
+
26650
+ WEEK_INTERVAL
26651
+ : DECIMAL_INTEGER ('w' | 'week' | 'weeks')
26652
+ ;
26653
+
26654
+ MONTH_INTERVAL
26655
+ : DECIMAL_INTEGER ('mon' | 'month' | 'months')
26656
+ ;
26657
+
26658
+ QUARTER_INTERVAL
26659
+ : DECIMAL_INTEGER ('q' | 'qtr' | 'qtrs' | 'quarter' | 'quarters')
26660
+ ;
26661
+
26662
+ YEAR_INTERVAL
26663
+ : DECIMAL_INTEGER ('y' | 'yr' | 'yrs' | 'year' | 'years')
26664
+ ;
26665
+
26666
+ ROWS_LITERAL
26667
+ : DECIMAL_INTEGER ('r' | 'row' | 'rows')
26668
+ ;
26669
+
26670
+ SECOND_TRUNC
26671
+ : '@' ('s' | 'sec' | 'secs' | 'second' | 'seconds')
26672
+ ;
26673
+
26674
+ MINUTE_TRUNC
26675
+ : '@' ('m' | 'min' | 'mins' | 'minute' | 'minutes')
26676
+ ;
26677
+
26678
+ HOUR_TRUNC
26679
+ : '@' ('h' | 'hr' | 'hrs' | 'hour' | 'hours')
26680
+ ;
26681
+
26682
+ DAY_TRUNC
26683
+ : '@' ('d' | 'day' | 'days')
26684
+ ;
26685
+
26686
+ WEEK_TRUNC
26687
+ : '@' ('w' | 'week' | 'weeks')
26688
+ ;
26689
+
26690
+ MONTH_TRUNC
26691
+ : '@' ('mon' | 'month' | 'months')
26692
+ ;
26693
+
26694
+ QUARTER_TRUNC
26695
+ : '@' ('q' | 'qtr' | 'qtrs' | 'quarter' | 'quarters')
26696
+ ;
26697
+
26698
+ YEAR_TRUNC
26699
+ : '@' ('y' | 'yr' | 'yrs' | 'year' | 'years')
26700
+ ;
26701
+
26702
+ INTEGER_VALUE
26703
+ : DECIMAL_INTEGER
26704
+ | HEXADECIMAL_INTEGER
26705
+ | OCTAL_INTEGER
26706
+ | BINARY_INTEGER
26707
+ ;
26708
+
26709
+ DECIMAL_VALUE
26710
+ : DECIMAL_INTEGER '.' DECIMAL_INTEGER
26711
+ | '.' DECIMAL_INTEGER
26712
+ ;
26713
+
26714
+ DOUBLE_VALUE
26715
+ : DIGIT+ ('.' DIGIT*)? EXPONENT
26716
+ | '.' DIGIT+ EXPONENT
26717
+ ;
26718
+
26719
+ IDENTIFIER
26720
+ : [a-zA-Z_][a-zA-Z_0-9]*
26721
+ ;
26722
+
26723
+ BACKQUOTED_IDENTIFIER
26724
+ : '\`' ( ~'\`' | '\`\`' )* '\`'
26725
+ ;
26726
+
26727
+ fragment DECIMAL_INTEGER
26728
+ : DIGIT ('_'? DIGIT)*
26729
+ ;
26730
+
26731
+ fragment HEXADECIMAL_INTEGER
26732
+ : '0x' ('_'? (DIGIT | [A-F]))+
26733
+ ;
26734
+
26735
+ fragment OCTAL_INTEGER
26736
+ : '0o' ('_'? [0-7])+
26737
+ ;
26738
+
26739
+ fragment BINARY_INTEGER
26740
+ : '0b' ('_'? [01])+
26741
+ ;
26742
+
26743
+ fragment EXPONENT
26744
+ : 'e' [+-]? DIGIT+
26745
+ ;
26746
+
26747
+ fragment DIGIT
26748
+ : [0-9]
26749
+ ;
26750
+
26751
+ //
26752
+ // Comments and whitespace
26753
+ //
26754
+
26755
+ SIMPLE_COMMENT
26756
+ : '//' ~[\\r\\n]* '\\r'? '\\n'? -> channel(HIDDEN)
26757
+ ;
26758
+
26759
+ BRACKETED_COMMENT
26760
+ : '/*' .*? '*/' -> channel(HIDDEN)
26761
+ ;
26762
+
26763
+ WS
26764
+ : [ \\r\\n\\t]+ -> skip
26765
+ ;
26766
+ `;
26767
+
26322
26768
  // src/get-datasets-from-query.ts
26323
26769
  var getDatasetsFromQuery = async (catalog, hamelinInput) => {
26324
26770
  await initializeWasm();
@@ -26954,5 +27400,6 @@ export {
26954
27400
  getFunctionDescriptions,
26955
27401
  getLimits,
26956
27402
  getSorts,
27403
+ hamelinGrammar,
26957
27404
  sampleCatalog
26958
27405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamelin.sh/compiler",
3
- "version": "0.2.3-prerelease.20250910T133135",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false,
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -33,12 +33,13 @@
33
33
  "check": "pnpm check:types",
34
34
  "check:types": "tsc --noEmit",
35
35
  "dev": "tsup --watch",
36
- "generate": "pnpm generate:1 && pnpm generate:2 && pnpm generate:3 && pnpm generate:4 && pnpm generate:5",
36
+ "generate": "pnpm generate:1 && pnpm generate:2 && pnpm generate:3 && pnpm generate:4 && pnpm generate:5 && pnpm generate:6",
37
37
  "generate:1": "cd ../../hamelin_wasm && wasm-pack build --target web",
38
38
  "generate:2": "copyfiles -u 4 \"../../hamelin_wasm/pkg/hamelin_wasm*\" src/generated/",
39
39
  "generate:3": "node encode-wasm.js",
40
40
  "generate:4": "antlr4ng -Dlanguage=TypeScript -visitor -Xexact-output-dir ../../hamelin_lib/grammars/Hamelin.g4 -o src/generated",
41
- "generate:5": "biome lint --write src/generated --only style/useImportType --config-path ./purposefully-empty.json",
41
+ "generate:5": "node generate-hamelin-grammar-string.js",
42
+ "generate:6": "biome lint --write src/generated --only style/useImportType --config-path ./purposefully-empty.json",
42
43
  "test": "vitest"
43
44
  }
44
45
  }