-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathHexNumberExpression.ts
More file actions
31 lines (23 loc) · 879 Bytes
/
HexNumberExpression.ts
File metadata and controls
31 lines (23 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { SlangNode } from './SlangNode.js';
import { NumberUnit } from './NumberUnit.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
export class HexNumberExpression extends SlangNode {
readonly kind = NonterminalKind.HexNumberExpression;
literal: string;
unit?: NumberUnit;
constructor(ast: ast.HexNumberExpression, collected: CollectedMetadata) {
super(ast, collected);
this.literal = ast.literal.unparse();
if (ast.unit) {
this.unit = new NumberUnit(ast.unit, collected);
}
this.updateMetadata(this.unit);
}
print(print: PrintFunction): Doc {
const unitDoc = print('unit');
return [this.literal, unitDoc ? [' ', unitDoc] : unitDoc];
}
}