From 17dd7fbc5ebb8a2aace9fd49944ed7709e6eaa20 Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Sun, 3 Jul 2022 19:50:56 -0500 Subject: [PATCH] new formatter feature --- README.md | 7 +++++++ appy.yaml | 2 +- cmd/fmt.go | 20 ++++++++++++++++++++ core/assembler.go | 2 -- core/formatter.go | 24 ++++++++++++++++++++++++ go.mod | 5 ++++- go.sum | 14 ++++++++------ testsrc/fmt.s | 18 ++++++++++++++++++ 8 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 cmd/fmt.go create mode 100644 core/formatter.go create mode 100644 testsrc/fmt.s diff --git a/README.md b/README.md index b1d1ac8..3253e45 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,10 @@ $ appy brun # assemble files, make disk, and launch emulator This is an early experimental version not intended for public use. Versioning/vendoring binaries from external sources not yet implemented but all core functionality exists including local binary overrides. + + +### Dev Quickstart + +1. Checkout +2. Run `go mod tidy` to install dependencies +3. Run `go build & go install` to build and install \ No newline at end of file diff --git a/appy.yaml b/appy.yaml index 040a617..47f87ba 100644 --- a/appy.yaml +++ b/appy.yaml @@ -1,4 +1,4 @@ -assemble: [testsrc/sp.s, testsrc/pc.s] +assemble: [testsrc/sp.s, testsrc/pc.s, testsrc/fmt.s] disks: - name: mydiskimage file: mydiskimage800.2mg diff --git a/cmd/fmt.go b/cmd/fmt.go new file mode 100644 index 0000000..950822a --- /dev/null +++ b/cmd/fmt.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/digarok/appy/core" + "github.com/spf13/cobra" +) + +// 'appy fmt' command +var fmtCmd = &cobra.Command{ + Use: "fmt", + Short: "Format the source files in your project", + Long: `This will run an internal formatter over the assembly language files in the appy.yaml 'assemble:' list, OR you can pass filename arguments.`, + Run: func(cmd *cobra.Command, args []string) { + core.Format(args) + }, +} + +func init() { + rootCmd.AddCommand(fmtCmd) +} diff --git a/core/assembler.go b/core/assembler.go index 91cfb98..10b69f7 100644 --- a/core/assembler.go +++ b/core/assembler.go @@ -9,8 +9,6 @@ import ( "github.com/fatih/color" ) -var filesToAssemble []string - func Assemble() { // assemble all files in list for _, filename := range project.AppyProj.Assemble { diff --git a/core/formatter.go b/core/formatter.go new file mode 100644 index 0000000..09c5aaa --- /dev/null +++ b/core/formatter.go @@ -0,0 +1,24 @@ +package core + +import ( + "fmt" + + "github.com/digarok/appy/core/project" + "github.com/digarok/merlingo" +) + +func Format(args []string) { + if len(args) == 0 { + // format all assembly files in appy.yaml + for _, filename := range project.AppyProj.Assemble { + fmt.Printf("Formatting %v\n", filename) + merlingo.FmtFile(filename) + } + } else { + // format all assembly files in args + for _, filename := range args { + fmt.Printf("Formatting %v\n", filename) + merlingo.FmtFile(filename) + } + } +} diff --git a/go.mod b/go.mod index b60e1da..7264e41 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,11 @@ module github.com/digarok/appy go 1.16 require ( - github.com/fatih/color v1.10.0 + github.com/digarok/merlingo v1.0.0 + github.com/fatih/color v1.13.0 github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.1.3 github.com/spf13/viper v1.7.1 ) + +replace github.com/digarok/merlingo => ../merlingo diff --git a/go.sum b/go.sum index a346620..1399d75 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -115,11 +115,12 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -254,8 +255,9 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= diff --git a/testsrc/fmt.s b/testsrc/fmt.s new file mode 100644 index 0000000..36481ec --- /dev/null +++ b/testsrc/fmt.s @@ -0,0 +1,18 @@ +* formatting test + org $300 ; start + +main nop + + * what about this + + ; and this + + sta :jo+1 + + +:jo+1 lda $400 + lda $400 + rts + + +ReallyThisisaLoooooongLabelwith stal $e12000,y ; look at this long line