-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (49 loc) · 1.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fkclang/repl"
"fmt"
"os"
"os/user"
"strings"
)
const FKC = `
,--.
,---,. ,--/ /| ,----..
,' .' | ,---,': / ' / / \
,---.' | : : '/ / | : :
| | .' | ' , . | ;. /
: : : ' | / . ; /---
| | |-, | ; ; ; | ;
| : ;/| : ' \ | : |
| | .' | | ' . | '___
' : ' ' : |. \ ' ; : .'|
| | | | | '_\.' ' | '/ :
| : \ ' : | | : /
| | ,' ; |,' \ \ .'
--- --- ---
`
func main() {
u, err := user.Current()
if err != nil {
panic(err)
}
// 读取命令行参数
var fileNames []string
if len(os.Args) > 1 {
fileNames = os.Args[1:]
}
// 检查文件后缀名
checkExtension(fileNames)
fmt.Print(FKC)
fmt.Printf("Hello %s! This is the FkCongLang programming language!\n",
u.Username)
fmt.Printf("Feel free to type in commands\n")
repl.Start(os.Stdin, os.Stdout, fileNames...)
}
func checkExtension(fileNames []string) {
for _, fileName := range fileNames {
if !strings.HasSuffix(fileName, ".fkc") {
panic("file extension must be .fkc")
}
}
}