File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
packages/langium/src/utils Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import type { AstNode, CstNode } from '../syntax-tree.js';
10
10
import { isCompositeCstNode } from '../syntax-tree.js' ;
11
11
import { getContainerOfType , streamAllContents } from './ast-utils.js' ;
12
12
import { streamCst } from './cst-utils.js' ;
13
- import { escapeRegExp } from './regexp-utils.js' ;
13
+ import { escapeRegExp , isWhitespace } from './regexp-utils.js' ;
14
14
15
15
/**
16
16
* Returns the entry rule of the given grammar, if any. If the grammar file does not contain an entry rule,
@@ -92,7 +92,7 @@ export function getCrossReferenceTerminal(crossRef: ast.CrossReference): ast.Abs
92
92
* that contains visible characters is considered a comment.
93
93
*/
94
94
export function isCommentTerminal ( terminalRule : ast . TerminalRule ) : boolean {
95
- return terminalRule . hidden && ! terminalRegex ( terminalRule ) . test ( ' ' ) ;
95
+ return terminalRule . hidden && ! isWhitespace ( terminalRegex ( terminalRule ) ) ;
96
96
}
97
97
98
98
/**
Original file line number Diff line number Diff line change @@ -138,9 +138,17 @@ export function isMultilineComment(regexp: RegExp | string): boolean {
138
138
}
139
139
}
140
140
141
+ /**
142
+ * A set of all characters that are considered whitespace by the '\s' RegExp character class.
143
+ * Taken from [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes).
144
+ */
145
+ export const whitespaceCharacters = (
146
+ '\f\n\r\t\v\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007' +
147
+ '\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff' ) . split ( '' ) ;
148
+
141
149
export function isWhitespace ( value : RegExp | string ) : boolean {
142
150
const regexp = typeof value === 'string' ? new RegExp ( value ) : value ;
143
- return regexp . test ( ' ' ) ;
151
+ return whitespaceCharacters . some ( ( ws ) => regexp . test ( ws ) ) ;
144
152
}
145
153
146
154
export function escapeRegExp ( value : string ) : string {
You can’t perform that action at this time.
0 commit comments