-
Notifications
You must be signed in to change notification settings - Fork 5
/
compilers.go
65 lines (53 loc) · 1.72 KB
/
compilers.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
57
58
59
60
61
62
63
64
65
package xaqt
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
)
// Compilers maps language names to the details of how to execute code in that language.
type Compilers map[string]CompilerDetails
// ExecutionDetails specifies how to execute certain code.
type ExecutionDetails struct {
Compiler string `json:"compiler"`
SourceFile string `json:"sourceFile"`
OptionalExecutable string `json:"optionalExecutable"`
CompilerFlags string `json:"compilerFlags"`
Disabled string `json:"disabled"`
}
// CompositionDetails specifies how to write code in a given language
type CompositionDetails struct {
Boilerplate string `json:"boilerplate"`
CommentPrefix string `json:"commentPrefix"`
}
// CompilerDetails contains everything XAQT knows about handling a certain language
type CompilerDetails struct {
ExecutionDetails
CompositionDetails
}
// ReadCompilers reads a compilers map from a file.
func ReadCompilers(filename string) Compilers {
compilerMap := make(Compilers, 0)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalf("Fatal: failed to read language file: %s", err)
}
err = json.Unmarshal(bytes, &compilerMap)
if err != nil {
log.Fatalf("Fatal: failed to parse JSON: %s", err)
}
return compilerMap
}
// availableLanguages returns a list of currently supported languages.
func (c Compilers) availableLanguages() map[string]CompositionDetails {
fmt.Printf("Received languages request...")
langs := make(map[string]CompositionDetails)
// make a list of currently supported languages
for k, v := range c {
if v.Disabled != "true" {
langs[k] = v.CompositionDetails
}
}
log.Printf("currently supporting %d of %d known languages\n", len(langs), len(c))
return langs
}