diff --git a/src/riscript.js b/src/riscript.js index 3ef75a2..d531dfb 100644 --- a/src/riscript.js +++ b/src/riscript.js @@ -87,6 +87,7 @@ class RiScript { this.RawAssignRE = new RegExp(`^[${anysym}][A-Za-z_0-9][A-Za-z_0-9]*\\s*=`); this.ChoiceWrapRE = new RegExp('^' + open + '[^' + open + close + ']*' + close + '$'); + this.EntityRE = tokens.modes.normal.filter(t => t.name === 'Entity')[0].PATTERN; this.SpecialRE = new RegExp(`[${this.Escaped.SPECIAL.replace('&', '')}]`); this.ContinueRE = new RegExp(this.Escaped.CONTINUATION + '\\r?\\n', 'g'); this.WhitespaceRE = /[\u00a0\u2000-\u200b\u2028-\u2029\u3000]+/g; diff --git a/src/tokens.js b/src/tokens.js index 66ee8cc..582180a 100644 --- a/src/tokens.js +++ b/src/tokens.js @@ -36,6 +36,7 @@ function getTokens(v2Compatible) { const Escaped = {}; Object.entries(Symbols).forEach(([k, v]) => { Escaped[k] = escapeRegex(v) }); + const ENTITY_PATTERN = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/i; const PENDING_GATE_PATTERN = new RegExp(`${Escaped.PENDING_GATE}([0-9]{9,11})`) Escaped.SPECIAL = Object.values(Escaped).join('').replace(/[<>]/g, ''); // allow <>& for html @@ -74,7 +75,7 @@ function getTokens(v2Compatible) { const CS = createToken({ name: "CS", pattern: new RegExp(`\\s*${Escaped.CLOSE_SILENT}`) }); const SYM = createToken({ name: "SYM", pattern: new RegExp(`[${Escaped.DYNAMIC}${Escaped.STATIC}][A-Za-z_0-9]*`) }); - const Entity = createToken({ name: "Entity", pattern: /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/i }); + const Entity = createToken({ name: "Entity", pattern: ENTITY_PATTERN }); const Weight = createToken({ name: "Weight", pattern: new RegExp(`\\s*${Escaped.OPEN_WEIGHT}.+${Escaped.CLOSE_WEIGHT}\\s*`) }); const Raw = createToken({ name: "Raw", pattern: new RegExp(`[^${Escaped.SPECIAL}]+`) });