style: no punctuation or capitalization in errors
This commit is contained in:
@@ -24,9 +24,9 @@ func ParseOptions() (*Options, error) {
|
|||||||
|
|
||||||
// Parse non-flag arguments.
|
// Parse non-flag arguments.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
return nil, fmt.Errorf("No input given.")
|
return nil, fmt.Errorf("no input given")
|
||||||
} else if flag.NArg() > 1 {
|
} else if flag.NArg() > 1 {
|
||||||
return nil, fmt.Errorf("More than 1 command-line argument.")
|
return nil, fmt.Errorf("more than 1 command-line argument")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Options{
|
return &Options{
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ func FromArgs() (*Config, error) {
|
|||||||
|
|
||||||
// Parse non-flag arguments.
|
// Parse non-flag arguments.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
return nil, fmt.Errorf("No input given.")
|
return nil, fmt.Errorf("no input given")
|
||||||
} else if flag.NArg() > 1 {
|
} else if flag.NArg() > 1 {
|
||||||
return nil, fmt.Errorf("More than 1 command-line argument.")
|
return nil, fmt.Errorf("more than 1 command-line argument")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse source type.
|
// Parse source type.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func (i Iterator[T]) Peek() (T, error) {
|
|||||||
var null T
|
var null T
|
||||||
|
|
||||||
if i.IsDone() {
|
if i.IsDone() {
|
||||||
return null, fmt.Errorf("Iterator is exhausted.")
|
return null, fmt.Errorf("iterator is exhausted")
|
||||||
}
|
}
|
||||||
|
|
||||||
return i.data[i.index], nil
|
return i.data[i.index], nil
|
||||||
|
|||||||
+11
-11
@@ -11,37 +11,37 @@ import (
|
|||||||
func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression, error) {
|
func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression, error) {
|
||||||
token, err := i.Next()
|
token, err := i.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not get next token: %w", err)
|
return nil, fmt.Errorf("could not get next token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch token.Type {
|
switch token.Type {
|
||||||
case tokenizer.TokenVariable:
|
case tokenizer.TokenVariable:
|
||||||
return lambda.NewVariable(token.Value), nil
|
return lambda.NewVariable(token.Value), nil
|
||||||
case tokenizer.TokenDot:
|
case tokenizer.TokenDot:
|
||||||
return nil, fmt.Errorf("Token '.' found without a corresponding slash (column %d).", token.Index)
|
return nil, fmt.Errorf("token '.' found without a corresponding slash (column %d)", token.Index)
|
||||||
case tokenizer.TokenSlash:
|
case tokenizer.TokenSlash:
|
||||||
atoms := []string{}
|
atoms := []string{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
atom, atom_err := i.Next()
|
atom, atom_err := i.Next()
|
||||||
if atom_err != nil {
|
if atom_err != nil {
|
||||||
return nil, fmt.Errorf("Could not find parameter or terminator of function: %w", atom_err)
|
return nil, fmt.Errorf("could not find parameter or terminator of function: %w", atom_err)
|
||||||
} else if atom.Type == tokenizer.TokenVariable {
|
} else if atom.Type == tokenizer.TokenVariable {
|
||||||
atoms = append(atoms, atom.Value)
|
atoms = append(atoms, atom.Value)
|
||||||
} else if atom.Type == tokenizer.TokenDot {
|
} else if atom.Type == tokenizer.TokenDot {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Expected function parameter or terminator, got '%v' (column %d).", atom.Value, atom.Index)
|
return nil, fmt.Errorf("expected function parameter or terminator, got '%v' (column %d)", atom.Value, atom.Index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(atoms) == 0 {
|
if len(atoms) == 0 {
|
||||||
return nil, fmt.Errorf("Every function must have atleast one parameter (column %d)", token.Index)
|
return nil, fmt.Errorf("every function must have atleast one parameter (column %d)", token.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, body_err := ParseExpression(i)
|
body, body_err := ParseExpression(i)
|
||||||
if body_err != nil {
|
if body_err != nil {
|
||||||
return nil, fmt.Errorf("Could not parse function body: %w", body_err)
|
return nil, fmt.Errorf("could not parse function body: %w", body_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -54,7 +54,7 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
case tokenizer.TokenOpenParen:
|
case tokenizer.TokenOpenParen:
|
||||||
fn, fn_err := ParseExpression(i)
|
fn, fn_err := ParseExpression(i)
|
||||||
if fn_err != nil {
|
if fn_err != nil {
|
||||||
return nil, fmt.Errorf("Could not parse call function: %w", fn_err)
|
return nil, fmt.Errorf("could not parse call function: %w", fn_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []lambda.Expression{}
|
args := []lambda.Expression{}
|
||||||
@@ -66,7 +66,7 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
|
|
||||||
arg, arg_err := ParseExpression(i)
|
arg, arg_err := ParseExpression(i)
|
||||||
if arg_err != nil {
|
if arg_err != nil {
|
||||||
return nil, fmt.Errorf("Could not parse call argument: %w", arg_err)
|
return nil, fmt.Errorf("could not parse call argument: %w", arg_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, arg)
|
args = append(args, arg)
|
||||||
@@ -76,7 +76,7 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
if close_err != nil {
|
if close_err != nil {
|
||||||
return nil, fmt.Errorf("Could not parse call terminating parenthesis: %w", close_err)
|
return nil, fmt.Errorf("Could not parse call terminating parenthesis: %w", close_err)
|
||||||
} else if close.Type != tokenizer.TokenCloseParen {
|
} else if close.Type != tokenizer.TokenCloseParen {
|
||||||
return nil, fmt.Errorf("Expected call terminating parenthesis, got '%v' (column %v).", close.Value, close.Index)
|
return nil, fmt.Errorf("expected call terminating parenthesis, got '%v' (column %v)", close.Value, close.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -87,9 +87,9 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
case tokenizer.TokenCloseParen:
|
case tokenizer.TokenCloseParen:
|
||||||
return nil, fmt.Errorf("Token ')' found without a corresponding openning parenthesis (column %d).", token.Index)
|
return nil, fmt.Errorf("token ')' found without a corresponding openning parenthesis (column %d)", token.Index)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unknown token '%v' (column %d).", token.Value, token.Index)
|
return nil, fmt.Errorf("unknown token '%v' (column %d)", token.Value, token.Index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user