Skip to content

Commit 2664adb

Browse files
committed
Allow identifiers mix letters and numbers
1 parent eccd5ec commit 2664adb

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/views/config-wizard/parser/cw-option.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,36 @@ describe('CwOption', () => {
300300
expect(matched).toBeDefined();
301301
expect(matched?.description.getText()).toBe('PushPull');
302302
});
303+
304+
it('should match mixed alphanumeric identifier options correctly', () => {
305+
const option = new CwOption();
306+
option.addProperty(
307+
tokenizer.tokenizeCmd('o MACRO2', 1),
308+
tokenizer.tokenizeDescr('Role level', 1),
309+
1
310+
);
311+
312+
const opt1 = new CwOptionAssign(option);
313+
opt1.addProperty(
314+
tokenizer.tokenizeCmd('LEVEL_UNKNOWN=', 2),
315+
tokenizer.tokenizeDescr('LEVEL_UNKNOWN', 2),
316+
2
317+
);
318+
option.addOption(opt1);
319+
320+
const opt2 = new CwOptionAssign(option);
321+
opt2.addProperty(
322+
tokenizer.tokenizeCmd('LEVEL_3P1=', 3),
323+
tokenizer.tokenizeDescr('LEVEL_3P1', 3),
324+
3
325+
);
326+
option.addOption(opt2);
327+
328+
const textValue = new TextType('LEVEL_3P1');
329+
const matched = option.getOption(textValue);
330+
expect(matched).toBeDefined();
331+
expect(matched?.description.getText()).toBe('LEVEL_3P1');
332+
});
303333
});
304334

305335
describe('Edge cases', () => {

src/views/config-wizard/parser/tokenizer.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const res: result[] = [
4141
{ input: '// <BAR=> Bar',
4242
cmd: { text: 'BAR=', items: [ 'BAR', '=' ] },
4343
text: { text: 'Bar', items: [ 'Bar' ] } },
44+
{ input: '// <LEVEL_3P1=> Level 3P1',
45+
cmd: { text: 'LEVEL_3P1=', items: [ 'LEVEL_3P1', '=' ] },
46+
text: { text: 'Level 3P1', items: [ 'Level 3P1' ] } },
4447
{ input: '// <-7..-4:2>',
4548
cmd: { text: '-7..-4:2', items: [ '-7', '..', '-4', ':', '2' ] },
4649
text: { text: '', items: [ ] } },

src/views/config-wizard/parser/tokenizer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export class Tokenizer {
9090
return token;
9191
}
9292

93+
const isAssignmentToken = text.includes('=');
94+
9395
let canBeNegative = false;
9496
if (text.indexOf('..') != -1) {
9597
canBeNegative = true;
@@ -177,7 +179,7 @@ export class Tokenizer {
177179
let str = '';
178180
do {
179181
ch = text[pos++];
180-
if (!ch.match(/[a-z_]/i)) {
182+
if (!ch.match(isAssignmentToken ? /[a-z\d_]/i : /[a-z_]/i)) {
181183
pos--;
182184
break;
183185
}

0 commit comments

Comments
 (0)