Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Typescript compiler #155

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ matrix:
- language: node_js
node_js: "node"
env: NODE=node
- language: node_ts
node_ts: "node"
env: NODE=node
- language: rust
rust:
- stable
Expand Down
58 changes: 56 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ python_sample_dir = sample
js_output_dir = js_out
js_runtime_dir = javascript
js_sample_dir = sample

ts_output_dir = ts_out
ts_runtime_dir = typescript
ts_sample_dir = sample

NODE ?= nodejs

cargo ?= cargo
Expand Down Expand Up @@ -69,6 +74,7 @@ COMPILER_SOURCES = compiler/space.c \
compiler/generator_csharp.c \
compiler/generator_java.c \
compiler/generator_js.c \
compiler/generator_ts.c \
compiler/generator_pascal.c \
compiler/generator_python.c \
compiler/generator_rust.c \
Expand Down Expand Up @@ -100,6 +106,10 @@ JS_RUNTIME_SOURCES = javascript/base-stemmer.js

JS_SAMPLE_SOURCES = javascript/stemwords.js

TS_RUNTIME_SOURCES = typescript/BaseStemmer.ts

TS_SAMPLE_SOURCES = typescript/stemWords.ts

PASCAL_RUNTIME_SOURCES = pascal/SnowballProgram.pas

PASCAL_STEMWORDS_SOURCES = pascal/stemwords.dpr
Expand Down Expand Up @@ -144,6 +154,7 @@ PASCAL_SOURCES = $(ISO_8859_1_algorithms:%=$(pascal_src_dir)/%Stemmer.pas)
PYTHON_SOURCES = $(libstemmer_algorithms:%=$(python_output_dir)/%_stemmer.py) \
$(python_output_dir)/__init__.py
JS_SOURCES = $(libstemmer_algorithms:%=$(js_output_dir)/%-stemmer.js)
TS_SOURCES = $(libstemmer_algorithms:%=$(ts_output_dir)/%-stemmer.ts)
RUST_SOURCES = $(libstemmer_algorithms:%=$(rust_src_dir)/%_stemmer.rs)
GO_SOURCES = $(libstemmer_algorithms:%=$(go_src_dir)/%_stemmer.go) \
$(go_src_main_dir)/stemwords/algorithms.go
Expand Down Expand Up @@ -331,6 +342,13 @@ $(js_output_dir)/%-stemmer.js: algorithms/%.sbl snowball
echo "./snowball $< -js -o $${o}"; \
./snowball $< -js -o $${o}

$(ts_output_dir)/%-stemmer.ts: algorithms/%.sbl snowball
@mkdir -p $(ts_output_dir)
@l=`echo "$<" | sed 's!\(.*\)\.sbl$$!\1!;s!^.*/!!'`; \
o="$(ts_output_dir)/$${l}-stemmer"; \
echo "./snowball $< -ts -o $${o}"; \
./snowball $< -ts -o $${o}

$(ada_src_dir)/stemmer-%.ads: algorithms/%.sbl snowball
@mkdir -p $(ada_src_dir)
@l=`echo "$<" | sed 's!\(.*\)\.sbl$$!\1!;s!^.*/!!'`; \
Expand All @@ -339,7 +357,7 @@ $(ada_src_dir)/stemmer-%.ads: algorithms/%.sbl snowball
./snowball $< -ada -P $${l} -o $${o}

# Make a full source distribution
dist: dist_snowball dist_libstemmer_c dist_libstemmer_csharp dist_libstemmer_java dist_libstemmer_js dist_libstemmer_python
dist: dist_snowball dist_libstemmer_c dist_libstemmer_csharp dist_libstemmer_java dist_libstemmer_js dist_libstemmer_ts dist_libstemmer_python

# Make a distribution of all the sources involved in snowball
dist_snowball: $(COMPILER_SOURCES) $(COMPILER_HEADERS) \
Expand Down Expand Up @@ -489,6 +507,24 @@ dist_libstemmer_js: $(JS_SOURCES)
(cd dist && tar zcf $${destname}$(tarball_ext) $${destname}) && \
rm -rf $${dest}

dist_libstemmer_ts: $(TS_SOURCES)
destname=tsstemmer-$(SNOWBALL_VERSION); \
dest=dist/$${destname}; \
rm -rf $${dest} && \
rm -f $${dest}$(tarball_ext) && \
mkdir -p $${dest} && \
mkdir -p $${dest}/$(ts_runtime_dir) && \
mkdir -p $${dest}/$(ts_sample_dir) && \
cp -a doc/libstemmer_ts_README $${dest}/README.rst && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no doc/libstemmer_ts_README so make dist fails (hence the CI failures)

cp -a $(COMMON_FILES) $${dest} && \
cp -a $(TS_RUNTIME_SOURCES) $${dest}/$(ts_runtime_dir) && \
cp -a $(TS_SAMPLE_SOURCES) $${dest}/$(ts_sample_dir) && \
cp -a $(TS_SOURCES) $${dest}/$(ts_runtime_dir) && \
(cd $${dest} && \
ls README.rst $(COMMON_FILES) $(ts_runtime_dir)/*.ts $(ts_sample_dir)/*.ts > MANIFEST) && \
(cd dist && tar zcf $${destname}$(tarball_ext) $${destname}) && \
rm -rf $${dest}

check: check_stemtest check_utf8 check_iso_8859_1 check_iso_8859_2 check_koi8r

check_stemtest: stemtest
Expand Down Expand Up @@ -603,6 +639,8 @@ check_pascal_%: $(STEMMING_DATA_ABS)/%

check_js: $(JS_SOURCES) $(libstemmer_algorithms:%=check_js_%)

check_ts: $(TS_SOURCES) $(libstemmer_algorithms:%=check_ts_%)

# Keep one in $(THIN_FACTOR) entries from gzipped vocabularies.
THIN_FACTOR ?= 3

Expand Down Expand Up @@ -647,7 +685,7 @@ check_go_%: $(STEMMING_DATA_ABS)/%
fi
@rm tmp.txt

export NODE_PATH = $(js_runtime_dir):$(js_output_dir)
export NODE_PATH = $(js_runtime_dir):$(js_output_dir):$(ts_runtime_dir):$(ts_output_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner to arrange to set this to just the paths that are relevant depending on whether we're doing javascript or typescript - then we don't have to worry that we might be pulling parts of the other one when running tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all Greek to me. I just did some guessing :)


check_js_%: $(STEMMING_DATA)/%
@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer for JS"
Expand All @@ -665,6 +703,22 @@ check_js_%: $(STEMMING_DATA)/%
fi
@rm tmp.txt

check_ts_%: $(STEMMING_DATA)/%
@echo "Checking output of `echo $<|sed 's!.*/!!'` stemmer for TS"
@if test -f '$</voc.txt.gz' ; then \
gzip -dc '$</voc.txt.gz'|$(THIN_TEST_DATA) > tmp.in; \
$(NODE) typescript/stemWords.ts -l `echo $<|sed 's!.*/!!'` -i tmp.in -o tmp.txt; \
rm tmp.in; \
else \
$(NODE) typescript/stemWords.ts -l `echo $<|sed 's!.*/!!'` -i $</voc.txt -o tmp.txt; \
fi
@if test -f '$</output.txt.gz' ; then \
gzip -dc '$</output.txt.gz'|$(THIN_TEST_DATA)|diff -u - tmp.txt; \
else \
diff -u $</output.txt tmp.txt; \
fi
@rm tmp.txt

check_python: check_python_stemwords $(libstemmer_algorithms:%=check_python_%)

check_python_%: $(STEMMING_DATA_ABS)/%
Expand Down
27 changes: 27 additions & 0 deletions compiler/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#define DEFAULT_JS_BASE_CLASS "BaseStemmer"

#define DEFAULT_TS_BASE_CLASS "BaseStemmer"

#define DEFAULT_PYTHON_BASE_CLASS "BaseStemmer"

static int eq(const char * s1, const char * s2) {
Expand Down Expand Up @@ -51,6 +53,9 @@ static void print_arglist(int exit_code) {
#ifndef DISABLE_JS
" -js\n"
#endif
#ifndef DISABLE_TS
" -ts\n"
#endif
#ifndef DISABLE_RUST
" -rust\n"
#endif
Expand Down Expand Up @@ -156,6 +161,12 @@ static int read_options(struct options * o, int argc, char * argv[]) {
continue;
}
#endif
#ifndef DISABLE_TS
if (eq(s, "-ts")) {
o->make_lang = LANG_TYPESCRIPT;
continue;
}
#endif
#ifndef DISABLE_RUST
if (eq(s, "-rust")) {
o->make_lang = LANG_RUST;
Expand Down Expand Up @@ -346,6 +357,11 @@ static int read_options(struct options * o, int argc, char * argv[]) {
if (!o->parent_class_name)
o->parent_class_name = DEFAULT_JS_BASE_CLASS;
break;
case LANG_TYPESCRIPT:
o->encoding = ENC_WIDECHARS;
if (!o->parent_class_name)
o->parent_class_name = DEFAULT_TS_BASE_CLASS;
break;
case LANG_PYTHON:
o->encoding = ENC_WIDECHARS;
if (!o->parent_class_name)
Expand Down Expand Up @@ -399,6 +415,7 @@ static int read_options(struct options * o, int argc, char * argv[]) {
new_name[0] = toupper(new_name[0]);
break;
case LANG_JAVASCRIPT:
case LANG_TYPESCRIPT:
case LANG_PYTHON: {
/* Upper case initial letter and change each
* underscore+letter or hyphen+letter to an upper case
Expand Down Expand Up @@ -542,6 +559,16 @@ extern int main(int argc, char * argv[]) {
fclose(o->output_src);
}
#endif
#ifndef DISABLE_TS
if (o->make_lang == LANG_TYPESCRIPT) {
symbol * b = add_s_to_b(0, s);
b = add_s_to_b(b, ".ts");
o->output_src = get_output(b);
lose_b(b);
generate_program_ts(g);
fclose(o->output_src);
}
#endif
#ifndef DISABLE_CSHARP
if (o->make_lang == LANG_CSHARP) {
symbol * b = add_s_to_b(0, s);
Expand Down
Loading