-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Expressions): add boolean symbols #12
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/expressions.js
Outdated
} | ||
|
||
interpret() { | ||
if (!(this.value in BooleanExpression.tokens)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to check it in constructor
lib/expressions.js
Outdated
class BooleanExpression { | ||
static tokens = { | ||
t: true, | ||
nil: false, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class BooleanExpression { | |
static tokens = { | |
t: true, | |
nil: false, | |
}; | |
const BOOL = { | |
t: true, | |
nil: false, | |
}; | |
class BooleanExpression { |
@tshemsedinov I've provided changes that you've highlighted. The single question that I want to ask is about CHANGELOG. I don't know what to write in this file 😄 |
lib/expressions.js
Outdated
if (!(value in BOOL)) { | ||
throw new Error(`Unknown boolean value: ${value}`); | ||
} | ||
this.value = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can store value
as javascript boolean type, receiving either js boolean or t/nil
lib/parser.js
Outdated
const expressionFactory = (token) => { | ||
if (!isNaN(token)) return new NumberExpression(token); | ||
if (token in BOOL) { | ||
return new BooleanExpression(token); | ||
} | ||
return new VariableExpression(token); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collection instead of if
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have .type field in all Expressions instead of slow instanceof
Additionly type field was added to all Expression classes Refs: metarhia#5
npm t
)npm run fix
)