Repository: goby-lang/goby (go)

Issue:
Positive unary operator like `+1` unhandled
When fixing #526, I also found that the positive unary operator like `+1` are treated as invalid:

```ruby
» -1
#» -1
» +1
unexpected + Line: 0
» +1
```

I'd like to fix this as well when fixing #526 and then close this issue.

Pull request description:
Fix #555
This closes #555 

Patch:
diff --git a/compiler/bytecode/expression_generation.go b/compiler/bytecode/expression_generation.go
index 057b022..69b3b9f 100644
--- a/compiler/bytecode/expression_generation.go
+++ b/compiler/bytecode/expression_generation.go
@@ -244,6 +244,8 @@ func (g *Generator) compilePrefixExpression(is *InstructionSet, exp *ast.PrefixE
 		is.define(PutObject, exp.Line(), 0)
 		g.compileExpression(is, exp.Right, scope, table)
 		is.define(Send, exp.Line(), exp.Operator, 1, "", &ArgSet{})
+	case "+":
+		g.compileExpression(is, exp.Right, scope, table)
 	}
 }
 
diff --git a/compiler/parser/parser.go b/compiler/parser/parser.go
index 3e3693a..6ed4441 100644
--- a/compiler/parser/parser.go
+++ b/compiler/parser/parser.go
@@ -70,6 +70,7 @@ func New(l *lexer.Lexer) *Parser {
 	p.registerPrefix(token.False, p.parseBooleanLiteral)
 	p.registerPrefix(token.Null, p.parseNilExpression)
 	p.registerPrefix(token.Minus, p.parsePrefixExpression)
+	p.registerPrefix(token.Plus, p.parsePrefixExpression)
 	p.registerPrefix(token.Asterisk, p.parsePrefixExpression)
 	p.registerPrefix(token.Bang, p.parsePrefixExpression)
 	p.registerPrefix(token.LParen, p.parseGroupedExpression)


Test patch:
diff --git a/compiler/parser/expression_parsing_test.go b/compiler/parser/expression_parsing_test.go
index 84b4171..e44a034 100644
--- a/compiler/parser/expression_parsing_test.go
+++ b/compiler/parser/expression_parsing_test.go
@@ -698,7 +698,8 @@ func TestArithmeticExpressionFail(t *testing.T) {
 		input string
 		error string
 	}{
-		{`{ 1 ++ 1 }`, `unexpected + Line: 0`},
+		{`{ 1 ++ 1 }`, `expected next token to be }, got +(+) instead. Line: 0`},
+		{`{ 1 -- 1 }`, `expected next token to be }, got -(-) instead. Line: 0`},
 		{`{ 1 * * 1 }`, `unexpected * Line: 0`},
 		{`{ 1 ** [1, 2] }`, `expected next token to be }, got **(**) instead. Line: 0`},
 	}
diff --git a/vm/evaluation_test.go b/vm/evaluation_test.go
index e6c6dd9..d2369a9 100644
--- a/vm/evaluation_test.go
+++ b/vm/evaluation_test.go
@@ -2242,6 +2242,26 @@ func TestMinusPrefixMethodCall(t *testing.T) {
 	}
 }
 
+func TestPlusPrefixMethodCall(t *testing.T) {
+	tests := []struct {
+		input    string
+		expected int
+	}{
+		{"+5", 5},
+		{"+10", 10},
+		{"+(-10)", -10},
+		{"+(-5)", -5},
+	}
+
+	for i, tt := range tests {
+		v := initTestVM()
+		evaluated := v.testEval(t, tt.input, getFilename())
+		VerifyExpected(t, i, evaluated, tt.expected)
+		v.checkCFP(t, i, 0)
+		v.checkSP(t, i, 1)
+	}
+}
+
 func TestMultiVarAssignment(t *testing.T) {
 	tests := []struct {
 		input    string