Skip to content

Commit a379989

Browse files
committed
crystal: Generate crystal/ReadMe.md
1 parent a9d4343 commit a379989

File tree

4 files changed

+211
-35
lines changed

4 files changed

+211
-35
lines changed

crystal/Makefile

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,40 @@ include ../common/base.mk
22
include $(COMMON)/binding.mk
33

44
# Define crystal command
5+
ifneq (,$(shell command -v crystal))
56
CRYSTAL ?= crystal
6-
7-
ifdef DOCKERENV
8-
CRYSTAL_BIN := $(YS_TMP)/crystal/bin
9-
else
10-
CRYSTAL_BIN := $(ROOT)/crystal/bin
117
endif
128

9+
BASE := $(ROOT)/crystal
10+
1311
VERSION := $(shell grep 'VERSION =' src/yamlscript/version.cr | cut -d'"' -f2)
1412
YAMLSCRIPT_VERSION ?= 0.1.95
15-
YAMLSCRIPT_FNP ?= $(HOME)/.local/lib/libyamlscript.so.$(YAMLSCRIPT_VERSION)
16-
LIBYAMLSCRIPT_SO_FQNP ?= $(YAMLSCRIPT_FNP)
13+
LIBYS_SO_PATH := $(ROOT)/libyamlscript/lib/$(LIBYS_SO_FQNP)
14+
BUILD_DEPS := $(LIBYS_SO_PATH)
1715

1816
#------------------------------------------------------------------------------
1917

20-
version:
21-
@echo $(VERSION)
22-
23-
# Build the library and documentation
24-
build:: build-doc build-lib
25-
@echo "Crystal binding built successfully"
18+
build:: build-doc
2619

27-
# Copy the library file to the local lib directory
28-
build-lib: $(LIBYAMLSCRIPT_SO_FQNP)
29-
@mkdir -p lib
30-
@echo "Copying $(LIBYAMLSCRIPT_SO_FQNP) to lib/"
31-
@cp -fL $(LIBYAMLSCRIPT_SO_FQNP) lib/
32-
@ln -sf libyamlscript.so.$(YAMLSCRIPT_VERSION) lib/libyamlscript.so
20+
build-doc:: ReadMe.md
3321

34-
.PHONY: test run-example
3522
ifdef CRYSTAL
36-
test:: test-wrapper
23+
test:: run-example test-crystal test-ffi
3724
endif
3825

39-
run-example: build-lib
40-
@CRYSTAL_LIBRARY_PATH="$(PWD)/lib" LD_LIBRARY_PATH="$(PWD)/lib:$(LD_LIBRARY_PATH)" $(CRYSTAL) run examples/simple.cr
26+
run-example: $(BUILD_DEPS)
27+
$(CRYSTAL) run examples/simple.cr
4128

42-
# Use wrapper script for tests
43-
test-wrapper:
44-
@./test_wrapper.sh
29+
test-crystal: $(BUILD_DEPS)
30+
$(CRYSTAL) spec
4531

46-
test-crystal: build-lib
47-
@CRYSTAL_LIBRARY_PATH="$(PWD)/lib" LD_LIBRARY_PATH="$(PWD)/lib:$(LD_LIBRARY_PATH)" $(CRYSTAL) spec
48-
49-
test-ffi: build-lib
50-
@echo "Running Crystal binding FFI test..."
51-
@CRYSTAL_LIBRARY_PATH="$(PWD)/lib" LD_LIBRARY_PATH="$(PWD)/lib:$(LD_LIBRARY_PATH)" $(CRYSTAL) run test/ffi.cr
32+
test-ffi: $(BUILD_DEPS)
33+
$(CRYSTAL) run test/ffi.cr
5234

5335
clean::
5436
$(RM) -r lib bin .crystal .shards shard.lock libyamlscript.so
55-
@echo
5637

57-
realclean::
58-
@echo
38+
$(LIBYS_SO_PATH):
39+
$(MAKE) -C $(ROOT)/libyamlscript $(LIBYS_SO_FQNP)
40+
41+
.PHONY: test

crystal/ReadMe.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<!-- DO NOT EDIT — THIS FILE WAS GENERATED -->
2+
3+
YS / YAMLScript
4+
===============
5+
6+
Add Logic to Your YAML Files
7+
8+
9+
## Synopsis
10+
11+
Load `file.yaml` with YS:
12+
```yaml
13+
!YS-v0:
14+
15+
# Get data from external sources:
16+
names-url =:
17+
"https://raw.githubusercontent.com/dominictarr/\
18+
random-name/master/first-names.json"
19+
20+
name-list =: &first-names json/load(curl(names-url))
21+
22+
# Data object with literal keys and generated values:
23+
name:: rand-nth(*first-names)
24+
aka:: name-list.rand-nth()
25+
age:: &num 2 * 3 * 7
26+
color:: &hue qw(red green blue yellow)
27+
.shuffle()
28+
.first()
29+
title:: "$(*num) shades of $(*hue)."
30+
```
31+
32+
and get:
33+
```json
34+
{
35+
"name": "Dolores",
36+
"aka": "Anita",
37+
"age": 42,
38+
"color": "green",
39+
"title": "42 shades of green."
40+
}
41+
```
42+
43+
44+
## Description
45+
46+
[YS](https://yamlscript.org) is a functional programming language with a clean
47+
YAML syntax.
48+
49+
YS can be used for enhancing ordinary [YAML](https://yaml.org) files with
50+
functional operations, such as:
51+
52+
* Import (parts of) other YAML files to any node
53+
* String interpolation including function calls
54+
* Data transforms including ones defined by you
55+
56+
This YS library should be a drop-in replacement for your current YAML loader!
57+
58+
Most existing YAML files are already valid YS files.
59+
This means that YS works as a normal YAML loader, but can also evaluate
60+
functional expressions if asked to.
61+
62+
Under the hood, YS code compiles to the Clojure programming language.
63+
This makes YS a complete functional programming language right out of the box.
64+
65+
Even though YS compiles to Clojure, and Clojure compiles to Java, there is no
66+
dependency on Java or the JVM.
67+
YS is compiled to a native shared library (`libyamlscript.so`) that can be used
68+
by any programming language that can load shared libraries.
69+
70+
To see the Clojure code that YS compiles to, you can use the YS
71+
CLI binary `ys` to run:
72+
73+
```text
74+
$ ys --compile file.ys
75+
(let
76+
[names-url "https://raw.githubusercontent.com/dominictarr/random-name/master/first-names.json"
77+
name-list (_& 'first-names (json/load (curl names-url)))]
78+
(%
79+
"name" (rand-nth (_** 'first-names))
80+
"aka" (rand-nth name-list)
81+
"age" (_& 'num (mul+ 2 3 7))
82+
"color" (_& 'hue (first (shuffle (qw red green blue yellow))))
83+
"title" (str (_** 'num) " shades of " (_** 'hue) ".")))
84+
```
85+
86+
## Crystal Usage
87+
88+
Here's a simple example of using the YAMLScript Crystal binding:
89+
90+
```crystal
91+
require "yamlscript"
92+
93+
# YAMLScript code
94+
ys_code = <<-YS
95+
!YS-v0
96+
inc: 41
97+
YS
98+
99+
# Load and evaluate the YAMLScript
100+
result = YAMLScript.load(ys_code)
101+
puts "Result: #{result}" # Output: Result: 42
102+
103+
# Regular YAML also works
104+
yaml_code = "foo: bar"
105+
result = YAMLScript.load(yaml_code)
106+
puts "YAML result: #{result["foo"]}" # Output: YAML result: bar
107+
```
108+
109+
## Development
110+
111+
To build and run tests:
112+
113+
```bash
114+
# Clone the repository
115+
git clone https://github.com/yaml/yamlscript.git
116+
cd yamlscript/crystal
117+
118+
# Build the binding and copy required libraries
119+
make build
120+
121+
# Run the tests
122+
make test
123+
124+
# Run the example
125+
make run-example
126+
```
127+
128+
## See Also
129+
130+
* [YS Web Site](https://yamlscript.org)
131+
* [YS Blog](https://yamlscript.org/blog)
132+
* [YS Source Code](https://github.com/yaml/yamlscript)
133+
* [YS Samples](https://github.com/yaml/yamlscript/tree/main/sample)
134+
* [YS Programs](https://rosettacode.org/wiki/Category:YAMLScript)
135+
* [YAML](https://yaml.org)
136+
* [Clojure](https://clojure.org)
137+
138+
139+
## Authors
140+
141+
* [Josephine Pfeiffer](https://github.com/pfeifferj)
142+
* [Ingy döt Net](https://github.com/ingydotnet)
143+
144+
## License & Copyright
145+
146+
Copyright 2022-2025 Ingy döt Net <[email protected]>
147+
148+
This project is licensed under the terms of the `MIT` license.
149+
See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for
150+
more details.

crystal/doc/authors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* [Josephine Pfeiffer](https://github.com/pfeifferj)
2+
* [Ingy döt Net](https://github.com/ingydotnet)

crystal/doc/readme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Crystal Usage
2+
3+
Here's a simple example of using the YAMLScript Crystal binding:
4+
5+
```crystal
6+
require "yamlscript"
7+
8+
# YAMLScript code
9+
ys_code = <<-YS
10+
!YS-v0
11+
inc: 41
12+
YS
13+
14+
# Load and evaluate the YAMLScript
15+
result = YAMLScript.load(ys_code)
16+
puts "Result: #{result}" # Output: Result: 42
17+
18+
# Regular YAML also works
19+
yaml_code = "foo: bar"
20+
result = YAMLScript.load(yaml_code)
21+
puts "YAML result: #{result["foo"]}" # Output: YAML result: bar
22+
```
23+
24+
## Development
25+
26+
To build and run tests:
27+
28+
```bash
29+
# Clone the repository
30+
git clone https://github.com/yaml/yamlscript.git
31+
cd yamlscript/crystal
32+
33+
# Build the binding and copy required libraries
34+
make build
35+
36+
# Run the tests
37+
make test
38+
39+
# Run the example
40+
make run-example
41+
```

0 commit comments

Comments
 (0)