-
Notifications
You must be signed in to change notification settings - Fork 1
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
Daniel Berezin
committed
May 2, 2019
1 parent
2477ba4
commit 2fd7388
Showing
15 changed files
with
249 additions
and
202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
bracketSpacing: true, | ||
insertPragma: false, | ||
parser: 'babel', | ||
printWidth: 100, | ||
proseWrap: 'preserve', | ||
requirePragma: false, | ||
semi: false, | ||
singleQuote: true, | ||
tabWidth: 2, | ||
useTabs: false | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 +1,45 @@ | ||
const tokenizer = require('./tokenizer') | ||
const token = tokenizer.tokenEnum | ||
|
||
const nullable = str => str ? str : '' | ||
const nullable = str => (str ? str : '') | ||
|
||
class LoxError { | ||
constructor (msg, startCoordinates, endCoordinates) { | ||
constructor(msg, startCoordinates, endCoordinates) { | ||
this.msg = msg | ||
this.startCoordinates = startCoordinates | ||
this.endCoordinates = endCoordinates | ||
} | ||
|
||
toString () { | ||
toString() { | ||
return this.msg | ||
} | ||
} | ||
|
||
const error = (msg, startCoordinates, endCoordinates) => | ||
new LoxError(msg, startCoordinates, endCoordinates ) | ||
new LoxError(msg, startCoordinates, endCoordinates) | ||
|
||
const parseError = (msg, token) => { | ||
if (token.type === token.EOF) { | ||
return new LoxError(msg, token.startCoordinates, token.endCoordinates) | ||
} else { | ||
return new LoxError(`${nullable(token.lexeme && `at "${token.lexeme}": `)}${msg}`, token.startCoordinates, token.endCoordinates) | ||
return new LoxError( | ||
`${nullable(token.lexeme && `at "${token.lexeme}": `)}${msg}`, | ||
token.startCoordinates, | ||
token.endCoordinates | ||
) | ||
} | ||
} | ||
|
||
const runtimeError = (msg, token) => | ||
new LoxError(`${nullable(token.lexeme && `at "${token.lexeme}": `)}${msg}`, token.startCoordinates, token.endCoordinates) | ||
new LoxError( | ||
`${nullable(token.lexeme && `at "${token.lexeme}": `)}${msg}`, | ||
token.startCoordinates, | ||
token.endCoordinates | ||
) | ||
|
||
module.exports = { | ||
error, | ||
LoxError, | ||
runtimeError, | ||
parseError | ||
} | ||
} |
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.