Skip to content

Commit

Permalink
Merge pull request #17 from Anton-4/nat_to_u64
Browse files Browse the repository at this point in the history
replace Nat with U64
  • Loading branch information
lukewilliamboswell authored Feb 21, 2024
2 parents 2410aaa + 1f3a0d7 commit 9dfc3ef
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 56 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

# Json Package for Roc 🤘

## Example

Try running some of the examples using Roc cli.

:warning: `--linker=legacy` is necessary for this package because of [this roc issue](https://github.com/roc-lang/roc/issues/3609)

## Example

```sh
$ roc run examples/simple1.roc --linker=legacy
Successfully decoded image, title:"View from 15th Floor"
Expand All @@ -16,7 +14,7 @@ Successfully decoded image, title:"View from 15th Floor"

See [https://lukewilliamboswell.github.io/roc-json/](https://lukewilliamboswell.github.io/roc-json/)

Alternatively, you can also generate docs locally using `roc docs package/main.roc` and then serve the html files.
Alternatively, generate docs locally using `roc docs package/main.roc` and then serve the html files.

## Package URL Release

Expand Down
2 changes: 1 addition & 1 deletion examples/simple1.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app "simple1"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br",
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
json: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/lukewilliamboswell/roc-json/releases
}
imports [
Expand Down
2 changes: 1 addition & 1 deletion examples/simple2.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app "simple2"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br",
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
json: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/lukewilliamboswell/roc-json/releases
}
imports [
Expand Down
2 changes: 1 addition & 1 deletion examples/tuple.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app "simple1"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br",
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
json: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/lukewilliamboswell/roc-json/releases
}
imports [
Expand Down
135 changes: 130 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
description = "json package devShell flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
roc.url = "github:roc-lang/roc";
nixpkgs.follows = "roc/nixpkgs";

# to easily make configs for multiple architectures
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
outputs = { self, nixpkgs, flake-utils, roc }:
let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
in flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import nixpkgs { inherit system; };
rocPkgs = roc.packages.${system};

linuxInputs = with pkgs;
lib.optionals stdenv.isLinux [
Expand All @@ -25,6 +27,7 @@

sharedInputs = (with pkgs; [
expect
rocPkgs.cli
]);
in {

Expand Down
80 changes: 40 additions & 40 deletions package/Core.roc
Original file line number Diff line number Diff line change
Expand Up @@ -798,21 +798,21 @@ numberHelp = \state, byte ->

NumberState : [
Start,
Minus Nat,
Zero Nat,
Integer Nat,
FractionA Nat,
FractionB Nat,
ExponentA Nat,
ExponentB Nat,
ExponentC Nat,
Minus U64,
Zero U64,
Integer U64,
FractionA U64,
FractionB U64,
ExponentA U64,
ExponentB U64,
ExponentC U64,
Invalid,
Finish Nat,
Finish U64,
]

# TODO confirm if we would like to be able to decode
# "340282366920938463463374607431768211455" which is MAX U128 and 39 bytes
maxBytes : Nat
maxBytes : U64
maxBytes = 21 # Max bytes in a double precision float

isDigit0to9 : U8 -> Bool
Expand Down Expand Up @@ -1010,13 +1010,13 @@ stringHelp = \state, byte ->

StringState : [
Start,
Chars Nat,
Escaped Nat,
UnicodeA Nat,
UnicodeB Nat,
UnicodeC Nat,
UnicodeD Nat,
Finish Nat,
Chars U64,
Escaped U64,
UnicodeA U64,
UnicodeB U64,
UnicodeC U64,
UnicodeD U64,
Finish U64,
InvalidNumber,
]

Expand Down Expand Up @@ -1292,14 +1292,14 @@ expect
actual == expected

ArrayOpeningState : [
BeforeOpeningBracket Nat,
AfterOpeningBracket Nat,
BeforeOpeningBracket U64,
AfterOpeningBracket U64,
]

ArrayClosingState : [
BeforeNextElemOrClosingBracket Nat,
BeforeNextElement Nat,
AfterClosingBracket Nat,
BeforeNextElemOrClosingBracket U64,
BeforeNextElement U64,
AfterClosingBracket U64,
]

# Test decoding an empty array
Expand Down Expand Up @@ -1486,16 +1486,16 @@ skipFieldHelp = \state, byte ->
_ -> Break InvalidObject

SkipValueState : [
FieldValue Nat,
FieldValueEnd Nat,
InsideAString Nat,
InsideAnObject { index : Nat, nesting : Nat },
StringInObject { index : Nat, nesting : Nat },
EncodedStringInObject { index : Nat, nesting : Nat },
InsideAnArray { index : Nat, nesting : Nat },
StringInArray { index : Nat, nesting : Nat },
EcapdedStringInArray { index : Nat, nesting : Nat },
Escaped Nat,
FieldValue U64,
FieldValueEnd U64,
InsideAString U64,
InsideAnObject { index : U64, nesting : U64 },
StringInObject { index : U64, nesting : U64 },
EncodedStringInObject { index : U64, nesting : U64 },
InsideAnArray { index : U64, nesting : U64 },
StringInArray { index : U64, nesting : U64 },
EcapdedStringInArray { index : U64, nesting : U64 },
Escaped U64,
InvalidObject,
]

Expand Down Expand Up @@ -1696,14 +1696,14 @@ objectHelp = \state, byte ->
_ -> Break InvalidObject

ObjectState : [
BeforeOpeningBrace Nat,
AfterOpeningBrace Nat,
ObjectFieldNameStart Nat,
BeforeColon Nat,
AfterColon Nat,
AfterObjectValue Nat,
AfterComma Nat,
AfterClosingBrace Nat,
BeforeOpeningBrace U64,
AfterOpeningBrace U64,
ObjectFieldNameStart U64,
BeforeColon U64,
AfterColon U64,
AfterObjectValue U64,
AfterComma U64,
AfterClosingBrace U64,
InvalidObject,
]

Expand Down

0 comments on commit 9dfc3ef

Please sign in to comment.