From 4549145b4f2ab71b17e7e2f97d1e719891c042b8 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Tue, 14 Jun 2022 09:19:09 +0200 Subject: [PATCH] feat: support for parsing chinese characters --- config.go | 3 +-- parser/regexes.go | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index b12f803..4f4c339 100644 --- a/config.go +++ b/config.go @@ -10,12 +10,11 @@ func getDefaultConfig() { if err != nil { log.Println("Creating default config...") b := []byte(defaultConfig()) - ioutil.WriteFile("renpy-graphviz.config", b, 0644) + ioutil.WriteFile("renpy-graphviz.config", b, 0o644) } } func defaultConfig() string { - return `### RENPY-GRAPHVIZ TOOL CONFIGURATION ### # Select what you want to show and what you want to hide # Hiding everything isn't always very useful diff --git a/parser/regexes.go b/parser/regexes.go index dd9e47a..56a8242 100644 --- a/parser/regexes.go +++ b/parser/regexes.go @@ -25,14 +25,14 @@ type customRegexes struct { // should be called rarely func initializeDetectors() customRegexes { return customRegexes{ - screen: regexp.MustCompile(`^\s*(?:init\s+[-\w]*\s+)?screen\s+([a-zA-Z0-9._-]+).*\s*:\s*(?:#.*)?$`), + screen: regexp.MustCompile(`^\s*(?:init\s+[-\w]*\s+)?screen\s+([\p{Han}a-zA-Z0-9._-]+).*\s*:\s*(?:#.*)?$`), useScreenInScreen: regexp.MustCompile(`^\s*use\s+(\w*).*(?:#.*)?$`), screenToScreen: regexp.MustCompile(`^\s*action\s+.*Show\("(.*?)".*\).*(?:#.*)?$`), screenToLabel: regexp.MustCompile(`^\s*action\s+.*(?:Jump|Call)\("(.*?)".*\).*(?:#.*)?$`), labelToScreen: regexp.MustCompile(`^\s*call\s+screen (\w*).*(?:#.*)?$`), - label: regexp.MustCompile(`^\s*label\s+([a-zA-Z0-9._-]+)(?:\([a-zA-Z0-9,_= \-"']*\))?\s*:\s*(?:#.*)?$`), - jump: regexp.MustCompile(`^\s*jump\s+([a-zA-Z0-9_.]+)\s*(?:#.*)?$`), - call: regexp.MustCompile(`^\s*call\s+(([a-zA-Z0-9_-]+)(?:\([a-zA-Z0-9,_= \-"']*\))?)\s*(?:#.*)?$`), + label: regexp.MustCompile(`^\s*label\s+([\p{Han}a-zA-Z0-9._-]+)(?:\([\p{Han}a-zA-Z0-9,_= \-"']*\))?\s*:\s*(?:#.*)?$`), + jump: regexp.MustCompile(`^\s*jump\s+([\p{Han}a-zA-Z0-9_.]+)\s*(?:#.*)?$`), + call: regexp.MustCompile(`^\s*call\s+(([\p{Han}a-zA-Z0-9_-]+)(?:\([\p{Han}a-zA-Z0-9,_= \-"']*\))?)\s*(?:#.*)?$`), comment: regexp.MustCompile(`^\s*(#.*)?$`), returns: regexp.MustCompile(`^\s{0,4}return\s*(?:#.*)?$`), menu: regexp.MustCompile(`^\s*menu.*:\s*(?:#.*)?$`),