Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪲 Fix highlighting of keywords with spaces #5190

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/js/lezer-parsers/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ export function initializeTranslation(options: InitializeCodeMirrorSyntaxHighlig

export function specializeKeyword(name: string, stack: Stack) {
for (const [key, value] of specializeTranslations) {
const regexString = value.replace(' ', '|');
const regexString = value.replace(/ /g, '|');
if (new RegExp(`^(${regexString})$`, 'gu').test(name)) {
if (stack.canShift(keywordToToken[level].specialize[key])) {
return keywordToToken[level].specialize[key];
Expand All @@ -723,7 +723,7 @@ export function specializeKeyword(name: string, stack: Stack) {

export function extendKeyword(name: string, stack: Stack) {
for (const [key, value] of extendTranslations) {
const regexString = value.replace(' ', '|');
const regexString = value.replace(/ /g, '|');
if (new RegExp(`^(${regexString})$`, 'gu').test(name)) {
if (stack.canShift(keywordToToken[level].extend[key])) {
return keywordToToken[level].extend[key];
Expand Down
16 changes: 16 additions & 0 deletions tests/cypress/e2e/lezer-tests/level_05.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ describe('Lezer parser tests for level 5', () => {

multiLevelTester('Test if text not in list print', code, expectedTree, 5, 7);
})

describe('Test if text not in spanish, but using english keyword', () => {
const code = `si text not in list imprimir 'in'`
const expectedTree =
`Program(
Command(
If(
if,
Condition(NotInListCheck(Text,not_in,not_in,Text)),
IfLessCommand(Print(print,String))
)
)
)`

multiLevelTester('Test if text not in list print', code, expectedTree, 5, 7, 'es');
})
});
});
})
Loading