Use --fix argument of linters to auto fix as many issue as possible
This commit is contained in:
parent
3f554445d8
commit
5882897375
|
@ -37,7 +37,6 @@ func restOfExprs(es []IExpr, i int) []IExpr {
|
||||||
// evaluation of a list it will evaluate all the elements and return the
|
// evaluation of a list it will evaluate all the elements and return the
|
||||||
// evaluated list
|
// evaluated list
|
||||||
func evalForm(rt *Runtime, scope IScope, form IExpr) (IExpr, IError) {
|
func evalForm(rt *Runtime, scope IScope, form IExpr) (IExpr, IError) {
|
||||||
|
|
||||||
switch form.GetType() {
|
switch form.GetType() {
|
||||||
case ast.Nil:
|
case ast.Nil:
|
||||||
return form, nil
|
return form, nil
|
||||||
|
|
|
@ -177,7 +177,6 @@ func MakeFnScope(rt *Runtime, parent IScope, bindings IColl, values IColl) (*Sco
|
||||||
errors.E0002,
|
errors.E0002,
|
||||||
fmt.Sprintf("expected '%d' arguments, got '%d'.", bindings.Count(), values.Count()),
|
fmt.Sprintf("expected '%d' arguments, got '%d'.", bindings.Count(), values.Count()),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +199,6 @@ func MakeFnScope(rt *Runtime, parent IScope, bindings IColl, values IColl) (*Sco
|
||||||
//
|
//
|
||||||
// for example: `(fn (x y &z) ...)`
|
// for example: `(fn (x y &z) ...)`
|
||||||
if binds[i].GetType() == ast.Symbol && binds[i].(*Symbol).IsRestable() {
|
if binds[i].GetType() == ast.Symbol && binds[i].(*Symbol).IsRestable() {
|
||||||
|
|
||||||
if i != len(binds)-1 {
|
if i != len(binds)-1 {
|
||||||
return nil, MakeError(rt, binds[i], "The function argument with '&' has to be the last argument.")
|
return nil, MakeError(rt, binds[i], "The function argument with '&' has to be the last argument.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ package core
|
||||||
// able to use the alias in a keyword.
|
// able to use the alias in a keyword.
|
||||||
//
|
//
|
||||||
// TODO: Cache the keywords in the runtime on the first eval so we
|
// TODO: Cache the keywords in the runtime on the first eval so we
|
||||||
// done have to evaluate them over and over agian. It can be achieved
|
// done have to evaluate them over and over again. It can be achieved
|
||||||
// by caching the `hash` value in the keyword itself and maintain a
|
// by caching the `hash` value in the keyword itself and maintain a
|
||||||
// hashmap in the runtime from hash codes to a pointer to the keyword.
|
// hashmap in the runtime from hash codes to a pointer to the keyword.
|
||||||
// But garbage collecting it would be an issue since Golang doesn't support
|
// But garbage collecting it would be an issue since Golang doesn't support
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
|
|
||||||
/** WARNING:
|
/** WARNING:
|
||||||
This List implementation may look simple and performant but since
|
This List implementation may look simple and performant but since
|
||||||
we're using a slice here. But in fact it's not memory effecient at
|
we're using a slice here. But in fact it's not memory efficient at
|
||||||
all. We need to rewrite this later to be a immutable and persistent
|
all. We need to rewrite this later to be a immutable and persistent
|
||||||
link list of cons.
|
link list of cons.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -66,7 +66,6 @@ func isMacroCall(rt *Runtime, scope IScope, form IExpr) (*Function, bool) {
|
||||||
if macro.GetType() == ast.Fn && macro.(*Function).IsMacro() {
|
if macro.GetType() == ast.Fn && macro.(*Function).IsMacro() {
|
||||||
return macro.(*Function), true
|
return macro.(*Function), true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (n *Namespace) SetExecutionScope(scope IScope) {}
|
||||||
|
|
||||||
// DefineGlobal inserts the given expr `v` to the root scope of
|
// DefineGlobal inserts the given expr `v` to the root scope of
|
||||||
// `n`. The `public` parameter determines whether the public
|
// `n`. The `public` parameter determines whether the public
|
||||||
// value is accessable publicly or not (in other namespaces).
|
// value is accessible publicly or not (in other namespaces).
|
||||||
func (n *Namespace) DefineGlobal(k string, v IExpr, public bool) {
|
func (n *Namespace) DefineGlobal(k string, v IExpr, public bool) {
|
||||||
n.rootScope.Insert(k, v, public)
|
n.rootScope.Insert(k, v, public)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@ func (i Integer) Hash() uint32 {
|
||||||
|
|
||||||
func (i Integer) GetExecutionScope() IScope {
|
func (i Integer) GetExecutionScope() IScope {
|
||||||
return i.scope
|
return i.scope
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Integer) SetExecutionScope(scope IScope) {
|
func (i Integer) SetExecutionScope(scope IScope) {
|
||||||
|
@ -143,7 +142,6 @@ func (d Double) ToDebugStr() string {
|
||||||
|
|
||||||
func (d Double) GetExecutionScope() IScope {
|
func (d Double) GetExecutionScope() IScope {
|
||||||
return d.scope
|
return d.scope
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Double) SetExecutionScope(scope IScope) {
|
func (d Double) SetExecutionScope(scope IScope) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ var validChars = []rune{'!', '$', '%', '&', '*', '+', '-', '.', '~', '/', ':', '
|
||||||
type IParsable interface {
|
type IParsable interface {
|
||||||
// Reads the next character in the buffer with respect to skipWhitespace
|
// Reads the next character in the buffer with respect to skipWhitespace
|
||||||
// parameter which basically jumps over whitespace and some conceptual
|
// parameter which basically jumps over whitespace and some conceptual
|
||||||
// equivilant of a whitespace like '\n'
|
// equivalent of a whitespace like '\n'
|
||||||
next(skipWhitespace bool) *string
|
next(skipWhitespace bool) *string
|
||||||
|
|
||||||
// Similar to the `next` but it won't change the position in the buffer
|
// Similar to the `next` but it won't change the position in the buffer
|
||||||
|
@ -101,10 +101,8 @@ func (sp *StringParser) updateLineIndex(pos int) {
|
||||||
} else {
|
} else {
|
||||||
sp.lineIndex = append(sp.lineIndex, pos+1)
|
sp.lineIndex = append(sp.lineIndex, pos+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the next character in the buffer
|
// Returns the next character in the buffer
|
||||||
|
@ -137,7 +135,6 @@ func isSeparator(c *string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the character of the buffer without consuming it
|
// Return the character of the buffer without consuming it
|
||||||
|
@ -389,7 +386,6 @@ func readSymbol(parser IParsable) (IExpr, IError) {
|
||||||
parser.back()
|
parser.back()
|
||||||
return readRawSymbol(parser)
|
return readRawSymbol(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return readRawSymbol(parser)
|
return readRawSymbol(parser)
|
||||||
}
|
}
|
||||||
|
@ -413,7 +409,6 @@ func readList(parser IParsable) (IExpr, IError) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
list = append(list, val)
|
list = append(list, val)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +469,7 @@ func readQuotedExpr(parser IParsable) (IExpr, IError) {
|
||||||
// ~a => (unquote a)
|
// ~a => (unquote a)
|
||||||
// ~@a => (unquote-splicing a)
|
// ~@a => (unquote-splicing a)
|
||||||
// Note: `unquote` and `unquote-splicing` are not global functions or special, they are bounded
|
// Note: `unquote` and `unquote-splicing` are not global functions or special, they are bounded
|
||||||
// to quasiquoted experssions only.
|
// to quasiquoted expressions only.
|
||||||
func readUnquotedExpr(parser IParsable) (IExpr, IError) {
|
func readUnquotedExpr(parser IParsable) (IExpr, IError) {
|
||||||
c := parser.peek(true)
|
c := parser.peek(true)
|
||||||
|
|
||||||
|
@ -496,7 +491,6 @@ func readUnquotedExpr(parser IParsable) (IExpr, IError) {
|
||||||
} else {
|
} else {
|
||||||
expr, err = readExpr(parser)
|
expr, err = readExpr(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sym, err = MakeSymbol(node, "unquote")
|
sym, err = MakeSymbol(node, "unquote")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -599,7 +593,6 @@ loop:
|
||||||
// }
|
// }
|
||||||
parser.back()
|
parser.back()
|
||||||
return readSymbol(parser)
|
return readSymbol(parser)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ParseToAST is the entry function to the reader/parser which
|
//ParseToAST is the entry function to the reader/parser which
|
||||||
|
@ -609,7 +602,6 @@ loop:
|
||||||
// It doesn't have anything to do with the concept of blocks
|
// It doesn't have anything to do with the concept of blocks
|
||||||
// from other programming languages.
|
// from other programming languages.
|
||||||
func ParseToAST(ns string, input string) (*Block, IError) {
|
func ParseToAST(ns string, input string) (*Block, IError) {
|
||||||
|
|
||||||
var ast Block
|
var ast Block
|
||||||
parser := StringParser{
|
parser := StringParser{
|
||||||
buffer: strings.Split(input, ""),
|
buffer: strings.Split(input, ""),
|
||||||
|
|
|
@ -98,7 +98,6 @@ func printError(rt *Runtime, err IError, stage int) {
|
||||||
|
|
||||||
errTag := color.Red.Sprint(err.GetErrType().String())
|
errTag := color.Red.Sprint(err.GetErrType().String())
|
||||||
fmt.Printf("%s: %s\nAt: %d to %d\n", errTag, err.String(), loc.GetStart(), loc.GetEnd())
|
fmt.Printf("%s: %s\nAt: %d to %d\n", errTag, err.String(), loc.GetStart(), loc.GetEnd())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func frameCaption(traces *TraceBack, frameIndex int) string {
|
func frameCaption(traces *TraceBack, frameIndex int) string {
|
||||||
|
@ -124,7 +123,6 @@ func frameCaption(traces *TraceBack, frameIndex int) string {
|
||||||
source.NS,
|
source.NS,
|
||||||
source.LineNumberFor(loc.GetStart()),
|
source.LineNumberFor(loc.GetStart()),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func frameSource(traces *TraceBack, frameIndex int) string {
|
func frameSource(traces *TraceBack, frameIndex int) string {
|
||||||
|
@ -157,7 +155,6 @@ func frameSource(traces *TraceBack, frameIndex int) string {
|
||||||
} else {
|
} else {
|
||||||
lines += "Builtin\n"
|
lines += "Builtin\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
@ -182,7 +179,6 @@ func printErrorWithTraceBack(rt *Runtime, err IError) {
|
||||||
if err.GetErrno() != errors.E0000 {
|
if err.GetErrno() != errors.E0000 {
|
||||||
fmt.Printf("For more information on this error try: `serene explain %s`\n", err.GetErrno())
|
fmt.Printf("For more information on this error try: `serene explain %s`\n", err.GetErrno())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintError(rt *Runtime, err IError) {
|
func PrintError(rt *Runtime, err IError) {
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (r *Runtime) CreateNS(name string, source string, setAsCurrent bool) {
|
||||||
|
|
||||||
// IsQQSimplificationEnabled returns a boolean value indicating whether
|
// IsQQSimplificationEnabled returns a boolean value indicating whether
|
||||||
// simplification of quasiquotation is enabled or not. If yes, we have
|
// simplification of quasiquotation is enabled or not. If yes, we have
|
||||||
// to replace the quasiquote expanded forms with a simplier form to gain
|
// to replace the quasiquote expanded forms with a simpler form to gain
|
||||||
// a better performance.
|
// a better performance.
|
||||||
func (r *Runtime) IsQQSimplificationEnabled() bool {
|
func (r *Runtime) IsQQSimplificationEnabled() bool {
|
||||||
// TODO: read the value of this flag from the arguments of serene
|
// TODO: read the value of this flag from the arguments of serene
|
||||||
|
@ -133,7 +133,7 @@ func (r *Runtime) IsQQSimplificationEnabled() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// nsNameToPath converts a namespace name to the filesystem equivilant path
|
// nsNameToPath converts a namespace name to the filesystem equivalent path
|
||||||
func nsNameToPath(ns string) string {
|
func nsNameToPath(ns string) string {
|
||||||
replacer := strings.NewReplacer(
|
replacer := strings.NewReplacer(
|
||||||
".", "/",
|
".", "/",
|
||||||
|
|
|
@ -63,7 +63,6 @@ func Def(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
||||||
// expressions in Serene `defmacro` DOES NOT evaluate its arguments.
|
// expressions in Serene `defmacro` DOES NOT evaluate its arguments.
|
||||||
// That is what makes macros great
|
// That is what makes macros great
|
||||||
func DefMacro(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
func DefMacro(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
||||||
|
|
||||||
// TODO: Add support for docstrings and meta
|
// TODO: Add support for docstrings and meta
|
||||||
|
|
||||||
if args.Count() < 2 {
|
if args.Count() < 2 {
|
||||||
|
@ -99,13 +98,11 @@ func DefMacro(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
||||||
ns.DefineGlobal(sym.GetName(), macro, true)
|
ns.DefineGlobal(sym.GetName(), macro, true)
|
||||||
|
|
||||||
return macro, nil
|
return macro, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fn defines a function inside the given scope `scope` with the given `args`.
|
// Fn defines a function inside the given scope `scope` with the given `args`.
|
||||||
// `args` contains the argument list, docstring and body of the function.
|
// `args` contains the argument list, docstring and body of the function.
|
||||||
func Fn(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
func Fn(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
||||||
|
|
||||||
if args.Count() < 2 {
|
if args.Count() < 2 {
|
||||||
return nil, MakeError(rt, args, "'fn' needs at least an arguments list")
|
return nil, MakeError(rt, args, "'fn' needs at least an arguments list")
|
||||||
}
|
}
|
||||||
|
@ -156,5 +153,4 @@ func NSForm(rt *Runtime, scope IScope, args *List) (IExpr, IError) {
|
||||||
return ns, nil
|
return ns, nil
|
||||||
// TODO: Handle the params like `require` and `meta`
|
// TODO: Handle the params like `require` and `meta`
|
||||||
// params := args.Rest().Rest()
|
// params := args.Rest().Rest()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ type IExpr interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add helper functions to reach methods on Node.location. For example
|
// TODO: Add helper functions to reach methods on Node.location. For example
|
||||||
// Node.location.DecStart() has to have a helper on the Node liek:
|
// Node.location.DecStart() has to have a helper on the Node like:
|
||||||
// Node.DecStartLocation
|
// Node.DecStartLocation
|
||||||
|
|
||||||
// Node struct is simply representing a Node in the AST which provides the
|
// Node struct is simply representing a Node in the AST which provides the
|
||||||
|
@ -95,7 +95,6 @@ type ExecutionScope struct {
|
||||||
|
|
||||||
func (e *ExecutionScope) GetExecutionScope() IScope {
|
func (e *ExecutionScope) GetExecutionScope() IScope {
|
||||||
return e.scope
|
return e.scope
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ExecutionScope) SetExecutionScope(scope IScope) {
|
func (e *ExecutionScope) SetExecutionScope(scope IScope) {
|
||||||
|
|
Loading…
Reference in New Issue