mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-08-30 22:06:27 -04:00
Add syntax_checker.go
Please use this file to check if the syntax files compile.
This commit is contained in:
@@ -2,8 +2,9 @@ package highlight
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"regexp"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// A Def is a full syntax definition for a language
|
||||
@@ -45,13 +46,23 @@ type Region struct {
|
||||
}
|
||||
|
||||
// ParseDef parses an input syntax file into a highlight Def
|
||||
func ParseDef(input []byte) (*Def, error) {
|
||||
func ParseDef(input []byte) (s *Def, err error) {
|
||||
// This is just so if we have an error, we can exit cleanly and return the parse error to the user
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
// fmt.Println("Micro encountered an error:", err)
|
||||
// Print the stack trace too
|
||||
// fmt.Print(errors.Wrap(err, 2).ErrorStack())
|
||||
err = e.(error)
|
||||
}
|
||||
}()
|
||||
|
||||
var rules map[interface{}]interface{}
|
||||
if err := yaml.Unmarshal(input, &rules); err != nil {
|
||||
if err = yaml.Unmarshal(input, &rules); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := new(Def)
|
||||
s = new(Def)
|
||||
|
||||
for k, v := range rules {
|
||||
if k == "filetype" {
|
||||
@@ -88,7 +99,7 @@ func ParseDef(input []byte) (*Def, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return s, nil
|
||||
return s, err
|
||||
}
|
||||
|
||||
func parseRules(input []interface{}, curRegion *Region) (*Rules, error) {
|
||||
|
||||
@@ -23,7 +23,7 @@ rules:
|
||||
|
||||
- special: "^[[:space:]]*[#|@][[:space:]]*(import|include)[[:space:]]*[\"|<].*\\/?[>|\"][[:space:]]*$"
|
||||
|
||||
- statement: "([.:;,+*|=!\\%\\[\\]]|<|>|/|-|&)"
|
||||
- statement: "([.:;,+*|=!\\%\\[\\]]|<|>|/|-|&)"
|
||||
|
||||
- constant.number: "(\\b(-?)?[0-9]+\\b|\\b\\[0-9]+\\.[0-9]+\\b|\\b0x[0-9A-F]+\\b)"
|
||||
- constant: "(@\\[(\\\\.|[^\\]])*\\]|@\\{(\\\\.|[^\\}])*\\}|@\\((\\\\.|[^\\)])*\\))"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/highlight"
|
||||
)
|
||||
|
||||
func main() {
|
||||
files, _ := ioutil.ReadDir(".")
|
||||
|
||||
hadErr := false
|
||||
for _, f := range files {
|
||||
if strings.HasSuffix(f.Name(), ".yaml") {
|
||||
input, _ := ioutil.ReadFile("/Users/zachary/gocode/src/github.com/zyedidia/highlight/syntax_files/" + f.Name())
|
||||
_, err := highlight.ParseDef(input)
|
||||
if err != nil {
|
||||
hadErr = true
|
||||
fmt.Printf("%s:\n", f.Name())
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hadErr {
|
||||
fmt.Println("No issues!")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user