-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
159 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import { expect } from "chai" | ||
const tokenMatcher = require("chevrotain").tokenMatcher | ||
const lex = require("./step1_lexing").lex | ||
const tokenVocabulary = require("./step1_lexing").tokenVocabulary | ||
import { tokenMatcher } from "chevrotain" | ||
import { From, lex, Select, Identifier, From } from "./step1_lexing.js" | ||
|
||
describe("Chevrotain Tutorial", () => { | ||
context("Step 1 - Lexing", () => { | ||
it("Can Lex a simple input", () => { | ||
let inputText = "SELECT column1 FROM table2" | ||
let lexingResult = lex(inputText) | ||
const inputText = "SELECT column1 FROM table2" | ||
const lexingResult = lex(inputText) | ||
|
||
expect(lexingResult.errors).to.be.empty | ||
|
||
let tokens = lexingResult.tokens | ||
const tokens = lexingResult.tokens | ||
expect(tokens).to.have.lengthOf(4) | ||
expect(tokens[0].image).to.equal("SELECT") | ||
expect(tokens[1].image).to.equal("column1") | ||
expect(tokens[2].image).to.equal("FROM") | ||
expect(tokens[3].image).to.equal("table2") | ||
|
||
// tokenMatcher acts as an "instanceof" check for Tokens | ||
expect(tokenMatcher(tokens[0], tokenVocabulary.Select)).to.be.true | ||
expect(tokenMatcher(tokens[1], tokenVocabulary.Identifier)).to.be.true | ||
expect(tokenMatcher(tokens[2], tokenVocabulary.From)).to.be.true | ||
expect(tokenMatcher(tokens[3], tokenVocabulary.Identifier)).to.be.true | ||
expect(tokenMatcher(tokens[0], Select)).to.be.true | ||
expect(tokenMatcher(tokens[1], Identifier)).to.be.true | ||
expect(tokenMatcher(tokens[2], From)).to.be.true | ||
expect(tokenMatcher(tokens[3], Identifier)).to.be.true | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.