-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsyntax.go
48 lines (39 loc) · 1.08 KB
/
syntax.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
// Copyright 2016 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package sublime
import (
"path/filepath"
"github.com/limetext/backend/parser"
"github.com/limetext/sublime/textmate/language"
)
// wrapper around Language implementing backend.Syntax interface
type syntax struct {
l *language.Language
}
func newSyntax(path string) (*syntax, error) {
if l, err := language.Load(path); err != nil {
return nil, err
} else {
return &syntax{l: l}, nil
}
}
func (s *syntax) Parser(data string) (parser.Parser, error) {
// we can't use syntax language(s.l) because it causes race conditions
// on concurrent parsing. We could load the language from the file again
// but I think copying would be much faster
l := s.l.Copy()
return language.NewParser(l, []rune(data)), nil
}
func (s *syntax) Name() string {
return s.l.Name
}
func (s *syntax) FileTypes() []string {
return s.l.FileTypes
}
func isSyntax(path string) bool {
if filepath.Ext(path) == ".tmLanguage" {
return true
}
return false
}