Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.cm/
sources
*.mlb.d
83 changes: 83 additions & 0 deletions Makefile.mlton
Original file line number Diff line number Diff line change
@@ -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)

50 changes: 43 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <codec> <regex>` 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 <code> <infile> <pattern>` searches fragments match to the pattern.


## License

Expand Down
1 change: 1 addition & 0 deletions example/SuffixArray/main/call-main.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SuffixArray.main (CommandLine.name(), CommandLine.arguments());
6 changes: 6 additions & 0 deletions example/SuffixArray/main/sources.mlb
Original file line number Diff line number Diff line change
@@ -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