mirror of
https://github.com/hazemKrimi/jack-compiler.git
synced 2026-05-01 17:48:57 +00:00
feat: check the validity of the passed argument
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
out
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package tokenizer
|
package compiler
|
||||||
|
|
||||||
type TokenType int
|
type TokenType int
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,34 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
// "strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func process(Path string) {
|
func process(inputPath string) {
|
||||||
fmt.Println(Path)
|
// outputPath := strings.Replace(inputPath, ".jack", ".xml", 1)
|
||||||
|
source, err := os.ReadFile(inputPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(source))
|
||||||
|
}
|
||||||
|
|
||||||
|
func walker(path string, entry fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if match, _ := regexp.MatchString(".+\\.jack$", path); match {
|
||||||
|
process(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -17,9 +39,25 @@ func main() {
|
|||||||
panic("You must provide a path for a Jack file or a directory that contains Jack files to compile!")
|
panic("You must provide a path for a Jack file or a directory that contains Jack files to compile!")
|
||||||
}
|
}
|
||||||
|
|
||||||
Path := args[1]
|
info, err := os.Stat(args[1])
|
||||||
|
|
||||||
if match, _ := regexp.MatchString(".+\\.jack", Path); match {
|
if err != nil {
|
||||||
process(Path)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
err := filepath.WalkDir(args[1], walker)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if match, _ := regexp.MatchString(".+\\.jack$", args[1]); !match {
|
||||||
|
panic("You must provide a path for a Jack file or a directory that contains Jack files to compile!")
|
||||||
|
}
|
||||||
|
|
||||||
|
process(args[1])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user