@@ -11,6 +11,7 @@ export type OnToken = (token: BaseToken, scanner: BaseScanner) => void;
11
11
* @internal
12
12
*/
13
13
export default class BaseScanner {
14
+ private static _spaceCharsWithBreak = [ " " , "\t" , "\n" , "\r" ] ;
14
15
private static _spaceChars = [ " " , "\t" ] ;
15
16
private static _checkIsIn ( checked : string , chars : string [ ] ) : boolean {
16
17
for ( let i = 0 ; i < chars . length ; i ++ ) {
@@ -101,27 +102,17 @@ export default class BaseScanner {
101
102
}
102
103
103
104
skipSpace ( includeLineBreak : boolean ) : void {
104
- let curChar : string ;
105
-
106
- while ( includeLineBreak ) {
107
- const chars = this . peek ( 2 ) ;
108
- curChar = chars [ 0 ] ;
109
-
110
- if ( chars === "\r\n" ) {
111
- this . advance ( 2 ) ;
112
- } else if ( curChar === "\n" || curChar === "\r" ) {
113
- this . advance ( 1 ) ;
114
- } else {
115
- break ;
116
- }
117
- }
118
-
119
- curChar = this . getCurChar ( ) ;
120
- const spaceChars = BaseScanner . _spaceChars ;
105
+ const spaceChars = includeLineBreak ? BaseScanner . _spaceCharsWithBreak : BaseScanner . _spaceChars ;
106
+ let curChar = this . getCurChar ( ) ;
121
107
122
108
while ( BaseScanner . _checkIsIn ( curChar , spaceChars ) ) {
123
109
this . _advance ( ) ;
124
110
curChar = this . getCurChar ( ) ;
111
+ // Compatible with windows line break CRLF.
112
+ if ( includeLineBreak && curChar === "\n" ) {
113
+ this . _advance ( ) ;
114
+ curChar = this . getCurChar ( ) ;
115
+ }
125
116
}
126
117
}
127
118
@@ -131,7 +122,11 @@ export default class BaseScanner {
131
122
const start = this . getCurPosition ( ) ;
132
123
this . advance ( 2 ) ;
133
124
// single line comments
134
- while ( this . getCurChar ( ) !== "\n" && ! this . isEnd ( ) ) this . _advance ( ) ;
125
+ let curChar = this . getCurChar ( ) ;
126
+ while ( curChar !== "\n" && curChar !== "\r" && ! this . isEnd ( ) ) {
127
+ this . _advance ( ) ;
128
+ curChar = this . getCurChar ( ) ;
129
+ }
135
130
this . skipCommentsAndSpace ( ) ;
136
131
return ShaderLab . createRange ( start , this . getCurPosition ( ) ) ;
137
132
} else if ( this . peek ( 2 ) === "/*" ) {
0 commit comments