Skip to content

Commit

Permalink
fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 8, 2020
1 parent e0c5164 commit eb4a236
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ export class Parser {
};
}

private _parseNumberLiteral(): NumberNode | LiteralNode | undefined {
let tk = this._accept(TokenType.Number);
if (!tk) {
return undefined;
}

let value = this._scanner.value(tk);
let end = tk.end;
while (this._token.type !== TokenType.Whitespace && this._token.type !== TokenType.EOF) {
value += this._scanner.value(this._token);
end = this._token.end;
this._accept(this._token.type);
}

if (end === tk.end) {
// didnt move forward
return {
_type: NodeType.Number,
start: tk.start,
end,
value: Number(this._scanner.value(tk))
};
}

return {
_type: NodeType.Literal,
start: tk.start,
end,
value
};
}

private _parseNumber(): NumberNode | undefined {
const tk = this._accept(TokenType.Number);
if (!tk) {
Expand Down Expand Up @@ -255,15 +287,17 @@ export class Parser {
};
}

private _parseRangeFixedStart(): RangeNode | DateNode | NumberNode | undefined {
private _parseRangeFixedStart(): RangeNode | undefined {
// value..*
const anchor = this._token;
const value = this._parseDate() ?? this._parseNumber();
if (!value) {
return;
}
const token = this._accept(TokenType.RangeFixedStart);
if (!token) {
return value;
this._reset(anchor);
return undefined;
}
return {
_type: NodeType.Range,
Expand All @@ -290,7 +324,7 @@ export class Parser {
?? this._parseRangeFixedStart()
?? this._parseRangeFixedEnd()
?? this._parseDate()
?? this._parseNumber()
?? this._parseNumberLiteral()
?? this._parseVariableName()
?? this._parseLiteral()
?? this._parseAny(TokenType.SHA)
Expand Down
4 changes: 4 additions & 0 deletions src/test-unit/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ suite('Parser', function () {
assertNodeTypes('label:foo sort:comments-asc sortby', NodeType.QualifiedValue, NodeType.Literal);
assertNodeTypesDeep('label:123 sort:comments-asc', NodeType.Query, NodeType.QualifiedValue, NodeType.Literal, NodeType.Number, NodeType.QualifiedValue, NodeType.Literal, NodeType.Literal);
});

test('Bad diagnostics on my milestone query #35', function () {
assertNodeTypes('milestone:4.7.0', NodeType.QualifiedValue);
});
});


Expand Down

0 comments on commit eb4a236

Please sign in to comment.