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

Refactor parsePrefixExpression, block some expressions #189 #191

Merged
merged 4 commits into from Jan 30, 2019

Conversation

u5surf
Copy link
Contributor

@u5surf u5surf commented Jan 24, 2019

resolved: #189

details: I added validation rules to block prefix ‘!‘ is not valid for StringLiteral.
and ‘-’ is also invalid for Boolean.

[task detail...]

  1. I added validations to block invalid prefix for some Literals.
  2. I fix the TestMakePrefix

Copy link
Member

@zeroFruit zeroFruit left a comment

Choose a reason for hiding this comment

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

First of all, thank you for contributing to our project! @u5surf 👍

Feedback

The logic is ok. But I think we can refactor and improve more.

  1. How about validating operation and right expression first, then create whole expression?
    The old code create whole expression first then filling the operation and right expression. I think after validating op and right expression then creates whole expression is more make sense.
func parsePrefixExpression(buf TokenBuffer) (ast.Expression, error) {
	tok := buf.Read()

	op := operatorMap[tok.Type]
	right, err := parseExpression(buf, PREFIX)

        // validating logic

	// create whole expression
}
  1. We can use switch instead of if. I think using switch can be more readable and scalable.
switch op {
case ast.Bang:
    ...
case ast.Minus:
    ...
}

and

switch right.(type) {
case *ast.BooleanLiteral:
    ...
case *ast.StringLiteral:    
    ...
}

@junbeomlee
Copy link
Member

Error has occurred !!

parse/parser.go:381:16: too few values in parseError literal
parse/parser.go:389:16: too few values in parseError literal

plz fix the error
you can check this in here https://travis-ci.org/DE-labtory/koa/builds/483891010?utm_source=github_status&utm_medium=notification

@junbeomlee
Copy link
Member

There is still an error in the code.
Could u check parse/parser.go: 381 lines and
389 line!

@u5surf
Copy link
Contributor Author

u5surf commented Jan 25, 2019

Oh, I got it, parseError has added some element imperceptibly!

@@ -367,16 +367,38 @@ func parseInfixExpression(buf TokenBuffer, left ast.Expression) (ast.Expression,
func parsePrefixExpression(buf TokenBuffer) (ast.Expression, error) {
var err error
Copy link
Member

Choose a reason for hiding this comment

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

I think this err is not needed

@junbeomlee junbeomlee merged commit 6b32692 into DE-labtory:develop Jan 30, 2019
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.

[parser] refactor parsePrefixExpression, block some expressions
3 participants