Skip to content

Commit

Permalink
feat: add try-with-finally expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Apr 5, 2024
1 parent cbb64ce commit 54c22a3
Show file tree
Hide file tree
Showing 7 changed files with 254,362 additions and 232,271 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build/release
on:
workflow_dispatch:
permissions:
contents: write

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
ref: "develop"
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm install
- run: npm test

release:
runs-on: ubuntu-latest
steps:
- name: Checkout develop branch
uses: actions/checkout@v3
with:
ref: "develop"
- name: Fetch main branch
run: |
git fetch origin main
git branch -t main origin/main
- name: "remove src/parser.c from .gitignore"
run: sed -i '/src\/parser.c/d' .gitignore
- uses: actions/setup-node@v2
with:
node-version: 16
- name: "compile main branch"
run: |
npm install
npm run build
- name: Merge into main branch and publish
run: |
git config user.name github-actions
git config user.email [email protected]
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
tree=$(git write-tree)
commit=$(git commit-tree -p main -p develop -m "release" $tree)
git update-ref refs/heads/main $commit
git push origin main
9 changes: 5 additions & 4 deletions examples/expressions.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
do
if b then
1
else
2
try
()
with
| _ -> ()
| _ -> ()
40 changes: 23 additions & 17 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,16 @@ module.exports = grammar({
$.record_pattern,
$.typed_pattern,
$.attribute_pattern,
// :? atomic-type
// :? atomic-type as ident
$.type_check_pattern,
),

type_check_pattern: $ =>
prec.right(
seq(
":?",
$.atomic_type,
optional(seq("as", $.identifier))
)
),

attribute_pattern: $ => prec.left(seq($.attributes, $._pattern)),
Expand Down Expand Up @@ -616,8 +624,9 @@ module.exports = grammar({
$._indent,
$._expression,
$._dedent,
optional($._newline),
choice(
seq('with', $._indent, $.rules, $._dedent),
seq('with', $.rules),
seq('finally', $._indent, $._expression, $._dedent),
),
)),
Expand All @@ -628,18 +637,14 @@ module.exports = grammar({
choice('match', 'match!'),
$._expression,
'with',
$._indent,
$.rules,
$._dedent,
)),

function_expression: $ =>
prec(PREC.MATCH_EXPR,
seq(
'function',
$._indent,
$.rules,
$._dedent,
)),

object_instantiation_expression: $ =>
Expand Down Expand Up @@ -772,6 +777,7 @@ module.exports = grammar({
prec.right(
seq(
$._pattern,
optional(seq("when", $._expression)),
'->',
$._indent,
$._expression,
Expand All @@ -781,9 +787,8 @@ module.exports = grammar({
rules: $ =>
prec.right(PREC.MATCH_EXPR,
seq(
optional('|'),
$.rule,
repeat(seq('|', $.rule)),
optional('|'), $.rule,
repeat(seq(optional($._newline), '|', $.rule)),
)),

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

atomic_type: $ =>
choice(
seq('#', $.type),
$.type_argument,
seq('(', $.type, ')'),
$.long_identifier,
seq($.long_identifier, '<', $.type_attributes, '>'),
),
prec.right(
choice(
seq('#', $.type),
$.type_argument,
seq('(', $.type, ')'),
$.long_identifier,
seq($.long_identifier, '<', $.type_attributes, '>'),
)),

constraint: $ =>
choice(
Expand Down
Loading

0 comments on commit 54c22a3

Please sign in to comment.