当前位置: 首页>>代码示例>>Golang>>正文


Golang rubex.Compile函数代码示例

本文整理汇总了Golang中github.com/limetext/rubex.Compile函数的典型用法代码示例。如果您正苦于以下问题:Golang Compile函数的具体用法?Golang Compile怎么用?Golang Compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Compile函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: loadSettings

// Will load view settings respect to current syntax
// e.g if current syntax is Python settings order will be:
// Packages/Python/Python.sublime-settings
// Packages/Python/Python (Windows).sublime-settings
// Packages/User/Python.sublime-settings
// <Buffer Specific Settings>
func (v *View) loadSettings() {
	syntax := v.Settings().Get("syntax", "").(string)

	if syntax == "" {
		v.Settings().SetParent(v.window)
		return
	}

	defSettings, usrSettings, platSettings := &HasSettings{}, &HasSettings{}, &HasSettings{}

	defSettings.Settings().SetParent(v.window)
	platSettings.Settings().SetParent(defSettings)
	usrSettings.Settings().SetParent(platSettings)
	v.Settings().SetParent(usrSettings)

	ed := GetEditor()
	if r, err := rubex.Compile(`([A-Za-z]+?)\.(?:[^.]+)$`); err != nil {
		log.Error(err)
		return
	} else if s := r.FindStringSubmatch(syntax); s != nil {
		p := path.Join(LIME_PACKAGES_PATH, s[1], s[1]+".sublime-settings")
		ed.load(packages.NewPacket(p, defSettings.Settings()))

		p = path.Join(LIME_PACKAGES_PATH, s[1], s[1]+" ("+ed.Plat()+").sublime-settings")
		ed.load(packages.NewPacket(p, platSettings.Settings()))

		p = path.Join(LIME_USER_PACKAGES_PATH, s[1]+".sublime-settings")
		ed.load(packages.NewPacket(p, usrSettings.Settings()))
	}
}
开发者ID:rokite,项目名称:lime,代码行数:36,代码来源:view.go

示例2: UnmarshalJSON

func (r *Regex) UnmarshalJSON(data []byte) error {
	str := string(data[1 : len(data)-1])
	str = strings.Replace(str, "\\\\", "\\", -1)
	str = strings.Replace(str, "\\n", "\n", -1)
	str = strings.Replace(str, "\\t", "\t", -1)
	if re, err := rubex.Compile(str); err != nil {
		log.Warn("Couldn't compile language pattern %s: %s", str, err)
	} else {
		r.re = re
	}
	return nil
}
开发者ID:hanshenu,项目名称:lime,代码行数:12,代码来源:language.go

示例3: Classify

// Classifies point, returning a bitwise OR of zero or more of defined flags
func (v *View) Classify(point int) (res int) {
	var a, b string = "", ""
	ws := v.Settings().Get("word_separators", "[!\"#$%&'()*+,\\-./:;<=>[email protected]\\[\\\\\\]^_`{|}~]").(string)
	if point > 0 {
		a = v.buffer.Substr(Region{point - 1, point})
	}
	if point < v.buffer.Size() {
		b = v.buffer.Substr(Region{point, point + 1})
	}

	// Special cases
	if v.buffer.Size() == 0 || point < 0 || point > v.buffer.Size() {
		res = 3520
		return
	}
	if re, err := rubex.Compile("[A-Z]"); err != nil {
		log4go.Error(err)
	} else {
		if re.MatchString(b) && !re.MatchString(a) {
			res |= CLASS_SUB_WORD_START
			res |= CLASS_SUB_WORD_END
		}
	}
	if a == "," {
		res |= CLASS_OPENING_PARENTHESIS
	}
	if b == "," {
		res |= CLASS_CLOSING_PARENTHESIS
	}
	if a == "," && b == "," {
		res = 0
		return
	}
	// Punc start & end
	if re, err := rubex.Compile(ws); err != nil {
		log4go.Error(err)
	} else {
		if (re.MatchString(b) || b == "") && !re.MatchString(a) {
			res |= CLASS_PUNCTUATION_START
		}
		if (re.MatchString(a) || a == "") && !re.MatchString(b) {
			res |= CLASS_PUNCTUATION_END
		}
		// Word start & end
		if re1, err := rubex.Compile("\\w"); err != nil {
			log4go.Error(err)
		} else if re2, err := rubex.Compile("\\s"); err != nil {
			log4go.Error(err)
		} else {
			if re1.MatchString(b) && (re.MatchString(a) || re2.MatchString(a) || a == "") {
				res |= CLASS_WORD_START
			}
			if re1.MatchString(a) && (re.MatchString(b) || re2.MatchString(b) || b == "") {
				res |= CLASS_WORD_END
			}
		}
	}
	// SubWord start & end

	// Line start & end
	if a == "\n" || a == "" {
		res |= CLASS_LINE_START
	}
	if b == "\n" || b == "" {
		res |= CLASS_LINE_END
	}
	// Empty line
	if (a == "\n" && b == "\n") || (a == "" && b == "") {
		res |= CLASS_EMPTY_LINE
	}
	// Middle word
	if re, err := rubex.Compile("\\w"); err != nil {
		log4go.Error(err)
	} else {
		if re.MatchString(a) && re.MatchString(b) {
			res |= CLASS_MIDDLE_WORD
		}
	}
	// Word start & end with punc
	if re, err := rubex.Compile("\\s"); err != nil {
		log4go.Error(err)
	} else {
		if (res&CLASS_PUNCTUATION_START == CLASS_PUNCTUATION_START) && (re.MatchString(a) || a == "") {
			res |= CLASS_WORD_START_WITH_PUNCTUATION
		}
		if (res&CLASS_PUNCTUATION_END == CLASS_PUNCTUATION_END) && (re.MatchString(b) || b == "") {
			res |= CLASS_WORD_END_WITH_PUNCTUATION
		}
	}
	// Openning & closing parentheses
	if re, err := rubex.Compile("[(\\[{]"); err != nil {
		log4go.Error(err)
	} else {
		if re.MatchString(a) || re.MatchString(b) {
			res |= CLASS_OPENING_PARENTHESIS
		}
		if re.MatchString(a) && a == b {
			res = 0
			return
//.........这里部分代码省略.........
开发者ID:BinaryPaean,项目名称:lime,代码行数:101,代码来源:view.go

示例4: Classify

// Classifies point, returning a bitwise OR of zero or more of defined flags
func (v *View) Classify(point int) (res int) {
	var a, b string = "", ""
	ws := v.Settings().Get("word_separators", DEFAULT_SEPARATORS).(string)
	if point > 0 {
		a = v.buffer.Substr(Region{point - 1, point})
	}
	if point < v.buffer.Size() {
		b = v.buffer.Substr(Region{point, point + 1})
	}

	// Out of range
	if v.buffer.Size() == 0 || point < 0 || point > v.buffer.Size() {
		res = 3520
		return
	}

	// If before and after the point are separators return 0
	if re, err := rubex.Compile(ws); err != nil {
		log.Error(err)
	} else if a == b && re.MatchString(a) {
		res = 0
		return
	}

	// SubWord start & end
	if re, err := rubex.Compile("[A-Z]"); err != nil {
		log.Error(err)
	} else {
		if re.MatchString(b) && !re.MatchString(a) {
			res |= CLASS_SUB_WORD_START
			res |= CLASS_SUB_WORD_END
		}
	}
	if a == "_" && b != "_" {
		res |= CLASS_SUB_WORD_START
	}
	if b == "_" && a != "_" {
		res |= CLASS_SUB_WORD_END
	}

	// Punc start & end
	if re, err := rubex.Compile(ws); err != nil {
		log.Error(err)
	} else {
		// Why ws != ""? See https://github.com/limetext/rubex/issues/2
		if ((re.MatchString(b) && ws != "") || b == "") && !(re.MatchString(a) && ws != "") {
			res |= CLASS_PUNCTUATION_START
		}
		if ((re.MatchString(a) && ws != "") || a == "") && !(re.MatchString(b) && ws != "") {
			res |= CLASS_PUNCTUATION_END
		}
		// Word start & end
		if re1, err := rubex.Compile("\\w"); err != nil {
			log.Error(err)
		} else if re2, err := rubex.Compile("\\s"); err != nil {
			log.Error(err)
		} else {
			if re1.MatchString(b) && ((re.MatchString(a) && ws != "") || re2.MatchString(a) || a == "") {
				res |= CLASS_WORD_START
			}
			if re1.MatchString(a) && ((re.MatchString(b) && ws != "") || re2.MatchString(b) || b == "") {
				res |= CLASS_WORD_END
			}
		}
	}

	// Line start & end
	if a == "\n" || a == "" {
		res |= CLASS_LINE_START
	}
	if b == "\n" || b == "" {
		res |= CLASS_LINE_END
		if ws == "" {
			res |= CLASS_WORD_END
		}
	}

	// Empty line
	if (a == "\n" && b == "\n") || (a == "" && b == "") {
		res |= CLASS_EMPTY_LINE
	}
	// Middle word
	if re, err := rubex.Compile("\\w"); err != nil {
		log.Error(err)
	} else {
		if re.MatchString(a) && re.MatchString(b) {
			res |= CLASS_MIDDLE_WORD
		}
	}

	// Word start & end with punc
	if re, err := rubex.Compile("\\s"); err != nil {
		log.Error(err)
	} else {
		if (res&CLASS_PUNCTUATION_START != 0) && (re.MatchString(a) || a == "") {
			res |= CLASS_WORD_START_WITH_PUNCTUATION
		}
		if (res&CLASS_PUNCTUATION_END != 0) && (re.MatchString(b) || b == "") {
			res |= CLASS_WORD_END_WITH_PUNCTUATION
//.........这里部分代码省略.........
开发者ID:sivaramanr,项目名称:lime-backend,代码行数:101,代码来源:view.go


注:本文中的github.com/limetext/rubex.Compile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。