Skip to content

Commit 54c22a3

Browse files
committed
feat: add try-with-finally expressions
1 parent cbb64ce commit 54c22a3

File tree

7 files changed

+254362
-232271
lines changed

7 files changed

+254362
-232271
lines changed

.github/workflows/main.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build/release
2+
on:
3+
workflow_dispatch:
4+
permissions:
5+
contents: write
6+
7+
jobs:
8+
test:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
os: [macos-latest, ubuntu-latest]
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
ref: "develop"
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: 16
21+
- run: npm install
22+
- run: npm test
23+
24+
release:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout develop branch
28+
uses: actions/checkout@v3
29+
with:
30+
ref: "develop"
31+
- name: Fetch main branch
32+
run: |
33+
git fetch origin main
34+
git branch -t main origin/main
35+
- name: "remove src/parser.c from .gitignore"
36+
run: sed -i '/src\/parser.c/d' .gitignore
37+
- uses: actions/setup-node@v2
38+
with:
39+
node-version: 16
40+
- name: "compile main branch"
41+
run: |
42+
npm install
43+
npm run build
44+
- name: Merge into main branch and publish
45+
run: |
46+
git config user.name github-actions
47+
git config user.email [email protected]
48+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
49+
git add .
50+
tree=$(git write-tree)
51+
commit=$(git commit-tree -p main -p develop -m "release" $tree)
52+
git update-ref refs/heads/main $commit
53+
git push origin main

examples/expressions.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
do
2-
if b then
3-
1
4-
else
5-
2
2+
try
3+
()
4+
with
5+
| _ -> ()
6+
| _ -> ()

grammar.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,16 @@ module.exports = grammar({
281281
$.record_pattern,
282282
$.typed_pattern,
283283
$.attribute_pattern,
284-
// :? atomic-type
285-
// :? atomic-type as ident
284+
$.type_check_pattern,
285+
),
286+
287+
type_check_pattern: $ =>
288+
prec.right(
289+
seq(
290+
":?",
291+
$.atomic_type,
292+
optional(seq("as", $.identifier))
293+
)
286294
),
287295

288296
attribute_pattern: $ => prec.left(seq($.attributes, $._pattern)),
@@ -616,8 +624,9 @@ module.exports = grammar({
616624
$._indent,
617625
$._expression,
618626
$._dedent,
627+
optional($._newline),
619628
choice(
620-
seq('with', $._indent, $.rules, $._dedent),
629+
seq('with', $.rules),
621630
seq('finally', $._indent, $._expression, $._dedent),
622631
),
623632
)),
@@ -628,18 +637,14 @@ module.exports = grammar({
628637
choice('match', 'match!'),
629638
$._expression,
630639
'with',
631-
$._indent,
632640
$.rules,
633-
$._dedent,
634641
)),
635642

636643
function_expression: $ =>
637644
prec(PREC.MATCH_EXPR,
638645
seq(
639646
'function',
640-
$._indent,
641647
$.rules,
642-
$._dedent,
643648
)),
644649

645650
object_instantiation_expression: $ =>
@@ -772,6 +777,7 @@ module.exports = grammar({
772777
prec.right(
773778
seq(
774779
$._pattern,
780+
optional(seq("when", $._expression)),
775781
'->',
776782
$._indent,
777783
$._expression,
@@ -781,9 +787,8 @@ module.exports = grammar({
781787
rules: $ =>
782788
prec.right(PREC.MATCH_EXPR,
783789
seq(
784-
optional('|'),
785-
$.rule,
786-
repeat(seq('|', $.rule)),
790+
optional('|'), $.rule,
791+
repeat(seq(optional($._newline), '|', $.rule)),
787792
)),
788793

789794
application_expression: $ =>
@@ -1044,13 +1049,14 @@ module.exports = grammar({
10441049
type_attributes: $ => seq($.type_attribute, repeat(prec.left(PREC.COMMA, seq(',', $.type_attribute)))),
10451050

10461051
atomic_type: $ =>
1047-
choice(
1048-
seq('#', $.type),
1049-
$.type_argument,
1050-
seq('(', $.type, ')'),
1051-
$.long_identifier,
1052-
seq($.long_identifier, '<', $.type_attributes, '>'),
1053-
),
1052+
prec.right(
1053+
choice(
1054+
seq('#', $.type),
1055+
$.type_argument,
1056+
seq('(', $.type, ')'),
1057+
$.long_identifier,
1058+
seq($.long_identifier, '<', $.type_attributes, '>'),
1059+
)),
10541060

10551061
constraint: $ =>
10561062
choice(

0 commit comments

Comments
 (0)