Skip to content

Commit

Permalink
Merge pull request #24 from fink-lang/remove-use-of-inspect
Browse files Browse the repository at this point in the history
feat(deps): remove dependency on node modules
  • Loading branch information
kollhof authored Oct 14, 2020
2 parents 190d043 + 879b0e7 commit 424970b
Show file tree
Hide file tree
Showing 9 changed files with 1,416 additions and 908 deletions.
2,198 changes: 1,329 additions & 869 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
"release": "semantic-release"
},
"dependencies": {
"@fink/snippet": "^2.0.0",
"@fink/snippet": "^2.0.1",
"@fink/std-lib": "^5.0.0"
},
"devDependencies": {
"@fink/cli": "^7.0.0",
"@fink/jest": "^6.0.0",
"@fink/larix": "^12.3.0",
"@fink/loxia": "^13.0.1",
"@fink/cli": "^8.0.0",
"@fink/jest": "^7.0.0",
"@fink/larix": "^13.1.0",
"@fink/loxia": "^14.0.2",
"commitizen": "^4.0.4",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^26.5.0",
"jest-cli": "^26.5.3",
"npx-run": "^2.1.2",
"semantic-release": "^17.1.2"
"semantic-release": "^17.2.1"
},
"config": {
"commitizen": {
Expand Down
2 changes: 2 additions & 0 deletions src/errors.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{stack_trace} = import '@fink/std-lib/stack-trace.fnk'



get_error = fn ctx, msg, token, stack_func:
{tokenizer: {code, filename}} = ctx
{start: {line, column}} = token.loc
Expand All @@ -19,6 +20,7 @@ get_error = fn ctx, msg, token, stack_func:
error



add_error = fn ctx, msg, token:
error = get_error ctx, msg, token, add_error
[error, {...ctx, errors: [...ctx.errors, error]}]
24 changes: 12 additions & 12 deletions src/parse.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ describe 'advance to next token', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:12
1| foobar = 123; shrub = ni
^

Expected one of [ '==' ] but found ';'.
"
Expected one of `==` but found `;`.
'


describe 'handles errors', fn:
Expand All @@ -243,41 +243,41 @@ describe 'handles errors', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:0
1| = 123
^

Unexpected token '=' at start of expression.
"
Unexpected token `=` at start of expression.
'


it 'using prefix operator as infix operator', fn:
[, {errors: [{error}]}] = parse 'foo ! ni'

expect
error
to_equal "
to_equal '
test.fnk:1:4
1| foo ! ni
^

Cannot use '!' as an infix operator.
"
Cannot use `!` as an infix operator.
'


it 'using other as infix operator', fn:
[, {errors: [{error}]}] = parse 'foo = spam ni'

expect
error
to_equal "
to_equal '
test.fnk:1:11
1| foo = spam ni
^

Cannot use 'ni' as an infix operator.
"
Cannot use `ni` as an infix operator.
'


it 'collecting text when not finding expected end', fn:
Expand Down
24 changes: 19 additions & 5 deletions src/parser.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{inspect} = import 'util'

{matches} = import '@fink/std-lib/regex.fnk'
{is_empty} = import '@fink/std-lib/iter.fnk'

Expand All @@ -8,50 +6,60 @@
{add_error} = import './errors.fnk'



# TODO: should it live here
ingnorable_token = {ignorable: true}



start_token = dict:
start_token: true
loc: dict:
start: {pos: 0, line: 1, column: 0}
end: {pos: 0, line: 1, column: 0}



has_errors = fn ctx:
match ctx:
{errors: not is_empty ?}: true
else: false



curr_value = fn {curr_token}:
curr_token.value



curr_loc = fn {curr_token}:
curr_token.loc



curr_is = fn ctx, expected:
expected == curr_value ctx



next_value = fn {next_token}:
next_token.value



next_loc = fn {next_token}:
next_token.loc



next_is = fn ctx, expected:
expected == next_value ctx



next_is_any = fn ctx, ...expected:
# TODO: use std-lib or in operator
expected.includes next_value ctx
(next_value ctx) in [...expected]



next_matches = fn ctx, regex:
Expand All @@ -71,6 +79,7 @@ next_is_end = fn ctx, expected_end:
else: false



advance = fn ctx:
curr_token = ctx.next_token

Expand All @@ -91,18 +100,20 @@ advance = fn ctx:
{...ctx, tokenizer, curr_token, next_token}



advance_expected = fn ctx, ...expected:
match ctx:
next_is_any ?, ...expected:
advance ctx
else:
{value} = ctx.next_token
[, next_ctx] = add_error ctx,
'Expected one of ${inspect expected} but found ${inspect value}.'
'Expected one of `${expected}` but found `${value}`.'
ctx.next_token
next_ctx



collect_text = fn ctx, stop_at:
{curr_token} = ctx

Expand All @@ -122,6 +133,7 @@ collect_text = fn ctx, stop_at:
[text, advance next_ctx]



expression = fn ctx, rbp:
match ctx:
next_is_end ?:
Expand Down Expand Up @@ -150,6 +162,7 @@ expression = fn ctx, rbp:
[left, next_ctx]



init_parser = fn {code, filename}:
tokenizer = init_tokenizer code, filename
symbols = init_symbols _
Expand All @@ -162,6 +175,7 @@ init_parser = fn {code, filename}:
symbols



start_parser = fn ctx:
advance ctx

29 changes: 19 additions & 10 deletions src/parser.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{symbol, other_symbol} = import './symbols.fnk'



other = fn:
dict:
...other_symbol
Expand All @@ -21,6 +22,7 @@ other = fn:
[{type: 'other', value}, ctx]



infix = fn op:
dict:
...symbol op
Expand All @@ -30,6 +32,7 @@ infix = fn op:
[{type: 'infx', op, left, right}, next_ctx]



prefix = fn op:
dict:
...symbol op
Expand All @@ -39,6 +42,7 @@ prefix = fn op:
[{type: 'prefix', op, right}, next_ctx]



string = fn op:
dict:
...symbol op
Expand Down Expand Up @@ -73,6 +77,7 @@ parse = fn code:
expression ctx, 0



describe 'parser', fn:
it 'parses simple expression', fn:
[ast, ctx] = parse 'foobar = !123'
Expand Down Expand Up @@ -119,6 +124,7 @@ describe 'parser', fn:
to_equal true



describe 'curr token tests, values, and assertions', fn:
it 'checks if current token value is same as expected', fn:
[, ctx] = parse 'foobar = 123'
Expand Down Expand Up @@ -148,6 +154,7 @@ describe 'curr token tests, values, and assertions', fn:
}



describe 'next token tests and assertions', fn:
it 'checks if next token value is same as expected', fn:
[, ctx] = parse 'foobar = 123;'
Expand Down Expand Up @@ -195,6 +202,7 @@ describe 'next token tests and assertions', fn:
}



describe 'advance to next token', fn:

it 'advances if next token value is as expected', fn:
Expand All @@ -214,13 +222,14 @@ describe 'advance to next token', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:12
1| foobar = 123; shrub = ni
^

Expected one of [ '==' ] but found ';'.
"
Expected one of `==` but found `;`.
'



describe 'handles errors', fn:
Expand All @@ -243,27 +252,27 @@ describe 'handles errors', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:0
1| = 123
^

Unexpected token '=' at start of expression.
"
Unexpected token `=` at start of expression.
'


it 'using prefix operator as infix operator', fn:
[, {errors: [{error}]}] = parse 'foo ! ni'

expect
error
to_equal "
to_equal '
test.fnk:1:4
1| foo ! ni
^

Cannot use '!' as an infix operator.
"
Cannot use `!` as an infix operator.
'


it 'using other as infix operator', fn:
Expand All @@ -276,7 +285,7 @@ describe 'handles errors', fn:
1| foo = spam ni
^

Cannot use 'ni' as an infix operator.
Cannot use `ni` as an infix operator.
"


Expand Down
Loading

0 comments on commit 424970b

Please sign in to comment.