@@ -67,64 +67,44 @@ export const EOF = undefined;
67
67
const SPECIAL_LINE_START_CHARS = [ "}" , "." , "[" , "*" ] ;
68
68
69
69
export class FluentParserStream extends ParserStream {
70
- skipBlankInline ( ) {
71
- let blank = "" ;
72
- while ( this . currentChar === " " ) {
73
- blank += " " ;
74
- this . next ( ) ;
75
- }
76
- return blank ;
77
- }
78
-
79
70
peekBlankInline ( ) {
71
+ const start = this . index + this . peekOffset ;
80
72
while ( this . currentPeek === " " ) {
81
73
this . peek ( ) ;
82
74
}
75
+ return this . string . slice ( start , this . index + this . peekOffset ) ;
83
76
}
84
77
85
- skipBlankBlock ( ) {
78
+ skipBlankInline ( ) {
79
+ const blank = this . peekBlankInline ( ) ;
80
+ this . skipToPeek ( ) ;
81
+ return blank ;
82
+ }
83
+
84
+ peekBlankBlock ( ) {
86
85
let blank = "" ;
87
86
while ( true ) {
87
+ const lineStart = this . peekOffset ;
88
88
this . peekBlankInline ( ) ;
89
-
90
89
if ( this . currentPeek === EOL ) {
91
- this . skipToPeek ( ) ;
92
- this . next ( ) ;
93
90
blank += EOL ;
91
+ this . peek ( ) ;
94
92
continue ;
95
93
}
96
-
97
94
if ( this . currentPeek === EOF ) {
98
- // Consume any inline blanks before the EOF.
99
- this . skipToPeek ( ) ;
95
+ // Treat the blank line at EOF as a blank block.
100
96
return blank ;
101
97
}
102
-
103
98
// Any other char; reset to column 1 on this line.
104
- this . resetPeek ( ) ;
99
+ this . resetPeek ( lineStart ) ;
105
100
return blank ;
106
101
}
107
102
}
108
103
109
- peekBlankBlock ( ) {
110
- let blank = "" ;
111
- while ( true ) {
112
- const lineStart = this . peekOffset ;
113
- this . peekBlankInline ( ) ;
114
- if ( this . currentPeek === EOL ) {
115
- this . peek ( ) ;
116
- blank += EOL ;
117
- } else {
118
- this . resetPeek ( lineStart ) ;
119
- return blank ;
120
- }
121
- }
122
- }
123
-
124
- skipBlank ( ) {
125
- while ( this . currentChar === " " || this . currentChar === EOL ) {
126
- this . next ( ) ;
127
- }
104
+ skipBlankBlock ( ) {
105
+ const blank = this . peekBlankBlock ( ) ;
106
+ this . skipToPeek ( ) ;
107
+ return blank ;
128
108
}
129
109
130
110
peekBlank ( ) {
@@ -133,6 +113,11 @@ export class FluentParserStream extends ParserStream {
133
113
}
134
114
}
135
115
116
+ skipBlank ( ) {
117
+ this . peekBlank ( ) ;
118
+ this . skipToPeek ( ) ;
119
+ }
120
+
136
121
expectChar ( ch ) {
137
122
if ( this . currentChar === ch ) {
138
123
this . next ( ) ;
0 commit comments