Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler fixes #4215

Merged
merged 7 commits into from
Aug 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions tools/grammars/compiler/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path"
"regexp"
"runtime"
"sort"
"strings"
Expand All @@ -18,7 +19,8 @@ import (
)

type Converter struct {
root string
root string
version string

modified bool
grammars map[string][]string
Expand Down Expand Up @@ -194,6 +196,13 @@ func (conv *Converter) WriteJSON(rulePath string) error {
return err
}

f, err := os.Create(path.Join(rulePath, "version"))
if err != nil {
return err
}
f.Write([]byte(conv.version))
f.Close()

for _, repo := range conv.Loaded {
for scope, file := range repo.Files {
p := path.Join(rulePath, scope+".json")
Expand Down Expand Up @@ -248,13 +257,25 @@ func (conv *Converter) Report() error {
return nil
}

var VERSION_RE *regexp.Regexp = regexp.MustCompile("VERSION = \"(.+)\"")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a little cleaner to change version.rb to do VERSION = File.read("#{__dir__}/VERSION") to simplify this, but this is clever and works 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer your suggestion 100%. Thank you!


func NewConverter(root string) (*Converter, error) {
ver, err := ioutil.ReadFile(path.Join(root, "lib", "linguist", "version.rb"))
if err != nil {
return nil, err
}

submatches := VERSION_RE.FindSubmatch(ver)
if submatches == nil {
return nil, fmt.Errorf("no match in lib/linguist/version.rb")
}

yml, err := ioutil.ReadFile(path.Join(root, "grammars.yml"))
if err != nil {
return nil, err
}

conv := &Converter{root: root}
conv := &Converter{root: root, version: string(submatches[1])}

if err := yaml.Unmarshal(yml, &conv.grammars); err != nil {
return nil, err
Expand Down