go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit aa25412557ade7364fe82a5beea5f1c565e058b3
parent c8c8a25862ee2e5baf9a9caf888cabf322b0f191
Author: lash <dev@holbrook.no>
Date:   Mon, 26 Aug 2024 22:25:51 +0100

Rename to flagparser, fix fail on numeric croak

Diffstat:
Dasm/preprocess.go | 61-------------------------------------------------------------
Mdev/asm/main.go | 6+++---
2 files changed, 3 insertions(+), 64 deletions(-)

diff --git a/asm/preprocess.go b/asm/preprocess.go @@ -1,61 +0,0 @@ -package asm - -import ( - "encoding/csv" - "fmt" - "io" - "os" - "strconv" -) - -type PreProcessor struct { - flags map[string]string -} - -func NewPreProcessor() *PreProcessor { - return &PreProcessor{ - flags: make(map[string]string), - } -} - -func(pp *PreProcessor) Get(key string) (string, error) { - v, ok := pp.flags[key] - if !ok { - return "", fmt.Errorf("no flag registered under key: %s", key) - } - return v, nil -} - -func(pp *PreProcessor) Load(fp string) (int, error) { - var i int - f, err := os.Open(fp) - if err != nil { - return 0, err - } - defer f.Close() - r := csv.NewReader(f) - for i = 0; true; i++ { - r, err := r.Read() - if err != nil { - if err == io.EOF { - break - } - return 0, err - } - if r[0] == "flag" { - if len(r) < 3 { - return 0, fmt.Errorf("Not enough fields for flag setting in line %d", i) - } - _, err = strconv.Atoi(r[2]) - if err != nil { - return 0, fmt.Errorf("Flag translation value must be numeric") - } - pp.flags[r[1]] = r[2] - Logg.Debugf("added flag translation", "from", r[1], "to", r[2]) - } - } - - return i, nil -} - - diff --git a/dev/asm/main.go b/dev/asm/main.go @@ -17,7 +17,7 @@ import ( type arg struct { - One *string `@Sym` + One *string `(@Sym | @NumFirst)` Two *string `((@Sym | @NumFirst) Whitespace?)?` Three *string `((@Sym | @NumFirst) Whitespace?)?` //Desc *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?` @@ -34,13 +34,13 @@ type asmAsm struct { } type processor struct { - *asm.PreProcessor + *asm.FlagParser } func newProcessor(fp string) (*processor, error) { o := &processor{ - asm.NewPreProcessor(), + asm.NewFlagParser(), } _, err := o.Load(fp) return o, err