style: no underscores in variable names
This commit is contained in:
@@ -5,8 +5,8 @@ func ReduceOnce(e *Expression) bool {
|
|||||||
case *Abstraction:
|
case *Abstraction:
|
||||||
return ReduceOnce(&typed.Body)
|
return ReduceOnce(&typed.Body)
|
||||||
case *Application:
|
case *Application:
|
||||||
fn, fn_ok := typed.Abstraction.(*Abstraction)
|
fn, fnOk := typed.Abstraction.(*Abstraction)
|
||||||
if fn_ok {
|
if fnOk {
|
||||||
Substitute(&fn.Body, fn.Parameter, typed.Argument)
|
Substitute(&fn.Body, fn.Parameter, typed.Argument)
|
||||||
*e = fn.Body
|
*e = fn.Body
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ func Substitute(e *Expression, target string, replacement Expression) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
replacement_free_vars := GetFreeVariables(replacement)
|
replacementFreeVars := GetFreeVariables(replacement)
|
||||||
if !replacement_free_vars.Has(typed.Parameter) {
|
if !replacementFreeVars.Has(typed.Parameter) {
|
||||||
Substitute(&typed.Body, target, replacement)
|
Substitute(&typed.Body, target, replacement)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
used := GetFreeVariables(typed.Body)
|
used := GetFreeVariables(typed.Body)
|
||||||
used.Union(replacement_free_vars)
|
used.Union(replacementFreeVars)
|
||||||
fresh_var := GenerateFreshName(used)
|
freshVar := GenerateFreshName(used)
|
||||||
Rename(typed, typed.Parameter, fresh_var)
|
Rename(typed, typed.Parameter, freshVar)
|
||||||
Substitute(&typed.Body, target, replacement)
|
Substitute(&typed.Body, target, replacement)
|
||||||
case *Application:
|
case *Application:
|
||||||
Substitute(&typed.Abstraction, target, replacement)
|
Substitute(&typed.Abstraction, target, replacement)
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
atoms := []string{}
|
atoms := []string{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
atom, atom_err := i.Next()
|
atom, atomErr := i.Next()
|
||||||
if atom_err != nil {
|
if atomErr != 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", atomErr)
|
||||||
} 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 {
|
||||||
@@ -39,9 +39,9 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
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, bodyErr := ParseExpression(i)
|
||||||
if body_err != nil {
|
if bodyErr != nil {
|
||||||
return nil, fmt.Errorf("could not parse function body: %w", body_err)
|
return nil, fmt.Errorf("could not parse function body: %w", bodyErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -52,29 +52,29 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
case tokenizer.TokenOpenParen:
|
case tokenizer.TokenOpenParen:
|
||||||
fn, fn_err := ParseExpression(i)
|
fn, fnErr := ParseExpression(i)
|
||||||
if fn_err != nil {
|
if fnErr != nil {
|
||||||
return nil, fmt.Errorf("could not parse call function: %w", fn_err)
|
return nil, fmt.Errorf("could not parse call function: %w", fnErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []lambda.Expression{}
|
args := []lambda.Expression{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if next, next_err := i.Peek(); next_err == nil && next.Type == tokenizer.TokenCloseParen {
|
if next, nextErr := i.Peek(); nextErr == nil && next.Type == tokenizer.TokenCloseParen {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
arg, arg_err := ParseExpression(i)
|
arg, argErr := ParseExpression(i)
|
||||||
if arg_err != nil {
|
if argErr != nil {
|
||||||
return nil, fmt.Errorf("could not parse call argument: %w", arg_err)
|
return nil, fmt.Errorf("could not parse call argument: %w", argErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, arg)
|
args = append(args, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
close, close_err := i.Next()
|
close, closeErr := i.Next()
|
||||||
if close_err != nil {
|
if closeErr != 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", closeErr)
|
||||||
} 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user