summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-04-05 23:18:48 +0700
committerShulhan <ms@kilabit.info>2023-04-05 23:18:48 +0700
commit78e301986dceacc8daa7cb3f549859a005b2b9b8 (patch)
treeda23bb1292f838d4eb9c655f100797e87f730d9f
parent91c42d7ace627321785c3092d8956ab61f71ca20 (diff)
downloadpakakeh.go-78e301986dceacc8daa7cb3f549859a005b2b9b8.tar.xz
lib/hunspell: replace lib/parser with lib/strings
The lib/parser has been deprecated.
-rw-r--r--lib/hunspell/dictionary.go4
-rw-r--r--lib/hunspell/hunspell.go4
-rw-r--r--lib/hunspell/options.go3
-rw-r--r--lib/hunspell/stem.go9
-rw-r--r--lib/hunspell/tests/all_test.go4
-rw-r--r--lib/hunspell/tests/morphology.go22
6 files changed, 22 insertions, 24 deletions
diff --git a/lib/hunspell/dictionary.go b/lib/hunspell/dictionary.go
index aeca33b6..3ca6011f 100644
--- a/lib/hunspell/dictionary.go
+++ b/lib/hunspell/dictionary.go
@@ -11,7 +11,7 @@ import (
"strconv"
"strings"
- "github.com/shuLhan/share/lib/parser"
+ libstrings "github.com/shuLhan/share/lib/strings"
)
type dictionary struct {
@@ -35,7 +35,7 @@ func (dict *dictionary) open(file string, opts *affixOptions) (err error) {
// load dictionary from string.
func (dict *dictionary) load(content string, opts *affixOptions) (err error) {
- p := parser.New(content, "")
+ p := libstrings.NewParser(content, "")
// The string splitted into lines and then parsed one by one.
lines := p.Lines()
diff --git a/lib/hunspell/hunspell.go b/lib/hunspell/hunspell.go
index f998d293..914d242c 100644
--- a/lib/hunspell/hunspell.go
+++ b/lib/hunspell/hunspell.go
@@ -13,7 +13,7 @@ import (
"github.com/shuLhan/share/lib/ascii"
libio "github.com/shuLhan/share/lib/io"
- "github.com/shuLhan/share/lib/parser"
+ libstrings "github.com/shuLhan/share/lib/strings"
)
// List of affix file general options.
@@ -182,7 +182,7 @@ func MergeDictionaries(outFile string, inFiles ...string) (n int, err error) {
dict := make(map[string]string, 1024)
for x := 0; x < len(inFiles); x++ {
- lines, err := parser.Lines(inFiles[x])
+ lines, err := libstrings.LinesOfFile(inFiles[x])
if err != nil {
return 0, err
}
diff --git a/lib/hunspell/options.go b/lib/hunspell/options.go
index f285ebd6..539e6817 100644
--- a/lib/hunspell/options.go
+++ b/lib/hunspell/options.go
@@ -13,7 +13,6 @@ import (
"strings"
"unicode/utf8"
- "github.com/shuLhan/share/lib/parser"
libstrings "github.com/shuLhan/share/lib/strings"
)
@@ -175,7 +174,7 @@ func (opts *affixOptions) open(file string) (err error) {
// load affix options from string.
func (opts *affixOptions) load(content string) (err error) {
- p := parser.New(content, "")
+ p := libstrings.NewParser(content, "")
lines := p.Lines()
diff --git a/lib/hunspell/stem.go b/lib/hunspell/stem.go
index fe285a68..126d3ef5 100644
--- a/lib/hunspell/stem.go
+++ b/lib/hunspell/stem.go
@@ -9,7 +9,7 @@ import (
"strconv"
"strings"
- "github.com/shuLhan/share/lib/parser"
+ libstrings "github.com/shuLhan/share/lib/strings"
)
// Stem contains the word and its attributes.
@@ -81,16 +81,17 @@ func (stem *Stem) Analyze() Morphemes {
// STEM := WORD [ " " WORD ] [ "/" FLAGS ] [ *MORPHEME ]
func (stem *Stem) parse(line string) (err error) {
var (
+ p = libstrings.NewParser(line, " \t")
+
token string
sep rune
nwords int
- p = parser.New(line, " \t")
)
// Parse one or two words with optional flags, and possibly one
// morpheme.
for {
- token, sep = p.Token()
+ token, sep = p.Read()
if len(token) == 0 {
return nil
}
@@ -131,7 +132,7 @@ func (stem *Stem) parse(line string) (err error) {
}
// Parse the rest of morphemes.
for {
- token, _ = p.Token()
+ token, _ = p.Read()
if len(token) == 0 {
break
}
diff --git a/lib/hunspell/tests/all_test.go b/lib/hunspell/tests/all_test.go
index ef85b871..61adde3d 100644
--- a/lib/hunspell/tests/all_test.go
+++ b/lib/hunspell/tests/all_test.go
@@ -11,7 +11,7 @@ import (
"testing"
"github.com/shuLhan/share/lib/hunspell"
- "github.com/shuLhan/share/lib/parser"
+ libstrings "github.com/shuLhan/share/lib/strings"
"github.com/shuLhan/share/lib/test"
)
@@ -37,7 +37,7 @@ func TestHunspell(t *testing.T) {
t.Fatalf("%s: %s", affFile, err)
}
- exps, err := parser.Lines(goodFile)
+ exps, err := libstrings.LinesOfFile(goodFile)
if err != nil {
t.Fatalf("%s: %s", goodFile, err)
}
diff --git a/lib/hunspell/tests/morphology.go b/lib/hunspell/tests/morphology.go
index 3054ac8b..d6042eff 100644
--- a/lib/hunspell/tests/morphology.go
+++ b/lib/hunspell/tests/morphology.go
@@ -8,7 +8,7 @@ import (
"fmt"
"github.com/shuLhan/share/lib/hunspell"
- "github.com/shuLhan/share/lib/parser"
+ libstrings "github.com/shuLhan/share/lib/strings"
)
const (
@@ -24,7 +24,7 @@ type morphology struct {
}
func parseMorphologiesFile(morphFile string) (morphs map[string]morphology, err error) {
- lines, err := parser.Lines(morphFile)
+ lines, err := libstrings.LinesOfFile(morphFile)
if err != nil {
return nil, err
}
@@ -82,11 +82,11 @@ func (morph *morphology) parseAnalyze(line string) (err error) {
sep rune
)
for {
- token, sep = p.Token()
+ token, sep = p.Read()
if sep == 0 {
break
}
- morph.analyze[token], _ = p.Token()
+ morph.analyze[token], _ = p.Read()
p.SkipHorizontalSpaces()
}
return nil
@@ -98,19 +98,17 @@ func (morph *morphology) parseStem(line string) (err error) {
return fmt.Errorf("parseStem: %w", err)
}
- morph.stem, _ = p.Token()
+ morph.stem, _ = p.Read()
return nil
}
-func (morph *morphology) initParser(line, exp string) (
- p *parser.Parser, err error,
-) {
- p = parser.New(line, "()=: \t")
+func (morph *morphology) initParser(line, exp string) (p *libstrings.Parser, err error) {
+ p = libstrings.NewParser(line, "()=: \t")
p.SkipHorizontalSpaces()
- token, sep := p.Token()
+ token, sep := p.Read()
if token != exp {
return nil, fmt.Errorf("expecting %q, got %q", exp, token)
}
@@ -120,7 +118,7 @@ func (morph *morphology) initParser(line, exp string) (
p.SkipHorizontalSpaces()
- token, sep = p.Token()
+ token, sep = p.Read()
if sep != ')' {
return nil, fmt.Errorf("expecting ')', got %q", sep)
}
@@ -130,7 +128,7 @@ func (morph *morphology) initParser(line, exp string) (
p.SkipHorizontalSpaces()
- token, sep = p.Token()
+ token, sep = p.Read()
if sep != '=' {
return nil, fmt.Errorf("expecting '=', got %q", sep)
}