Skip to content

Commit b4cfd86

Browse files
committed
Fixed Tokenizer + Added Test
1 parent 89ba65f commit b4cfd86

11 files changed

Lines changed: 76 additions & 5 deletions

File tree

Source/Tokenizer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const tokens = [
1414
[ 'Colon' , /^:/ ] ,
1515

1616
[ 'Newline' , /^\r?\n/ ] ,
17-
[ 'Space' , /^[\s]+/ , 0 ] ,
17+
18+
[ 'MultiString' , /^[^\S\n]*'''[\s\S]*?'''/u , 0 ] ,
19+
[ 'Space' , /^[^\S\n]+/ , 0 ] ,
1820

19-
[ 'MultiString' , /^'''([\s\S]*?)'''/u , 1 ] ,
2021
[ 'MultiComment' , /^\/\*([\s\S]*?)\*\//u ] ,
2122
[ 'SingleString' , /^'(([^\\]|(\\["'\\/bfnrt])|(\\u\d{4}))*?)'/ , 1 ] ,
2223
[ 'DoubleString' , /^"(([^\\]|(\\["'\\/bfnrt])|(\\u\d{4}))*?)"/ , 1 ] ,
@@ -61,8 +62,6 @@ export default class Tokenizer {
6162

6263
const found = string.match(regex);
6364

64-
console.log(type,found);
65-
6665
this.#string = string.substring(found[0].length);
6766

6867
const token = { type };

Tests/Normalize.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
clear
3+
4+
echo ""
5+
echo ""
6+
echo ""
7+
echo ""
8+
echo ""
9+
echo ""
10+
echo ""
11+
echo ""
12+
echo ""
13+
14+
deno test \
15+
--importmap=Tests/Imports.json \
16+
Tests/Normalize

Tests/Tokens/Multiline.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import { assertSameTokens , test } from 'TokenTest';
3+
4+
5+
const hjson =
6+
`{
7+
multiline-value :
8+
9+
'''
10+
Tes\nting
11+
12+
this
13+
'''
14+
}`;
15+
16+
17+
const tokens = [{
18+
type : 'ObjectStart'
19+
},{
20+
type : 'Newline'
21+
},{
22+
type : 'Space' ,
23+
value : ' '
24+
},{
25+
type : 'Member' ,
26+
value : 'multiline-value'
27+
},{
28+
type : 'Space' ,
29+
value : ' '
30+
},{
31+
type : 'Colon'
32+
},{
33+
type : 'Space' ,
34+
value : ' '
35+
},{
36+
type : 'Newline'
37+
},{
38+
type : 'Space' ,
39+
value : ' '
40+
},{
41+
type : 'Newline'
42+
},{
43+
type : 'MultiString' ,
44+
value : ` '''\n Tes\nting\n \n this\n '''`
45+
},{
46+
type : 'Newline'
47+
},{
48+
type : 'ObjectEnd'
49+
}];
50+
51+
52+
test('Multiline Member',() => {
53+
54+
assertSameTokens(hjson,tokens);
55+
56+
})

0 commit comments

Comments
 (0)