Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zpwebbear
Copy link

@zpwebbear zpwebbear commented Dec 5, 2024

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fix)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

@zpwebbear zpwebbear mentioned this pull request Dec 5, 2024
4 tasks
Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

interpret() {
if (!(this.value in BooleanExpression.tokens)) {
Copy link
Member

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

Comment on lines 5 to 9
class BooleanExpression {
static tokens = {
t: true,
nil: false,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class BooleanExpression {
static tokens = {
t: true,
nil: false,
};
const BOOL = {
t: true,
nil: false,
};
class BooleanExpression {

@zpwebbear
Copy link
Author

@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 😄

if (!(value in BOOL)) {
throw new Error(`Unknown boolean value: ${value}`);
}
this.value = value;
Copy link
Member

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
Comment on lines 37 to 43
const expressionFactory = (token) => {
if (!isNaN(token)) return new NumberExpression(token);
if (token in BOOL) {
return new BooleanExpression(token);
}
return new VariableExpression(token);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection instead of ifs

Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants