fix: properly treat unicode blanks, fixes #221

This commit is contained in:
harttle
2020-04-28 20:55:30 +08:00
parent 2fa4edaa84
commit 673b015435
3 changed files with 27 additions and 4 deletions
+9 -2
View File
@@ -5,9 +5,11 @@ const isOperator = c => '!=<>'.includes(c)
const isNumber = c => c >= '0' && c <= '9'
const isCharacter = c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
const isVariable = c => '_-?'.includes(c) || isCharacter(c) || isNumber(c)
const isBlank = c => c === '\n' || c === '\t' || c === ' ' || c === '\r'
const isBlank = c => c === '\n' || c === '\t' || c === ' ' || c === '\r' || c === '\v' || c === '\f'
const isInlineBlank = c => c === '\t' || c === ' ' || c === '\r'
const isSign = c => c === '-' || c === '+'
// See https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp
const unicodeBlanks = '\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000'
const types = []
for (let i = 0; i < 128; i++) {
@@ -22,9 +24,12 @@ for (let i = 0; i < 128; i++) {
if (isSign(c)) n |= 64
types.push(n)
}
console.log(`
// **DO NOT CHANGE THIS FILE**
//
// This file is generated by bin/character-gen.js
// bitmask character types to boost performance
// generated by bin/character-gen.js
export const TYPES = [${types.join(', ')}]
export const VARIABLE = 1
export const OPERATOR = 2
@@ -34,3 +39,5 @@ export const INLINE_BLANK = 16
export const NUMBER = 32
export const SIGN = 64
`.trim())
console.log([...unicodeBlanks].map(char => `TYPES[${char.charCodeAt(0)}]`).join(' = ') + ' = BLANK')