diff --git a/.gitignore b/.gitignore index bbaef55..1a3ef37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .cm/ sources +*.mlb.d diff --git a/Makefile.mlton b/Makefile.mlton new file mode 100644 index 0000000..bbd1374 --- /dev/null +++ b/Makefile.mlton @@ -0,0 +1,83 @@ + +MLTON := mlton +MLTON_FLAGS := -default-ann "nonexhaustiveMatch ignore" +ifneq ($(MLB_PATH_MAP),) +MLTON_FLAGS += -mlb-path-map $(MLB_PATH_MAP) +endif + +PREFIX := /usr/local/mlton + +LMLML_MLB := LMLML.mlb +LMLML_TEST_MLB := test/sources.mlb +LMLML_MLBS := $(LMLML_MLB) \ + $(LMLML_TEST_MLB) + +EXAMPLES := example/RegExp/example/Grep/sources + +EXAMPLE_MLB := $(EXAMPLES:=.mlb) + +LMLML_DIR := $(shell readlink -f .) + + +all: typecheck_lmlml test example + + +.PHONY: typecheck_lmlml +typecheck_lmlml: $(LMLML_MLB) + @echo " [MLTON] typecheck $<" + @$(MLTON) $(MLTON_FLAGS) -stop tc $< + + +$(EXAMPLE_MLB:.mlb=): MLTON_FLAGS += -mlb-path-var "LMLML $(LMLML_DIR)" +$(LMLML_TEST_MLB:.mlb=) $(EXAMPLE_MLB:.mlb=): %: %.mlb + @echo " [MLTON] $@" + @$(MLTON) $(MLTON_FLAGS) -output $@ $< + + +$(EXAMPLE_MLB:.mlb=.mlb.d): MLTON_FLAGS += -mlb-path-var "LMLML $(LMLML_DIR)" +%.mlb.d: %.mlb + @echo " [GEN] $@" + @$(SHELL) -ec '$(MLTON) $(MLTON_FLAGS) -stop f $< \ + | sed -e "1i$(<:.mlb=) $@:\\\\" -e "s|.*| & \\\\|" -e "\$$s| \\\\||" > $@; \ + [ -s $@ ] || rm -rf $@' + + +.PHONY: test +test: typecheck_lmlml $(LMLML_TEST_MLB:.mlb=) + $(LMLML_TEST_MLB:.mlb=) + + +.PHONY: example +example: typecheck_lmlml $(EXAMPLES) + + +ifeq ($(findstring clean,$(MAKECMDGOALS)),) +include $(LMLML_MLBS:.mlb=.mlb.d) +include $(EXAMPLE_MLB:.mlb=.mlb.d) +endif + + +.PHONY: install +install: typecheck_lmlml $(LMLML_MLB) + @[ -e $(PREFIX)/lib/LMLML ] || mkdir $(PREFIX)/lib/LMLML + @$(MLTON) $(MLTON_FLAGS) -stop f $(LMLML_MLB) | \ + while read file; do \ + if expr $$(readlink -f $$file) : ^$$(pwd) >/dev/null; then \ + cp --parents $$(realpath --relative-to=$$(pwd) $$file) $(PREFIX)/lib/LMLML; \ + echo -n . ; \ + fi; \ + done + @echo "Installation has been completed." + @echo "Please add the entry to your mlb path map file:" + @echo "" + @echo " LMLML $(PREFIX)/lib/LMLML" + @echo "" + + +.PHONY: clean +clean: + -$(RM) $(LMLML_MLBS:.mlb=) + -$(RM) $(LMLML_MLBS:.mlb=.mlb.d) + -$(RM) $(EXAMPLES) + -$(RM) $(EXAMPLE_MLB:.mlb=.mlb.d) + diff --git a/Readme.md b/Readme.md index cd57638..de9d3c2 100644 --- a/Readme.md +++ b/Readme.md @@ -75,26 +75,62 @@ val it = true : bool ### Install -Insert mapping entry to `mlb-path-map`. +To install [LMLML] for MLton, use `Makefile.mlton`. ```sh -$ echo 'LMLML /path/to/LMLML' >> $MLTON_ROOT/mlb-path-map +$ make -f Makefile.mlton install + [MLTON] typecheck LMLML.mlb +..............................Installation has been completed. +Please add the entry to your mlb path map file: + + LMLML /usr/local/mlton/lib/LMLML + +``` + +This command install this library to `/usr/local/mlton/lib/LMLML` by default. +It is able to change the location with `PREFIX` variable like: + +```sh +$ make -f Makefile.mlton PREFIX=~/.sml/mlton install +``` + +After `make install`, you need to add an entry in a mlb path mapping file: + +```sh +$ echo 'LMLML $(PREFIX)/lib/LMLML' >> /path/to/mlb-path-map ``` -Refer to `$(LMLML)/LMLML.mlb` from your `sources.mlb`. +Refer to `$(LMLML)/LMLML.mlb` from your mlbasis files. ### Test +Perform unit tests for [LMLML], execute `test` target: + ```sh -$ mlton test/sources.mlb -$ ./test/sources -..........................................................................F.F..F............................... -..................................................E.............................F.F.EF......................... +$ make -f Makefile.mlton MLB_PATH_MAP=~/.sml/mlton/mlb-path-map + [MLTON] typecheck LMLML.mlb + [MLTON] test/sources +test/sources +..........................................................................F.F..F...................................... +...........................................E.............................F.F.EF....................................... +..........................................E.............................F.F.EF........................................ . . ``` +### Example + +The `example` target builds `Grep` and `SuffixArray` examples. + +- `Grep` (./example/RegExp/example/Grep/sources) is a multilingualized grep. + `sources ` read input string from stdin per line, and checking the contents of the line matches to the regexp pattern. + If the line matches to the pattern, print it. + + +- `SuffixArray` (./example/SuffixArray/main/sources) is a multilingualized full text search. + `sources ` searches fragments match to the pattern. + ## License diff --git a/example/SuffixArray/main/call-main.sml b/example/SuffixArray/main/call-main.sml new file mode 100644 index 0000000..359f6ea --- /dev/null +++ b/example/SuffixArray/main/call-main.sml @@ -0,0 +1 @@ +SuffixArray.main (CommandLine.name(), CommandLine.arguments()); diff --git a/example/SuffixArray/main/sources.mlb b/example/SuffixArray/main/sources.mlb new file mode 100644 index 0000000..c3832d9 --- /dev/null +++ b/example/SuffixArray/main/sources.mlb @@ -0,0 +1,6 @@ +$(SML_LIB)/basis/basis.mlb +$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb +../../../main/sources.mlb +SuffixArray.sml +call-main.sml +