File tree Expand file tree Collapse file tree 2 files changed +37
-39
lines changed Expand file tree Collapse file tree 2 files changed +37
-39
lines changed Original file line number Diff line number Diff line change 1
1
import { isDigit , Char } from "../char" ;
2
+ import { StringIterator } from "./string-iterator" ;
2
3
import {
3
4
AST ,
4
5
RangeRepetitionNode ,
@@ -58,46 +59,7 @@ class Range {
58
59
to : i32 = - 1 ;
59
60
}
60
61
61
- class StringIterator {
62
- current : u32 ;
63
- cursor : u32 = 0 ;
64
-
65
- constructor ( private sourceString : string ) {
66
- this . current = this . sourceString . charCodeAt ( 0 ) ;
67
- }
68
-
69
- lookahead ( distance : u32 ) : u32 {
70
- return this . sourceString . charCodeAt ( this . cursor + distance ) ;
71
- }
72
-
73
- next ( ) : bool {
74
- this . cursor ++ ;
75
- if ( this . cursor >= u32 ( this . sourceString . length ) ) {
76
- return false ;
77
- }
78
- this . current = this . sourceString . charCodeAt ( this . cursor ) ;
79
- return true ;
80
- }
81
-
82
- currentAsString ( ) : string {
83
- return String . fromCharCode ( this . current ) ;
84
- }
85
-
86
- more ( ) : bool {
87
- return this . cursor < u32 ( this . sourceString . length ) ;
88
- }
89
-
90
- copy ( ) : StringIterator {
91
- const iterator = new StringIterator ( this . sourceString ) ;
92
- iterator . cursor = this . cursor ;
93
- iterator . current = this . current ;
94
- return iterator ;
95
- }
96
- }
97
-
98
62
export class Parser {
99
- // currentToken: string = "";
100
- // cursor: u32 = 0;
101
63
iterator : StringIterator ;
102
64
103
65
private constructor ( input : string ) {
Original file line number Diff line number Diff line change
1
+ export class StringIterator {
2
+ current : u32 ;
3
+ cursor : u32 = 0 ;
4
+
5
+ constructor ( private sourceString : string ) {
6
+ this . current = this . sourceString . charCodeAt ( 0 ) ;
7
+ }
8
+
9
+ lookahead ( distance : u32 ) : u32 {
10
+ return this . sourceString . charCodeAt ( this . cursor + distance ) ;
11
+ }
12
+
13
+ next ( ) : bool {
14
+ this . cursor ++ ;
15
+ if ( this . cursor >= u32 ( this . sourceString . length ) ) {
16
+ return false ;
17
+ }
18
+ this . current = this . sourceString . charCodeAt ( this . cursor ) ;
19
+ return true ;
20
+ }
21
+
22
+ currentAsString ( ) : string {
23
+ return String . fromCharCode ( this . current ) ;
24
+ }
25
+
26
+ more ( ) : bool {
27
+ return this . cursor < u32 ( this . sourceString . length ) ;
28
+ }
29
+
30
+ copy ( ) : StringIterator {
31
+ const iterator = new StringIterator ( this . sourceString ) ;
32
+ iterator . cursor = this . cursor ;
33
+ iterator . current = this . current ;
34
+ return iterator ;
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments