@altopelago/aeon-lexer 0.9.0

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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @altopelago/aeon-lexer
2
+
3
+ Tokenization for AEON source text.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @altopelago/aeon-lexer
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { tokenize } from '@altopelago/aeon-lexer';
15
+
16
+ const result = tokenize('answer = 42');
17
+
18
+ for (const token of result.tokens) {
19
+ console.log(token.kind, token.raw);
20
+ }
21
+ ```
22
+
23
+ Use this package when you need direct token access for tooling, analysis, or editor features.
24
+ If you want the stable application-facing entry point, prefer `@altopelago/aeon-core`.
@@ -0,0 +1,56 @@
1
+ import type { Span } from './tokens.js';
2
+ /**
3
+ * Base class for all lexer errors
4
+ */
5
+ export declare class LexerError extends Error {
6
+ readonly span: Span;
7
+ readonly code: string;
8
+ constructor(message: string, span: Span, code?: string);
9
+ }
10
+ /**
11
+ * Unexpected character encountered
12
+ */
13
+ export declare class UnexpectedCharacterError extends LexerError {
14
+ readonly character: string;
15
+ constructor(character: string, span: Span);
16
+ }
17
+ /**
18
+ * Unterminated string literal
19
+ */
20
+ export declare class UnterminatedStringError extends LexerError {
21
+ readonly delimiter: string;
22
+ constructor(delimiter: string, span: Span);
23
+ }
24
+ /**
25
+ * Invalid escape sequence
26
+ */
27
+ export declare class InvalidEscapeSequenceError extends LexerError {
28
+ readonly sequence: string;
29
+ constructor(sequence: string, span: Span);
30
+ }
31
+ /**
32
+ * Invalid number literal
33
+ */
34
+ export declare class InvalidNumberError extends LexerError {
35
+ readonly raw: string;
36
+ constructor(raw: string, span: Span);
37
+ }
38
+ export declare class InvalidTimeError extends LexerError {
39
+ readonly raw: string;
40
+ constructor(raw: string, span: Span);
41
+ }
42
+ export declare class InvalidDateError extends LexerError {
43
+ readonly raw: string;
44
+ constructor(raw: string, span: Span);
45
+ }
46
+ export declare class InvalidDateTimeError extends LexerError {
47
+ readonly raw: string;
48
+ constructor(raw: string, span: Span);
49
+ }
50
+ /**
51
+ * Unterminated block comment
52
+ */
53
+ export declare class UnterminatedBlockCommentError extends LexerError {
54
+ constructor(span: Span);
55
+ }
56
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE,MAAsB;CAMxE;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;IACpD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAK5C;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAK5C;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAK3C;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKtC;AAED,qBAAa,gBAAiB,SAAQ,UAAU;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKtC;AAED,qBAAa,gBAAiB,SAAQ,UAAU;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKtC;AAED,qBAAa,oBAAqB,SAAQ,UAAU;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKtC;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,UAAU;gBAC7C,IAAI,EAAE,IAAI;CAIzB"}
package/dist/errors.js ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Base class for all lexer errors
3
+ */
4
+ export class LexerError extends Error {
5
+ span;
6
+ code;
7
+ constructor(message, span, code = 'LEXER_ERROR') {
8
+ super(message);
9
+ this.name = 'LexerError';
10
+ this.span = span;
11
+ this.code = code;
12
+ }
13
+ }
14
+ /**
15
+ * Unexpected character encountered
16
+ */
17
+ export class UnexpectedCharacterError extends LexerError {
18
+ character;
19
+ constructor(character, span) {
20
+ super(`Unexpected character: '${character}'`, span, 'UNEXPECTED_CHARACTER');
21
+ this.name = 'UnexpectedCharacterError';
22
+ this.character = character;
23
+ }
24
+ }
25
+ /**
26
+ * Unterminated string literal
27
+ */
28
+ export class UnterminatedStringError extends LexerError {
29
+ delimiter;
30
+ constructor(delimiter, span) {
31
+ super(`Unterminated string literal (started with ${delimiter})`, span, 'UNTERMINATED_STRING');
32
+ this.name = 'UnterminatedStringError';
33
+ this.delimiter = delimiter;
34
+ }
35
+ }
36
+ /**
37
+ * Invalid escape sequence
38
+ */
39
+ export class InvalidEscapeSequenceError extends LexerError {
40
+ sequence;
41
+ constructor(sequence, span) {
42
+ super(`Invalid escape sequence: '${sequence}'`, span, 'INVALID_ESCAPE');
43
+ this.name = 'InvalidEscapeSequenceError';
44
+ this.sequence = sequence;
45
+ }
46
+ }
47
+ /**
48
+ * Invalid number literal
49
+ */
50
+ export class InvalidNumberError extends LexerError {
51
+ raw;
52
+ constructor(raw, span) {
53
+ super(`Invalid number literal: '${raw}'`, span, 'INVALID_NUMBER');
54
+ this.name = 'InvalidNumberError';
55
+ this.raw = raw;
56
+ }
57
+ }
58
+ export class InvalidTimeError extends LexerError {
59
+ raw;
60
+ constructor(raw, span) {
61
+ super(`Invalid time literal: '${raw}'`, span, 'INVALID_TIME');
62
+ this.name = 'InvalidTimeError';
63
+ this.raw = raw;
64
+ }
65
+ }
66
+ export class InvalidDateError extends LexerError {
67
+ raw;
68
+ constructor(raw, span) {
69
+ super(`Invalid date literal: '${raw}'`, span, 'INVALID_DATE');
70
+ this.name = 'InvalidDateError';
71
+ this.raw = raw;
72
+ }
73
+ }
74
+ export class InvalidDateTimeError extends LexerError {
75
+ raw;
76
+ constructor(raw, span) {
77
+ super(`Invalid datetime literal: '${raw}'`, span, 'INVALID_DATETIME');
78
+ this.name = 'InvalidDateTimeError';
79
+ this.raw = raw;
80
+ }
81
+ }
82
+ /**
83
+ * Unterminated block comment
84
+ */
85
+ export class UnterminatedBlockCommentError extends LexerError {
86
+ constructor(span) {
87
+ super('Unterminated block comment', span, 'UNTERMINATED_BLOCK_COMMENT');
88
+ this.name = 'UnterminatedBlockCommentError';
89
+ }
90
+ }
91
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACxB,IAAI,CAAO;IACX,IAAI,CAAS;IAEtB,YAAY,OAAe,EAAE,IAAU,EAAE,OAAe,aAAa;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,C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AE,IAAU;QAC/B,KAAK,CAAC,0BAA0B,GAAG,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AAED,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IACnC,GAAG,CAAS;IAErB,YAAY,GAAW,EAAE,IAAU;QAC/B,KAAK,CAAC,0BAA0B,GAAG,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AAED,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IACvC,GAAG,CAAS;IAErB,YAAY,GAAW,EAAE,IAAU;QAC/B,KAAK,CAAC,8BAA8B,GAAG,GAAG,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,UAAU;IACzD,YAAY,IAAU;QAClB,KAAK,CAAC,4BAA4B,EAAE,IAAI,EAAE,4BAA4B,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAChD,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @altopelago/aeon-lexer - AEON Lexer Package
3
+ *
4
+ * Tokenizes AEON documents into a stream of tokens with span information.
5
+ */
6
+ export * from './tokens.js';
7
+ export * from './lexer.js';
8
+ export * from './errors.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @altopelago/aeon-lexer - AEON Lexer Package
3
+ *
4
+ * Tokenizes AEON documents into a stream of tokens with span information.
5
+ */
6
+ export * from './tokens.js';
7
+ export * from './lexer.js';
8
+ export * from './errors.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { type Token } from './tokens.js';
2
+ import { LexerError } from './errors.js';
3
+ /**
4
+ * Lexer options
5
+ */
6
+ export interface LexerOptions {
7
+ /** Include comment tokens in output (default: false) */
8
+ readonly includeComments?: boolean;
9
+ /** Include newline tokens in output (default: false) */
10
+ readonly includeNewlines?: boolean;
11
+ }
12
+ /**
13
+ * Result of lexing
14
+ */
15
+ export interface LexResult {
16
+ readonly tokens: readonly Token[];
17
+ readonly errors: readonly LexerError[];
18
+ }
19
+ /**
20
+ * AEON Lexer
21
+ *
22
+ * Hand-written lexer for AEON documents. Produces a stream of tokens
23
+ * with accurate span information for error reporting.
24
+ */
25
+ export declare class Lexer {
26
+ private readonly input;
27
+ private readonly options;
28
+ private offset;
29
+ private line;
30
+ private column;
31
+ private sawLeadingShebang;
32
+ private readonly tokens;
33
+ private readonly errors;
34
+ constructor(input: string, options?: LexerOptions);
35
+ /**
36
+ * Tokenize the input
37
+ */
38
+ tokenize(): LexResult;
39
+ private isAtEnd;
40
+ private currentPosition;
41
+ private peek;
42
+ private peekNext;
43
+ private peekN;
44
+ private advance;
45
+ private match;
46
+ private addToken;
47
+ private scanToken;
48
+ private scanString;
49
+ private scanEscapeSequence;
50
+ private scanUnicodeEscape;
51
+ private scanNumber;
52
+ private scanTime;
53
+ private scanDateOrDateTime;
54
+ private scanHexLiteral;
55
+ private scanRadixLiteral;
56
+ private scanEncodingLiteral;
57
+ private scanSeparatorLiteral;
58
+ private scanIdentifierOrKeyword;
59
+ private scanLineComment;
60
+ private scanShebangComment;
61
+ private scanBlockComment;
62
+ private scanSlashChannelBlockComment;
63
+ private addCommentToken;
64
+ private isLeadingShebangStart;
65
+ private isHostDirectiveSlot;
66
+ private classifyLineComment;
67
+ }
68
+ /**
69
+ * Tokenize an AEON document
70
+ */
71
+ export declare function tokenize(input: string, options?: LexerOptions): LexResult;
72
+ //# sourceMappingURL=lexer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../src/lexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EAMb,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,UAAU,EASb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,wDAAwD;IACxD,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC,wDAAwD;IACxD,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AA6FD;;;;;GAKG;AACH,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,C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