-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: better cli * fix: imports and declarations in repl were broken
- Loading branch information
Showing
12 changed files
with
960 additions
and
79 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
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
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ RUN go mod download | |
|
||
COPY ./ ./ | ||
|
||
RUN go build ./cmd/lithia | ||
RUN go build ./app/lithia | ||
|
||
## | ||
## Deploy | ||
|
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,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
// rootCmd.AddCommand(lspCmd) | ||
lspCmd.AddCommand(lspStdioCmd) | ||
lspCmd.AddCommand(lspSocketCmd) | ||
|
||
lspSocketCmd.Flags().StringVarP( | ||
&lspSocketAddress, | ||
"listen", | ||
"l", | ||
"127.0.0.1:7998", | ||
"Address and port on which to listen for LSP connections", | ||
) | ||
} | ||
|
||
var lspCmd = &cobra.Command{ | ||
Use: "lsp", | ||
Short: "Language Server", | ||
Long: `Runs the language server for the use inside an editor.`, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
lspStdioCmd.Run(lspStdioCmd, args) | ||
}, | ||
} | ||
|
||
var lspStdioCmd = &cobra.Command{ | ||
Use: "stdio", | ||
Aliases: []string{"stdin", "-"}, | ||
Short: "stdio mode. Supported by most editors.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("stdio") | ||
}, | ||
} | ||
|
||
var lspSocketAddress string = "127.0.0.1:7998" | ||
var lspSocketCmd = &cobra.Command{ | ||
Use: "socket", | ||
Short: `opens a socket on the specified address. Make sure the port is free.`, | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("socket", lspSocketAddress) | ||
}, | ||
} |
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,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/vknabel/go-lithia/reporting" | ||
"github.com/vknabel/go-lithia/runtime" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(replCmd) | ||
} | ||
|
||
var replCmd = &cobra.Command{ | ||
Use: "repl", | ||
Short: "Runs interactive Lithia REPL.", | ||
Long: ``, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runPrompt() | ||
}, | ||
} | ||
|
||
func runPrompt() { | ||
importRoot, err := os.Getwd() | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
reader := bufio.NewReader(os.Stdin) | ||
inter := runtime.NewInterpreter(importRoot) | ||
for { | ||
fmt.Print("> ") | ||
line, err := reader.ReadString('\n') | ||
if err == io.EOF { | ||
return | ||
} | ||
if err != nil { | ||
reporting.ReportErrorOrPanic(err) | ||
continue | ||
} | ||
value, err := inter.InterpretEmbed("prompt", line) | ||
if err != nil { | ||
reporting.ReportErrorOrPanic(err) | ||
continue | ||
} | ||
if value != nil { | ||
fmt.Println("- ", value) | ||
} | ||
} | ||
} |
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,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "lithia", | ||
Short: "Lithia programming language", | ||
Long: "Lithia is an experimental functional programming language " + | ||
"with an implicit but strong and dynamic type system.\n" + | ||
"It is designed around a few core concepts in mind " + | ||
"all language features contribute to.\n" + | ||
"\n" + | ||
"Lean more at https://github.com/vknabel/lithia", | ||
Version: "0.0.12-next", | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 1 { | ||
runFile(args[0]) | ||
} else { | ||
runPrompt() | ||
} | ||
}, | ||
} |
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,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/vknabel/go-lithia/runtime" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(runCmd) | ||
} | ||
|
||
var runCmd = &cobra.Command{ | ||
Use: "run [script]", | ||
Short: "Runs a Lithia script", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runFile(args[0]) | ||
}, | ||
} | ||
|
||
func runFile(fileName string) { | ||
scriptData, err := os.ReadFile(fileName) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
inter := runtime.NewInterpreter(path.Dir(fileName)) | ||
script := string(scriptData) + "\n" | ||
_, err = inter.Interpret(fileName, script) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
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,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/vknabel/go-lithia/app/lithia/cmd" | ||
) | ||
|
||
func main() { | ||
err := cmd.Execute() | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.