Skip to content

Commit ec36b2d

Browse files
committed
Add changelog, map matching reference, and embedding doc cookbook
1 parent 37c9d24 commit ec36b2d

File tree

6 files changed

+254
-0
lines changed

6 files changed

+254
-0
lines changed

CHANGELOG.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Changelog
2+
3+
All notable changes to FScript are documented in this file.
4+
5+
## [Unreleased]
6+
7+
### Documentation
8+
- Added dedicated map matching reference: `docs/map-matching-reference.md`.
9+
- Added include-resolution details (path normalization, root confinement, include deduplication, file-aware errors) in `docs/syntax-and-indentation.md`.
10+
- Added embedding cookbook section to `docs/embedding-fscript-language.md`.
11+
- Added and expanded onboarding tutorial and README navigation polish.
12+
13+
## [0.23.1]
14+
15+
### Documentation
16+
- Refined onboarding tutorial and prioritized tutorial-first navigation in `README.md`.
17+
18+
## [0.23.0]
19+
20+
### Documentation
21+
- Added progressive getting-started tutorial and linked it from docs/README.
22+
23+
## [0.22.0]
24+
25+
### Documentation
26+
- Updated docs and samples for `int` + `string` map keys.
27+
28+
## [0.21.0]
29+
30+
### Language
31+
- Added `int` and `string` map key support with inferred polymorphic empty maps.
32+
33+
## [0.20.0]
34+
35+
### Language
36+
- Improved map pattern matching semantics.
37+
38+
## [0.19.0]
39+
40+
### Language
41+
- Added `when` guards in match cases.
42+
43+
## [0.18.0]
44+
45+
### Language
46+
- Added map spread syntax (`{ [k] = v; ..tail }`).
47+
- Restricted append operator `@` to list-only usage.
48+
49+
## [0.17.0]
50+
51+
### Language and stdlib
52+
- Added map pattern matching.
53+
- Moved collection helpers to stdlib-first model.
54+
55+
## [0.16.0]
56+
57+
### Language
58+
- Added qualified discriminated union constructors/pattern support.
59+
60+
## [0.15.2]
61+
62+
### Packaging
63+
- Stopped packing `FScript.png` in NuGet packages.
64+
65+
## [0.15.1]
66+
67+
### Documentation
68+
- Updated README content.
69+
70+
## [0.15.0]
71+
72+
### Packaging
73+
- Added NuGet package icon and branding assets.
74+
75+
## [0.14.0]
76+
77+
### Language
78+
- Improved indentation diagnostics for misindented expressions.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ See [`docs/sandbox-and-security.md`](docs/sandbox-and-security.md) for the full
120120

121121
- [`docs/syntax-and-indentation.md`](docs/syntax-and-indentation.md)
122122
- [`docs/supported-types.md`](docs/supported-types.md)
123+
- [`docs/map-matching-reference.md`](docs/map-matching-reference.md)
123124
- [`docs/function-annotations.md`](docs/function-annotations.md)
124125
- [`docs/external-functions.md`](docs/external-functions.md)
125126
- [`docs/stdlib-functions.md`](docs/stdlib-functions.md)
@@ -128,6 +129,10 @@ See [`docs/sandbox-and-security.md`](docs/sandbox-and-security.md) for the full
128129
- [`docs/fsharp-ocaml-differences.md`](docs/fsharp-ocaml-differences.md)
129130
- [`docs/assemblies-and-roles.md`](docs/assemblies-and-roles.md)
130131

132+
## Changelog
133+
134+
- [`CHANGELOG.md`](CHANGELOG.md)
135+
131136
## License
132137

133138
This project is licensed under the MIT License.

docs/embedding-fscript-language.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,71 @@ Use `Pretty.valueToString` for a readable string form.
185185
Each error contains:
186186
- `Message`
187187
- `Span` (`Line`/`Column` information)
188+
189+
## Embedding cookbook
190+
191+
### 1. Parse/eval a file with `#include`
192+
Use include-aware parsing when executing scripts from disk.
193+
194+
```fsharp
195+
open FScript.Language
196+
197+
let root = "/path/to/workspace"
198+
let entry = "/path/to/workspace/main.fss"
199+
200+
let program = FScript.parseFileWithIncludes root entry
201+
let typed = FScript.infer program
202+
let value = FScript.eval typed
203+
```
204+
205+
### 2. Load once, invoke many times
206+
Use `ScriptHost` when you want to invoke exported functions repeatedly.
207+
208+
```fsharp
209+
open FScript.Language
210+
open FScript.Runtime
211+
212+
let hostContext = { RootDirectory = "." }
213+
let externs = Registry.all hostContext
214+
215+
let loaded =
216+
ScriptHost.loadFile externs "./script.fss" "."
217+
218+
let r1 = ScriptHost.invoke loaded "run" [ VString "build" ]
219+
let r2 = ScriptHost.invoke loaded "run" [ VString "test" ]
220+
```
221+
222+
### 3. Add one custom extern
223+
Define a typed external function and pass it to inference/evaluation.
224+
225+
```fsharp
226+
open FScript.Language
227+
228+
let envExtern =
229+
{ Name = "Env.get"
230+
Scheme = Forall([], TFun(TString, TOption TString))
231+
Arity = 1
232+
Impl =
233+
function
234+
| [ VString key ] ->
235+
System.Environment.GetEnvironmentVariable(key)
236+
|> Option.ofObj
237+
|> VOption
238+
| _ ->
239+
raise (EvalException { Message = "Env.get expects one string"; Span = Span.mk (Span.pos 0 0) (Span.pos 0 0) }) }
240+
241+
let src = "Env.get \"HOME\""
242+
let program = FScript.parse src
243+
let typed = FScript.inferWithExterns [ envExtern ] program
244+
let value = FScript.evalWithExterns [ envExtern ] typed
245+
```
246+
247+
### 4. Export descriptor discovery
248+
After inference, get function descriptors to expose callable surface in hosts.
249+
250+
```fsharp
251+
open FScript.Language
252+
253+
let typed = "[<export>] let run x = x" |> FScript.parse |> FScript.infer
254+
let descriptors = Descriptor.describeFunctions typed Map.empty
255+
```

docs/map-matching-reference.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# FScript Map Matching Reference
2+
3+
## Purpose
4+
This document is a focused reference for `match` patterns on maps.
5+
6+
## Map pattern basics
7+
Map patterns use brace + keyed clauses:
8+
9+
```fsharp
10+
match values with
11+
| { ["name"] = v } -> v
12+
| _ -> ""
13+
```
14+
15+
Keys can be `string` or `int`:
16+
17+
```fsharp
18+
match codes with
19+
| { [200] = label } -> label
20+
| _ -> "missing"
21+
```
22+
23+
## Supported forms
24+
25+
### Single key
26+
```fsharp
27+
| { ["a"] = x } -> ...
28+
```
29+
30+
### Multiple keys
31+
```fsharp
32+
| { ["a"] = x; ["b"] = y } -> ...
33+
```
34+
35+
### Tail capture
36+
```fsharp
37+
| { ["a"] = x; ..rest } -> ...
38+
```
39+
40+
### Dynamic key extraction
41+
```fsharp
42+
| { [k] = v; ..rest } -> ...
43+
```
44+
45+
### Guarded key checks
46+
Use `when` for key equality checks (instead of pinning syntax):
47+
48+
```fsharp
49+
| { [current] = v; ..rest } when current = key -> ...
50+
```
51+
52+
## Partial matching semantics
53+
Map matching is partial:
54+
- a pattern only requires the listed keys to exist,
55+
- additional keys in the matched value are allowed.
56+
57+
Example:
58+
59+
```fsharp
60+
match values with
61+
| { ["name"] = name } -> $"name={name}"
62+
| _ -> "no match"
63+
```
64+
65+
This still matches if `values` has extra keys.
66+
67+
## Practical examples
68+
69+
### Remove one key
70+
```fsharp
71+
let remove key values =
72+
match values with
73+
| { [current] = _; ..rest } when current = key -> rest
74+
| _ -> values
75+
```
76+
77+
### Match two required keys
78+
```fsharp
79+
let describe values =
80+
match values with
81+
| { ["name"] = name; ["owner"] = owner } -> $"{name} by {owner}"
82+
| _ -> "unknown"
83+
```
84+
85+
## Notes
86+
- Map literals:
87+
- `{}` empty map
88+
- `{ ["k"] = v }`
89+
- `{ [1] = v }`
90+
- `{ ["k"] = v; ..tail }`
91+
- For map construction/update rules, see `docs/supported-types.md`.
92+
- For full syntax/layout rules, see `docs/syntax-and-indentation.md`.

docs/supported-types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This document specifies the value and type system used by the interpreter.
3131
- record entries use `Field = value`
3232
- `{}` denotes an empty map.
3333
- Values are inferred and unified to a single value type.
34+
- See `./map-matching-reference.md` for focused map-pattern examples.
3435

3536
## Function types
3637
- Functions use curried arrow types:

docs/syntax-and-indentation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,13 @@ All of the following map literal layouts are valid:
214214
- Include loading is recursive.
215215
- Cycles are fatal and reported as parse errors.
216216
- File paths in includes must be `.fss`.
217+
- Include resolution is file-relative:
218+
- `#include "x.fss"` resolves from the directory of the file containing the directive.
219+
- Paths are normalized before loading:
220+
- relative segments like `.` and `..` are collapsed.
221+
- Resolved files must stay inside the configured sandbox root (`RootDirectory`).
222+
- escaping the root is a parse error.
223+
- A file already loaded once in the include graph is skipped on subsequent includes.
224+
- includes are effectively deduplicated.
225+
- `#include` must appear before module declarations and executable/type code in a file.
226+
- Parse/type/eval errors include file-aware spans (`file`, `line`, `column`) so failures in included files point to the offending source.

0 commit comments

Comments
 (0)