Compare commits
9 Commits
93673cb359
...
35d76c5d2b
| Author | SHA1 | Date | |
|---|---|---|---|
|
35d76c5d2b
|
|||
|
dfd3301a33
|
|||
|
a4ce41ea9a
|
|||
|
773e43a215
|
|||
|
f150e1fdd6
|
|||
|
dec7010c35
|
|||
|
69bd88282c
|
|||
|
ca2053d3ba
|
|||
|
8d0aa1127c
|
@@ -1,69 +0,0 @@
|
|||||||
//go:generate gocc -a azalea.bnf
|
|
||||||
package azalea
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"hakurei.app/container/check"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Parser struct {
|
|
||||||
Generator
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewParser(gen Generator) *Parser {
|
|
||||||
return &Parser{
|
|
||||||
Generator: gen,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func (p Parser) Initialise() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Parser) Consume(ns string, file io.Reader) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConsumeDir walks a directory and consumes all Azalea source files within it and all its subdirectories, as long as they end with the .az extension.
|
|
||||||
func (p Parser) ConsumeDir(dir *check.Absolute) error {
|
|
||||||
ds := dir.String()
|
|
||||||
return filepath.WalkDir(ds, func(path string, d fs.DirEntry, err error) (e error) {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if d.IsDir() || !strings.HasSuffix(d.Name(), ".az") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rel, e := filepath.Rel(ds, path)
|
|
||||||
ns := strings.TrimSuffix(rel, ".az")
|
|
||||||
f, e := os.Open(path)
|
|
||||||
return p.Consume(ns, f)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConsumeAll consumes all provided readers as Azalea source code, each given the namespace `r%d` where `%d` is the index of the reader in the provided arguments.
|
|
||||||
func (p Parser) ConsumeAll(in ...io.Reader) error {
|
|
||||||
for i, r := range in {
|
|
||||||
err := p.Consume("r"+strconv.FormatInt(int64(i), 10), r)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConsumeStrings consumes all provided strings as Azalea source code, each given the namespace `s%d` where `%d` is the index of the string in the provided arugments.
|
|
||||||
func (p Parser) ConsumeStrings(in ...string) error {
|
|
||||||
for i, s := range in {
|
|
||||||
err := p.Consume("s"+strconv.FormatInt(int64(i), 10), strings.NewReader(s))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package azalea
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Generator interface {
|
|
||||||
Finalise() (error, io.Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
type JsonGenerator struct {
|
|
||||||
t any
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewJsonGenerator[T any]() JsonGenerator {
|
|
||||||
t := new(T)
|
|
||||||
|
|
||||||
return JsonGenerator{
|
|
||||||
t,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *JsonGenerator) Finalise() (error, io.Writer) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type PkgIRGenerator struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPkgIRGenerator() PkgIRGenerator {
|
|
||||||
return PkgIRGenerator{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PkgIRGenerator) Finalise() (error, io.Writer) {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user