-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cli | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Options struct { | ||
PrintAst bool | ||
} | ||
|
||
type Args struct { | ||
Options Options | ||
Input string | ||
Arguments []string | ||
} | ||
|
||
const HELP_HEADER = `Usage: umbra [options] [[file] [arguments]] | ||
Options:` | ||
|
||
func Parse() Args { | ||
parsedArgs := Args{} | ||
|
||
flag.BoolVar(&parsedArgs.Options.PrintAst, "ast", false, "Prints the AST of the program") | ||
flag.Usage = func() { | ||
fmt.Fprintln(os.Stderr, HELP_HEADER) | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
|
||
args := flag.Args() | ||
|
||
if len(args) > 0 { | ||
parsedArgs.Input = args[0] | ||
parsedArgs.Arguments = args[1:] | ||
} | ||
|
||
return parsedArgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/pmqueiroz/umbra/ast" | ||
"github.com/sanity-io/litter" | ||
) | ||
|
||
func PrintAst(module ast.ModuleStatement) { | ||
litter.Dump(module) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/pmqueiroz/umbra | ||
|
||
go 1.21.6 | ||
|
||
require github.com/sanity-io/litter v1.5.5 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sanity-io/litter v1.5.5 h1:iE+sBxPBzoK6uaEP5Lt3fHNgpKcHXc/A2HGETy0uJQo= | ||
github.com/sanity-io/litter v1.5.5/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U= | ||
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters