mirror of
https://github.com/chenasraf/search-ast-parser-js.git
synced 2026-05-18 01:49:07 +00:00
fix(lexer): stall on bad characters
This commit is contained in:
@@ -51,8 +51,8 @@ const result = [
|
|||||||
|
|
||||||
**Input:** `(mango banana lemon) OR apple -pineapple`
|
**Input:** `(mango banana lemon) OR apple -pineapple`
|
||||||
|
|
||||||
**Explanation:** One of the word: "mango", "banana", "lemon" OR "apple"; exclude all results
|
**Explanation:** Either one of the words: "mango", "banana", or "lemon"; OR the word "apple";
|
||||||
containing "pineapple"
|
exclude all results containing "pineapple"
|
||||||
|
|
||||||
**Output**:
|
**Output**:
|
||||||
|
|
||||||
@@ -108,7 +108,8 @@ This is the comprehensive list of operators and their object results:
|
|||||||
- **Word:** `example`
|
- **Word:** `example`
|
||||||
|
|
||||||
Any single word. Only alpha-numeric characters, dashes and underscores are considered a word. The
|
Any single word. Only alpha-numeric characters, dashes and underscores are considered a word. The
|
||||||
rest is ignored.
|
rest is considered whitespace, which is ignored by the parser, but will cause the surrounding
|
||||||
|
tokens to be broken apart.
|
||||||
|
|
||||||
**Object:**
|
**Object:**
|
||||||
|
|
||||||
|
|||||||
18
src/lexer.ts
18
src/lexer.ts
@@ -110,11 +110,7 @@ export class Lexer implements ILexer {
|
|||||||
case lexerState.default:
|
case lexerState.default:
|
||||||
// whitespace
|
// whitespace
|
||||||
if (this.isWhitespace(nextChar)) {
|
if (this.isWhitespace(nextChar)) {
|
||||||
this.afterWhitespace = true
|
return this.consumeWhitespace()
|
||||||
return {
|
|
||||||
value: this.reader.consume(),
|
|
||||||
token: LexerToken.whitespace,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// quote
|
// quote
|
||||||
@@ -154,8 +150,8 @@ export class Lexer implements ILexer {
|
|||||||
return this.consumeGroup()
|
return this.consumeGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// other, consume normally
|
// other, consider as whitespace
|
||||||
return this.consumeWord()
|
return this.consumeWhitespace()
|
||||||
case lexerState.inPhrase:
|
case lexerState.inPhrase:
|
||||||
this.afterWhitespace = false
|
this.afterWhitespace = false
|
||||||
|
|
||||||
@@ -172,6 +168,14 @@ export class Lexer implements ILexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private consumeWhitespace() {
|
||||||
|
this.afterWhitespace = true
|
||||||
|
return {
|
||||||
|
value: this.reader.consume(),
|
||||||
|
token: LexerToken.whitespace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private consumeQuote(): LexerTokenValue {
|
private consumeQuote(): LexerTokenValue {
|
||||||
return {
|
return {
|
||||||
value: this.reader.consume(),
|
value: this.reader.consume(),
|
||||||
|
|||||||
Reference in New Issue
Block a user