Skip to content

Commit ccce085

Browse files
committed
fix: tl-b grammar constructor name may contain a comma
1 parent 887d62b commit ccce085

6 files changed

Lines changed: 2598 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1313
- Fix tl-b grammar to support math expressions [issues #121](https://github.com/ton-community/tlb-parser/issues/121)
1414
- Fix tl-b grammar use a Nat field in an expression [issues #120](https://github.com/ton-community/tlb-parser/issues/120)
1515
- Fix tl-b grammar can use ref in expression
16+
- Fix tl-b grammar constructor name may contain a comma
1617

1718
### Chore
1819

src/grammar/tlb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TLB {
3737
// Identifiers
3838
identifier = identifierStart identifierPart*
3939
identifierStart = "_" | letter
40-
identifierPart = identifierStart | digit
40+
identifierPart = identifierStart | digit | ","
4141
4242
// Primitives
4343
number = digit+

src/parsing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const rootNodes = {
2525
export const constructorNodes = {
2626
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2727
Constructor(name: TerminalNode, tag: Node): any {
28-
const nameValue = name.sourceString;
28+
const nameValue = name.sourceString.replace(/,/g, '_');
2929
let tagValue = null;
3030

3131
if (tag.numChildren !== 0) {

tests/edge-cases.spec.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ import { isNatField } from '../src/validation';
2323

2424
describe('edge cases', () => {
2525
test.each([
26-
['_ n:(## 2) c:(n * Cell) = X;', null],
27-
['_ n:(## 2) c:(n * ^Cell) = X;', null],
28-
['_ x:# = X;', null],
29-
['test$10 = Test;', 'binary' as const],
30-
['test#0a = Test;', 'hex' as const],
31-
['test = Test;', null],
32-
['_ {n:#} = X (n + 1 + 2);', null],
33-
['_ {n:#} l:(## (n * 2 * 4)) = X;', null],
34-
])('parse & ast: %s', (schema: string, tagType: 'binary' | 'hex' | null) => {
26+
['a,b#00000001 = Ab;', 'hex', 'a_b'],
27+
['_ n:(## 2) c:(n * Cell) = X;', null, '_'],
28+
['_ n:(## 2) c:(n * ^Cell) = X;', null, '_'],
29+
['_ x:# = X;', null, '_'],
30+
['test$10 = Test;', 'binary', 'test'],
31+
['test#0a = Test;', 'hex', 'test'],
32+
['test = Test;', null, 'test'],
33+
['_ {n:#} = X (n + 1 + 2);', null, '_'],
34+
['_ {n:#} l:(## (n * 2 * 4)) = X;', null, '_'],
35+
])('parse & ast: %s', (schema: string, tagType: string | null, constName: string) => {
3536
expect(parse(schema).succeeded()).toBe(true);
3637
const tree = ast(schema);
3738
expect(tree).toBeInstanceOf(Program);
38-
expect(tree.declarations[0]!.constructorDef.getTagType()).toBe(tagType);
39+
const declaration = tree.declarations[0]!;
40+
expect(declaration.constructorDef.name).toBe(constName);
41+
expect(declaration.constructorDef.getTagType()).toBe(tagType);
3942
});
4043

4144
test('withParents handles all cases', () => {

0 commit comments

Comments
 (0)