diff options
Diffstat (limited to 'index.html')
| -rw-r--r-- | index.html | 59 |
1 files changed, 37 insertions, 22 deletions
@@ -88,7 +88,7 @@ </a> </div> <script> - if ('serviceWorker' in navigator) { + if ('serviceWorker' in navigator && location.hostname !== 'local.com') { window.addEventListener('load', () => { navigator.serviceWorker.register('/serviceWorker.js') .then(reg => console.log('sw registered')) @@ -350,34 +350,48 @@ } function validateSymbols(text, symbols) { - const usagePattern = /\\([^\\\s]+)\\/g - const usedSymbols = new Set() - let match + const definedSymbols = new Set() + const missing = new Map() + const lines = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n') - while ((match = usagePattern.exec(text)) !== null) { - usedSymbols.add(match[1]) - } + lines.forEach((rawLine, index) => { + const lineNumber = index + 1 + let line = rawLine + let ignoreUsages = false - const definedSymbols = new Set() - const defPattern = /^def\s+(\S+)/gm + if (line.startsWith('<!>')) { + line = line.substring(3) + ignoreUsages = true + } - while ((match = defPattern.exec(text)) !== null) { - // console.log('defined:', match[1]) - definedSymbols.add(match[1].replace(/^\\/g, '').replace(/\\$/g, '')) - } + const defMatch = line.match(/^def\s+(\S+)/) + if (defMatch) { + definedSymbols.add(defMatch[1].replace(/^\\/g, '').replace(/\\$/g, '')) + } - const missing = [] - for (const name of usedSymbols) { - if (definedSymbols.has(name)) continue + if (ignoreUsages) return - const symbol = symbols[name] - if (symbol && definedSymbols.has(symbol)) continue + const usagePattern = /\\([^\\\s]+)\\/g + let match + while ((match = usagePattern.exec(line)) !== null) { + const name = match[1] + if (definedSymbols.has(name)) continue + if (symbols[name] && definedSymbols.has(symbols[name])) continue - missing.push(name) - } + if (!missing.has(name)) { + missing.set(name, []) + } + missing.get(name).push(lineNumber) + } + }) - if (missing.length > 0) { - const msg = `undefined symbols detected:\n${missing.map(s => ` • (${symbols[s]}) ${s}`).join('\n')}` + if (missing.size > 0) { + let msg = 'undefined symbols detected:' + for (const [name, lineNums] of missing) { + const symChar = symbols[name] || '?' + const linesStr = lineNums.join(', ') + msg += `\n • (${symChar}) ${name} [line${lineNums.length > 1 ? 's' : ''}: ${linesStr}]` + } warnings.innerHTML += msg.replace(/\n/g, '<br>') console.warn('undefined symbols:', missing) } else { @@ -393,6 +407,7 @@ let text = await response.text() validateSymbols(text, symbols) + text = text.replace(/((^|\n)<!> *)/g, (e) => e.replace(/<!> */g, '')) text = applySymbols(text, symbols) const parser = new TempoParser(text) |
