Skip to content

Commit

Permalink
Address test failures
Browse files Browse the repository at this point in the history
Change some test expectations to expect a unary minus expression.

Change the parsing of ->>-9 and of SET TIMEZONE -9 to convert the unary minus expression to a negative integer.
  • Loading branch information
gthb committed Feb 27, 2024
1 parent 4bf7ac8 commit 995c538
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/lexer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,18 @@ describe('Lexer', () => {
next({ type: 'comma' });
next({ type: 'float', value: '.1' });
next({ type: 'comma' });
next({ type: 'float', value: '-.1' });
next({ type: 'op_minus' });
next({ type: 'float', value: '.1' });
next({ type: 'comma' });
next({ type: 'float', value: '-0.1' });
next({ type: 'op_minus' });
next({ type: 'float', value: '0.1' });
next({ type: 'comma' });
next({ type: 'float', value: '0.1' });
next({ type: 'comma' });
next({ type: 'float', value: '10.' });
next({ type: 'comma' });
next({ type: 'float', value: '-10.' });
next({ type: 'op_minus' });
next({ type: 'float', value: '10.' });
})

it('tokenizes ->', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/syntax/expr.ne
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ expr_array_index
| expr_member {% unwrap %}

expr_member
-> (expr_member | expr_paren) ops_member (string | int) {% x => track(x, {
-> (expr_member | expr_paren) ops_member %op_minus int {% x => track(x, {
type: 'member',
operand: unwrap(x[0]),
op: x[1],
member: -unwrap(x[3])
}) %}
| (expr_member | expr_paren) ops_member (string | int) {% x => track(x, {
type: 'member',
operand: unwrap(x[0]),
op: x[1],
Expand Down
29 changes: 24 additions & 5 deletions src/syntax/expr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,37 @@ describe('Expressions', () => {
});

checkTreeExpr(['-0.5', '-.5'], {
type: 'numeric',
value: -0.5,
type: 'unary',
op: '-',
operand: {
type: 'numeric',
value: 0.5,
}
});

checkTreeExpr(['-42.', '-42.0'], {
type: 'numeric',
value: -42,
type: 'unary',
op: '-',
operand: {
type: 'numeric',
value: 42,
}
});

checkInvalidExpr('42. 51');

checkInvalidExpr('42.-51');
checkTreeExpr(['42.-51'], {
type: 'binary',
op: '-',
left: {
type: 'numeric',
value: 42,
},
right: {
type: 'integer',
value: 51,
},
});

checkTreeExprLoc(['null'], {
_location: { start: 0, end: 4 },
Expand Down
1 change: 1 addition & 0 deletions src/syntax/simple-statements.ne
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ simplestatements_set_timezone -> kw_time kw_zone simplestatements_set_timezone_v

simplestatements_set_timezone_val
-> (string | int) {% x => track(x, { type: 'value', value: unwrap(x[0]) }) %}
| %op_minus int {% x => track(x, { type: 'value', value: -unwrap(x[1]) }) %}
| kw_local {% x => track(x, { type: 'local'}) %}
| %kw_default {% x => track(x, { type: 'default'}) %}
| kw_interval string kw_hour %kw_to kw_minute {% x => track(x, { type: 'interval', value: unbox(x[1]) }) %}
Expand Down

0 comments on commit 995c538

Please sign in to comment.