Skip to content

Commit

Permalink
fix: if int sig call, keep in int mode
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Apr 18, 2024
1 parent 04a7a22 commit 445bc12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions __tests__/txt2bas.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,17 @@ test('in the wild', (t) => {
0,
'@ label with no space not misread as number'
);

src = '10 %x=%SGN{RND0}';
res = parseLines(src, { validate: false }).statements[0].tokens;
t.is(
res.filter((_) => _.name === 'NUMBER').length,
0,
'No numbers found in %SGN{RND0}'
);
t.is(
res.filter((_) => _.name === 'LITERAL_NUMBER').length,
1,
'Int 0 found in %SGN{RND0}'
);
});
12 changes: 11 additions & 1 deletion txt2bas/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
OPEN_BRACKETS,
MODIFIER,
STRING_EXPRESSION,
SGN_EXPRESSION,
} from './types.mjs';

/**
Expand Down Expand Up @@ -644,6 +645,9 @@ export class Statement {
}
}
if (token.value === '{') {
if (this.lastToken.text === 'SGN') {
this.in.push(SGN_EXPRESSION);
}
this.in.push(OPEN_BRACES);
}
if (token.value === '[') {
Expand All @@ -659,6 +663,9 @@ export class Statement {
}
if (token.value === '}') {
this.popTo(OPEN_BRACES);
if (this.isIn(SGN_EXPRESSION)) {
this.popTo(SGN_EXPRESSION);
}
}
if (token.value === ']') {
this.popTo(OPEN_BRACKETS);
Expand All @@ -679,7 +686,10 @@ export class Statement {
}

if (token.name === KEYWORD) {
if (this.inIntExpression && this.isIn(OPEN_PARENS)) {
if (
this.inIntExpression &&
(this.isIn(OPEN_PARENS) || this.isIn(SGN_EXPRESSION))
) {
// nop
} else if (this.inIntExpression && intFunctions[token.text]) {
// check if an int function was used
Expand Down
1 change: 1 addition & 0 deletions txt2bas/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export const OPEN_BRACES = 'OPEN_BRACES'; // {}
export const INT_PARENS = 'INT_PARENS';
export const MODIFIER = 'MODIFIER';
export const STRING_EXPRESSION = 'STRING_EXPRESSION';
export const SGN_EXPRESSION = 'SGN_EXPRESSION';

0 comments on commit 445bc12

Please sign in to comment.