mittens 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/Rakefile +10 -3
- data/lib/mittens/version.rb +1 -1
- data/vendor/snowball/.github/workflows/ci.yml +144 -17
- data/vendor/snowball/.github/workflows/coverage.yml +117 -0
- data/vendor/snowball/.github/workflows/runtime-tests.yml +26 -0
- data/vendor/snowball/.gitignore +33 -7
- data/vendor/snowball/CONTRIBUTING.rst +7 -0
- data/vendor/snowball/COPYING +1 -1
- data/vendor/snowball/GNUmakefile +736 -298
- data/vendor/snowball/NEWS +1394 -7
- data/vendor/snowball/README.rst +8 -8
- data/vendor/snowball/ada/generate/generate.adb +5 -5
- data/vendor/snowball/ada/src/stemmer.adb +177 -188
- data/vendor/snowball/ada/src/stemmer.ads +86 -89
- data/vendor/snowball/ada/src/stemwords.adb +21 -5
- data/vendor/snowball/algorithms/czech.sbl +255 -0
- data/vendor/snowball/algorithms/danish.sbl +22 -10
- data/vendor/snowball/algorithms/english.sbl +7 -4
- data/vendor/snowball/algorithms/esperanto.sbl +6 -7
- data/vendor/snowball/algorithms/estonian.sbl +9 -4
- data/vendor/snowball/algorithms/finnish.sbl +33 -21
- data/vendor/snowball/algorithms/german.sbl +5 -0
- data/vendor/snowball/algorithms/indonesian.sbl +115 -96
- data/vendor/snowball/algorithms/italian.sbl +26 -1
- data/vendor/snowball/algorithms/lithuanian.sbl +13 -13
- data/vendor/snowball/algorithms/norwegian.sbl +17 -6
- data/vendor/snowball/algorithms/persian.sbl +387 -0
- data/vendor/snowball/algorithms/polish.sbl +177 -0
- data/vendor/snowball/algorithms/sesotho.sbl +115 -0
- data/vendor/snowball/algorithms/turkish.sbl +4 -4
- data/vendor/snowball/compiler/analyser.c +2002 -711
- data/vendor/snowball/compiler/driver.c +460 -298
- data/vendor/snowball/compiler/generator.c +439 -1965
- data/vendor/snowball/compiler/generator_ada.c +605 -430
- data/vendor/snowball/compiler/generator_c.c +2227 -0
- data/vendor/snowball/compiler/generator_csharp.c +365 -274
- data/vendor/snowball/compiler/generator_dart.c +1476 -0
- data/vendor/snowball/compiler/generator_go.c +348 -270
- data/vendor/snowball/compiler/generator_java.c +330 -233
- data/vendor/snowball/compiler/generator_js.c +534 -385
- data/vendor/snowball/compiler/generator_pascal.c +361 -320
- data/vendor/snowball/compiler/generator_php.c +1445 -0
- data/vendor/snowball/compiler/generator_python.c +399 -299
- data/vendor/snowball/compiler/generator_rust.c +370 -261
- data/vendor/snowball/compiler/generator_zig.c +1474 -0
- data/vendor/snowball/compiler/header.h +153 -86
- data/vendor/snowball/compiler/space.c +121 -63
- data/vendor/snowball/compiler/tokeniser.c +286 -182
- data/vendor/snowball/compiler/tokens.h +71 -0
- data/vendor/snowball/csharp/Snowball/Among.cs +14 -26
- data/vendor/snowball/csharp/Snowball/AssemblyInfo.cs +3 -3
- data/vendor/snowball/csharp/Snowball/Stemmer.cs +41 -45
- data/vendor/snowball/csharp/Stemwords/Program.cs +20 -14
- data/vendor/snowball/cxx/.gitignore +4 -0
- data/vendor/snowball/cxx/generate_algorithms.pl +87 -0
- data/vendor/snowball/cxx/stemmer.h +12 -0
- data/vendor/snowball/cxx/stemwords.cxx +176 -0
- data/vendor/snowball/cxx/utilities.cxx +2 -0
- data/vendor/snowball/dart/.gitignore +4 -0
- data/vendor/snowball/dart/analysis_options.yaml +1 -0
- data/vendor/snowball/dart/example/test_app.dart +65 -0
- data/vendor/snowball/dart/generate_algorithms.pl +21 -0
- data/vendor/snowball/dart/lib/snowball.dart +18 -0
- data/vendor/snowball/dart/lib/src/snowball.dart +339 -0
- data/vendor/snowball/dart/pubspec.yaml +17 -0
- data/vendor/snowball/doc/libstemmer_dart_README +37 -0
- data/vendor/snowball/doc/libstemmer_js_README +2 -2
- data/vendor/snowball/doc/libstemmer_php_README +38 -0
- data/vendor/snowball/doc/libstemmer_python_README +3 -3
- data/vendor/snowball/examples/stemwords.c +18 -3
- data/vendor/snowball/go/README.md +12 -4
- data/vendor/snowball/go/env.go +12 -14
- data/vendor/snowball/go/stemwords/main.go +2 -1
- data/vendor/snowball/java/org/tartarus/snowball/CharArraySequence.java +36 -0
- data/vendor/snowball/java/org/tartarus/snowball/SnowballProgram.java +17 -34
- data/vendor/snowball/java/org/tartarus/snowball/SnowballStemmer.java +0 -2
- data/vendor/snowball/javascript/base-stemmer.js +219 -252
- data/vendor/snowball/javascript/stemwords.js +86 -58
- data/vendor/snowball/libstemmer/mkmodules.pl +1 -1
- data/vendor/snowball/libstemmer/modules.txt +4 -0
- data/vendor/snowball/pascal/SnowballProgram.pas +18 -31
- data/vendor/snowball/php/base-stemmer.php +453 -0
- data/vendor/snowball/php/stemwords.php +25 -0
- data/vendor/snowball/python/create_init.py +16 -21
- data/vendor/snowball/python/pyproject.toml +3 -0
- data/vendor/snowball/python/setup.py +5 -7
- data/vendor/snowball/python/snowballstemmer/among.py +1 -2
- data/vendor/snowball/python/snowballstemmer/basestemmer.py +24 -33
- data/vendor/snowball/python/stemwords.py +72 -63
- data/vendor/snowball/runtime/api.c +11 -42
- data/vendor/snowball/runtime/api.h +11 -9
- data/vendor/snowball/runtime/snowball_runtime.h +110 -0
- data/vendor/snowball/runtime/utilities.c +282 -106
- data/vendor/snowball/rust/src/main.rs +2 -2
- data/vendor/snowball/rust/src/snowball/snowball_env.rs +7 -9
- data/vendor/snowball/tests/compilertest +62 -0
- data/vendor/snowball/tests/errors/ae-errors.sbl +53 -0
- data/vendor/snowball/tests/errors/ae-errors.stderr +8 -0
- data/vendor/snowball/tests/errors/bad-dollar.sbl +14 -0
- data/vendor/snowball/tests/errors/bad-dollar.stderr +4 -0
- data/vendor/snowball/tests/errors/bad-grouping-definition.sbl +9 -0
- data/vendor/snowball/tests/errors/bad-grouping-definition.stderr +6 -0
- data/vendor/snowball/tests/errors/missing-bra.sbl +6 -0
- data/vendor/snowball/tests/errors/missing-bra.stderr +3 -0
- data/vendor/snowball/tests/errors/missing-command.sbl +9 -0
- data/vendor/snowball/tests/errors/missing-command.stderr +1 -0
- data/vendor/snowball/tests/errors/missing-ket-backwardmode.sbl +3 -0
- data/vendor/snowball/tests/errors/missing-ket-backwardmode.stderr +1 -0
- data/vendor/snowball/tests/errors/missing-ket.sbl +7 -0
- data/vendor/snowball/tests/errors/missing-ket.stderr +6 -0
- data/vendor/snowball/tests/errors/notdefined.sbl +4 -0
- data/vendor/snowball/tests/errors/notdefined.stderr +2 -0
- data/vendor/snowball/tests/errors/string-omitted.sbl +5 -0
- data/vendor/snowball/tests/errors/string-omitted.stderr +1 -0
- data/vendor/snowball/tests/errors/undeclared.sbl +20 -0
- data/vendor/snowball/tests/errors/undeclared.stderr +9 -0
- data/vendor/snowball/tests/errors/unexpected-token.sbl +24 -0
- data/vendor/snowball/tests/errors/unexpected-token.stderr +17 -0
- data/vendor/snowball/tests/errors/wrongdirection.sbl +14 -0
- data/vendor/snowball/tests/errors/wrongdirection.stderr +1 -0
- data/vendor/snowball/tests/runtime/among.sbl +19 -0
- data/vendor/snowball/tests/runtime/arithmeticexpr.sbl +86 -0
- data/vendor/snowball/tests/runtime/attachinsert.sbl +47 -0
- data/vendor/snowball/tests/runtime/booleans.sbl +19 -0
- data/vendor/snowball/tests/runtime/externals.sbl +22 -0
- data/vendor/snowball/tests/runtime/hop.sbl +12 -0
- data/vendor/snowball/tests/runtime/integertests.sbl +60 -0
- data/vendor/snowball/tests/runtime/intlimits.sbl +25 -0
- data/vendor/snowball/tests/runtime/naming.sbl +20 -0
- data/vendor/snowball/tests/runtime/not.sbl +30 -0
- data/vendor/snowball/tests/runtime/or.sbl +17 -0
- data/vendor/snowball/tests/runtime/repeat.sbl +16 -0
- data/vendor/snowball/tests/runtime/setlimit.sbl +24 -0
- data/vendor/snowball/tests/runtime/sizelen.sbl +56 -0
- data/vendor/snowball/tests/runtime/slice.sbl +27 -0
- data/vendor/snowball/tests/runtime/stringdollar.sbl +39 -0
- data/vendor/snowball/tests/runtime/strings.sbl +66 -0
- data/vendor/snowball/tests/runtime/test.sbl +19 -0
- data/vendor/snowball/tests/stemtest.c +41 -1
- data/vendor/snowball/tests/syntax/canon.sbl +32 -0
- data/vendor/snowball/tests/syntax/canon.stderr +0 -0
- data/vendor/snowball/tests/syntax/canon.syntax +57 -0
- data/vendor/snowball/tests/syntax/emptyprogram.sbl +2 -0
- data/vendor/snowball/tests/syntax/emptyprogram.syntax +0 -0
- data/vendor/snowball/tests/syntax/groupings.sbl +11 -0
- data/vendor/snowball/tests/syntax/inline.sbl +144 -0
- data/vendor/snowball/tests/syntax/inline.stderr +0 -0
- data/vendor/snowball/tests/syntax/inline.syntax +121 -0
- data/vendor/snowball/tests/syntax/legacy.sbl +17 -0
- data/vendor/snowball/tests/syntax/legacy.stderr +5 -0
- data/vendor/snowball/tests/syntax/legacy.syntax +19 -0
- data/vendor/snowball/tests/syntax/loops.sbl +14 -0
- data/vendor/snowball/tests/syntax/loops.stderr +9 -0
- data/vendor/snowball/tests/syntax/loops.syntax +29 -0
- data/vendor/snowball/tests/syntax/noops.sbl +76 -0
- data/vendor/snowball/tests/syntax/noops.stderr +27 -0
- data/vendor/snowball/tests/syntax/noops.syntax +135 -0
- data/vendor/snowball/tests/syntax/simplifyae.sbl +21 -0
- data/vendor/snowball/tests/syntax/simplifyae.stderr +0 -0
- data/vendor/snowball/tests/syntax/simplifyae.syntax +39 -0
- data/vendor/snowball/tests/syntax/unused.sbl +18 -0
- data/vendor/snowball/tests/syntax/unused.stderr +7 -0
- data/vendor/snowball/tests/syntax/unused.syntax +3 -0
- data/vendor/snowball/zig/env.zig +599 -0
- data/vendor/snowball/zig/generate_algorithms.pl +19 -0
- data/vendor/snowball/zig/stemwords.zig +123 -0
- metadata +102 -4
- data/vendor/snowball/compiler/syswords.h +0 -86
- data/vendor/snowball/runtime/header.h +0 -62
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
import codecs
|
|
3
2
|
import snowballstemmer
|
|
4
3
|
|
|
5
4
|
def usage():
|
|
@@ -25,73 +24,83 @@ line.
|
|
|
25
24
|
-h displays this help''' % sys.argv[0])
|
|
26
25
|
|
|
27
26
|
def main():
|
|
27
|
+
pretty = 0
|
|
28
|
+
input = ''
|
|
29
|
+
output = ''
|
|
30
|
+
encoding = 'utf_8'
|
|
31
|
+
language = 'English'
|
|
32
|
+
show_help = False
|
|
28
33
|
argv = sys.argv[1:]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
while len(argv):
|
|
35
|
+
arg = argv.pop(0)
|
|
36
|
+
if arg == '-h':
|
|
37
|
+
show_help = True
|
|
38
|
+
break
|
|
39
|
+
elif arg == "-p":
|
|
40
|
+
pretty = 1
|
|
41
|
+
elif arg == "-p2":
|
|
42
|
+
pretty = 2
|
|
43
|
+
elif arg == "-l":
|
|
44
|
+
if len(argv) == 0:
|
|
45
|
+
show_help = True
|
|
46
|
+
break
|
|
47
|
+
language = argv.pop(0)
|
|
48
|
+
elif arg == "-i":
|
|
49
|
+
if len(argv) == 0:
|
|
50
|
+
show_help = True
|
|
51
|
+
break
|
|
52
|
+
input = argv.pop(0)
|
|
53
|
+
elif arg == "-o":
|
|
54
|
+
if len(argv) == 0:
|
|
41
55
|
show_help = True
|
|
42
56
|
break
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
elif arg == "-c":
|
|
63
|
-
if len(argv) == 0:
|
|
64
|
-
show_help = True
|
|
65
|
-
break
|
|
66
|
-
encoding = argv.pop(0)
|
|
67
|
-
if show_help or input == '' or output == '':
|
|
68
|
-
usage()
|
|
57
|
+
output = argv.pop(0)
|
|
58
|
+
elif arg == "-c":
|
|
59
|
+
if len(argv) == 0:
|
|
60
|
+
show_help = True
|
|
61
|
+
break
|
|
62
|
+
encoding = argv.pop(0)
|
|
63
|
+
if show_help:
|
|
64
|
+
usage()
|
|
65
|
+
else:
|
|
66
|
+
stemmer = snowballstemmer.stemmer(language)
|
|
67
|
+
if input != '':
|
|
68
|
+
infile = open(input, "r", encoding=encoding)
|
|
69
|
+
else:
|
|
70
|
+
infile = sys.stdin
|
|
71
|
+
# reconfigure() requires Python 3.7 so check existing encoding.
|
|
72
|
+
if infile.encoding.lower() != encoding.lower():
|
|
73
|
+
infile.reconfigure(encoding = encoding)
|
|
74
|
+
if output != '':
|
|
75
|
+
outfile = open(output, "w", encoding=encoding)
|
|
69
76
|
else:
|
|
70
|
-
|
|
77
|
+
outfile = sys.stdout
|
|
78
|
+
if outfile.encoding.lower() != encoding.lower():
|
|
79
|
+
outfile.reconfigure(encoding = encoding)
|
|
80
|
+
stemming(stemmer, infile, outfile, pretty)
|
|
81
|
+
outfile.close()
|
|
82
|
+
infile.close()
|
|
71
83
|
|
|
72
84
|
|
|
73
|
-
def stemming(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
outfile.write(" " * 30)
|
|
94
|
-
outfile.write(stemmed)
|
|
95
|
-
outfile.write('\n')
|
|
85
|
+
def stemming(stemmer, infile, outfile, pretty):
|
|
86
|
+
for original in infile.readlines():
|
|
87
|
+
original = original.strip()
|
|
88
|
+
# Convert only ASCII-letters to lowercase, to match C behavior
|
|
89
|
+
original = ''.join(c.lower() if 'A' <= c <= 'Z' else c for c in original)
|
|
90
|
+
stemmed = stemmer.stemWord(original)
|
|
91
|
+
if pretty == 0:
|
|
92
|
+
if stemmed != "":
|
|
93
|
+
outfile.write(stemmed)
|
|
94
|
+
elif pretty == 1:
|
|
95
|
+
outfile.write(original, " -> ", stemmed)
|
|
96
|
+
elif pretty == 2:
|
|
97
|
+
outfile.write(original)
|
|
98
|
+
if len(original) < 30:
|
|
99
|
+
outfile.write(" " * (30 - len(original)))
|
|
100
|
+
else:
|
|
101
|
+
outfile.write("\n")
|
|
102
|
+
outfile.write(" " * 30)
|
|
103
|
+
outfile.write(stemmed)
|
|
104
|
+
outfile.write('\n')
|
|
96
105
|
|
|
97
106
|
main()
|
|
@@ -1,63 +1,32 @@
|
|
|
1
1
|
|
|
2
|
-
#include <stdlib.h> /* for malloc,
|
|
3
|
-
#include "
|
|
2
|
+
#include <stdlib.h> /* for malloc, free */
|
|
3
|
+
#include "snowball_runtime.h"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
static const struct SN_env default_SN_env;
|
|
6
|
+
|
|
7
|
+
extern struct SN_env * SN_new_env(int alloc_size)
|
|
6
8
|
{
|
|
7
|
-
|
|
8
|
-
struct SN_env * z = (struct SN_env *) malloc(sizeof(struct SN_env));
|
|
9
|
+
struct SN_env * z = (struct SN_env *) malloc(alloc_size);
|
|
9
10
|
if (z == NULL) return NULL;
|
|
10
11
|
*z = default_SN_env;
|
|
11
12
|
z->p = create_s();
|
|
12
|
-
if (z->p == NULL)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
int i;
|
|
16
|
-
z->S = (symbol * *) malloc(S_size * sizeof(symbol *));
|
|
17
|
-
if (z->S == NULL) goto error;
|
|
18
|
-
|
|
19
|
-
for (i = 0; i < S_size; i++)
|
|
20
|
-
{
|
|
21
|
-
z->S[i] = create_s();
|
|
22
|
-
if (z->S[i] == NULL) {
|
|
23
|
-
S_size = i;
|
|
24
|
-
goto error;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (I_size)
|
|
30
|
-
{
|
|
31
|
-
z->I = (int *) calloc(I_size, sizeof(int));
|
|
32
|
-
if (z->I == NULL) goto error;
|
|
13
|
+
if (z->p == NULL) {
|
|
14
|
+
SN_delete_env(z);
|
|
15
|
+
return NULL;
|
|
33
16
|
}
|
|
34
|
-
|
|
35
17
|
return z;
|
|
36
|
-
error:
|
|
37
|
-
SN_close_env(z, S_size);
|
|
38
|
-
return NULL;
|
|
39
18
|
}
|
|
40
19
|
|
|
41
|
-
extern void
|
|
20
|
+
extern void SN_delete_env(struct SN_env * z)
|
|
42
21
|
{
|
|
43
22
|
if (z == NULL) return;
|
|
44
|
-
if (z->S)
|
|
45
|
-
{
|
|
46
|
-
int i;
|
|
47
|
-
for (i = 0; i < S_size; i++)
|
|
48
|
-
{
|
|
49
|
-
lose_s(z->S[i]);
|
|
50
|
-
}
|
|
51
|
-
free(z->S);
|
|
52
|
-
}
|
|
53
|
-
free(z->I);
|
|
54
23
|
if (z->p) lose_s(z->p);
|
|
55
24
|
free(z);
|
|
56
25
|
}
|
|
57
26
|
|
|
58
27
|
extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
|
|
59
28
|
{
|
|
60
|
-
int err = replace_s(z, 0, z->l, size, s
|
|
29
|
+
int err = replace_s(z, 0, z->l, size, s);
|
|
61
30
|
z->c = 0;
|
|
62
31
|
return err;
|
|
63
32
|
}
|
|
@@ -1,32 +1,34 @@
|
|
|
1
|
+
#ifndef SNOWBALL_API_H_INCLUDED
|
|
2
|
+
#define SNOWBALL_API_H_INCLUDED
|
|
1
3
|
|
|
2
4
|
typedef unsigned char symbol;
|
|
3
5
|
|
|
4
6
|
/* Or replace 'char' above with 'short' for 16 bit characters.
|
|
5
7
|
|
|
6
8
|
More precisely, replace 'char' with whatever type guarantees the
|
|
7
|
-
character width you need.
|
|
8
|
-
HEAD, defined in header.h as 2*sizeof(int), without remainder, otherwise
|
|
9
|
-
there is an alignment problem. In the unlikely event of a problem here,
|
|
10
|
-
consult Martin Porter.
|
|
11
|
-
|
|
9
|
+
character width you need.
|
|
12
10
|
*/
|
|
13
11
|
|
|
14
12
|
struct SN_env {
|
|
15
13
|
symbol * p;
|
|
16
14
|
int c; int l; int lb; int bra; int ket;
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
int af;
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
SN_env() : p(), c(), l(), lb(), bra(), ket(), af() { }
|
|
18
|
+
#endif
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
#ifdef __cplusplus
|
|
22
22
|
extern "C" {
|
|
23
23
|
#endif
|
|
24
24
|
|
|
25
|
-
extern struct SN_env *
|
|
26
|
-
extern void
|
|
25
|
+
extern struct SN_env * SN_new_env(int alloc_size);
|
|
26
|
+
extern void SN_delete_env(struct SN_env * z);
|
|
27
27
|
|
|
28
28
|
extern int SN_set_current(struct SN_env * z, int size, const symbol * s);
|
|
29
29
|
|
|
30
30
|
#ifdef __cplusplus
|
|
31
31
|
}
|
|
32
32
|
#endif
|
|
33
|
+
|
|
34
|
+
#endif
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#ifndef SNOWBALL_INCLUDED_SNOWBALL_RUNTIME_H
|
|
2
|
+
#define SNOWBALL_INCLUDED_SNOWBALL_RUNTIME_H
|
|
3
|
+
|
|
4
|
+
#include "api.h"
|
|
5
|
+
|
|
6
|
+
#include <limits.h>
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
/* Use reinterpret_cast<> to avoid -Wcast-align warnings from clang++. */
|
|
10
|
+
# define SIZE(p) (reinterpret_cast<const int *>(p))[-1]
|
|
11
|
+
# define SET_SIZE(p, n) (reinterpret_cast<int *>(p))[-1] = n
|
|
12
|
+
# define CAPACITY(p) (reinterpret_cast<int *>(p))[-2]
|
|
13
|
+
#else
|
|
14
|
+
# define SIZE(p) ((const int *)(p))[-1]
|
|
15
|
+
# define SET_SIZE(p, n) ((int *)(p))[-1] = n
|
|
16
|
+
# define CAPACITY(p) ((int *)(p))[-2]
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#ifdef SNOWBALL_RUNTIME_THROW_EXCEPTIONS
|
|
20
|
+
# define SNOWBALL_ERR void
|
|
21
|
+
#else
|
|
22
|
+
# define SNOWBALL_ERR int
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#ifdef SNOWBALL_DEBUG_COMMAND_USED
|
|
26
|
+
# include <stdio.h>
|
|
27
|
+
static void debug(struct SN_env * z, int n, int line) {
|
|
28
|
+
int i;
|
|
29
|
+
int len = SIZE(z->p);
|
|
30
|
+
printf("%3d (line %4d): [%d]'", n, line, len);
|
|
31
|
+
for (i = 0; i <= len; i++) {
|
|
32
|
+
if (z->lb == i) printf("{");
|
|
33
|
+
if (z->bra == i) printf("[");
|
|
34
|
+
if (z->c == i) printf("|");
|
|
35
|
+
if (z->ket == i) printf("]");
|
|
36
|
+
if (z->l == i) printf("}");
|
|
37
|
+
if (i < len) {
|
|
38
|
+
int ch = z->p[i];
|
|
39
|
+
if (ch == 0) ch = '#';
|
|
40
|
+
printf("%c", ch);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
printf("'\n");
|
|
44
|
+
}
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
struct among
|
|
48
|
+
{
|
|
49
|
+
/* Number of symbols in s. */
|
|
50
|
+
int s_size;
|
|
51
|
+
/* Search string. */
|
|
52
|
+
const symbol * s;
|
|
53
|
+
/* Delta of index to longest matching substring, or 0 if none. */
|
|
54
|
+
int substring_i;
|
|
55
|
+
/* Result of the lookup. */
|
|
56
|
+
int result;
|
|
57
|
+
/* Optional condition routine index, or 0 if none. */
|
|
58
|
+
int function;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/* MSVC doesn't like functions declared `extern "C"` throwing exceptions. */
|
|
62
|
+
#if defined __cplusplus && !defined SNOWBALL_RUNTIME_THROW_EXCEPTIONS
|
|
63
|
+
extern "C" {
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
extern symbol * create_s(void);
|
|
67
|
+
extern void lose_s(symbol * p);
|
|
68
|
+
|
|
69
|
+
extern int skip_utf8(const symbol * p, int c, int limit, int n);
|
|
70
|
+
|
|
71
|
+
extern int skip_b_utf8(const symbol * p, int c, int limit, int n);
|
|
72
|
+
|
|
73
|
+
extern int in_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
74
|
+
extern int in_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
75
|
+
extern int out_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
76
|
+
extern int out_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
77
|
+
|
|
78
|
+
extern int in_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
79
|
+
extern int in_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
80
|
+
extern int out_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
81
|
+
extern int out_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
|
|
82
|
+
|
|
83
|
+
extern int eq_s(struct SN_env * z, int s_size, const symbol * s);
|
|
84
|
+
extern int eq_s_b(struct SN_env * z, int s_size, const symbol * s);
|
|
85
|
+
extern int eq_v(struct SN_env * z, const symbol * p);
|
|
86
|
+
extern int eq_v_b(struct SN_env * z, const symbol * p);
|
|
87
|
+
|
|
88
|
+
extern int find_among(struct SN_env * z, const struct among * v, int v_size,
|
|
89
|
+
int (*)(struct SN_env *));
|
|
90
|
+
extern int find_among_b(struct SN_env * z, const struct among * v, int v_size,
|
|
91
|
+
int (*)(struct SN_env *));
|
|
92
|
+
|
|
93
|
+
extern SNOWBALL_ERR replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const symbol * s);
|
|
94
|
+
extern SNOWBALL_ERR slice_from_s(struct SN_env * z, int s_size, const symbol * s);
|
|
95
|
+
extern SNOWBALL_ERR slice_from_v(struct SN_env * z, const symbol * p);
|
|
96
|
+
extern SNOWBALL_ERR slice_del(struct SN_env * z);
|
|
97
|
+
|
|
98
|
+
extern SNOWBALL_ERR insert_s(struct SN_env * z, int bra, int ket, int s_size, const symbol * s);
|
|
99
|
+
extern SNOWBALL_ERR insert_v(struct SN_env * z, int bra, int ket, const symbol * p);
|
|
100
|
+
|
|
101
|
+
extern SNOWBALL_ERR slice_to(struct SN_env * z, symbol ** p);
|
|
102
|
+
extern SNOWBALL_ERR assign_to(struct SN_env * z, symbol ** p);
|
|
103
|
+
|
|
104
|
+
extern int len_utf8(const symbol * p);
|
|
105
|
+
|
|
106
|
+
#if defined __cplusplus && !defined SNOWBALL_RUNTIME_THROW_EXCEPTIONS
|
|
107
|
+
}
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
#endif
|