From d6ff26af58885ca9a1912c6f5a3f214dfcef0e1e Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Sun, 31 Mar 2024 21:46:52 +0200 Subject: [PATCH] Purescript Lua: initial sources --- dist/.gitignore | 1 + flake.lock | 833 ++++++++++++++++++++++++++++++ flake.nix | 37 ++ packages.dhall | 9 + scripts/build | 21 + scripts/test | 11 + spago.dhall | 20 + src/Data/String/CodePoints.lua | 8 + src/Data/String/CodeUnits.lua | 105 ++++ src/Data/String/Common.lua | 26 + src/Data/String/Regex.js | 103 ---- src/Data/String/Regex.purs | 131 ----- src/Data/String/Regex/Flags.purs | 129 ----- src/Data/String/Regex/Unsafe.purs | 14 - src/Data/String/Unsafe.lua | 12 + treefmt.toml | 4 + 16 files changed, 1087 insertions(+), 377 deletions(-) create mode 100644 dist/.gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 packages.dhall create mode 100755 scripts/build create mode 100755 scripts/test create mode 100644 spago.dhall create mode 100644 src/Data/String/CodePoints.lua create mode 100644 src/Data/String/CodeUnits.lua create mode 100644 src/Data/String/Common.lua delete mode 100644 src/Data/String/Regex.js delete mode 100644 src/Data/String/Regex.purs delete mode 100644 src/Data/String/Regex/Flags.purs delete mode 100644 src/Data/String/Regex/Unsafe.purs create mode 100644 src/Data/String/Unsafe.lua create mode 100644 treefmt.toml diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 0000000..d907c43 --- /dev/null +++ b/dist/.gitignore @@ -0,0 +1 @@ +*.lua diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..780c119 --- /dev/null +++ b/flake.lock @@ -0,0 +1,833 @@ +{ + "nodes": { + "HTTP": { + "flake": false, + "locked": { + "lastModified": 1451647621, + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + }, + "original": { + "owner": "phadej", + "repo": "HTTP", + "type": "github" + } + }, + "cabal-32": { + "flake": false, + "locked": { + "lastModified": 1603716527, + "narHash": "sha256-X0TFfdD4KZpwl0Zr6x+PLxUt/VyKQfX7ylXHdmZIL+w=", + "owner": "haskell", + "repo": "cabal", + "rev": "48bf10787e27364730dd37a42b603cee8d6af7ee", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.2", + "repo": "cabal", + "type": "github" + } + }, + "cabal-34": { + "flake": false, + "locked": { + "lastModified": 1645834128, + "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", + "owner": "haskell", + "repo": "cabal", + "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.4", + "repo": "cabal", + "type": "github" + } + }, + "cabal-36": { + "flake": false, + "locked": { + "lastModified": 1669081697, + "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", + "owner": "haskell", + "repo": "cabal", + "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.6", + "repo": "cabal", + "type": "github" + } + }, + "cardano-shell": { + "flake": false, + "locked": { + "lastModified": 1608537748, + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "cardano-shell", + "type": "github" + } + }, + "easy-purescript-nix": { + "inputs": { + "flake-utils": "flake-utils_2" + }, + "locked": { + "lastModified": 1710161569, + "narHash": "sha256-lcIRIOFCdIWEGyKyG/tB4KvxM9zoWuBRDxW+T+mvIb0=", + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "rev": "117fd96acb69d7d1727df95b6fde9d8715e031fc", + "type": "github" + }, + "original": { + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "type": "github" + } + }, + "easyps": { + "flake": false, + "locked": { + "lastModified": 1710161569, + "narHash": "sha256-lcIRIOFCdIWEGyKyG/tB4KvxM9zoWuBRDxW+T+mvIb0=", + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "rev": "117fd96acb69d7d1727df95b6fde9d8715e031fc", + "type": "github" + }, + "original": { + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1672831974, + "narHash": "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0=", + "owner": "input-output-hk", + "repo": "flake-compat", + "rev": "45f2638735f8cdc40fe302742b79f248d23eb368", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "ref": "hkm/gitlab-fix", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "ghc-8.6.5-iohk": { + "flake": false, + "locked": { + "lastModified": 1600920045, + "narHash": "sha256-DO6kxJz248djebZLpSzTGD6s8WRpNI9BTwUeOf5RwY8=", + "owner": "input-output-hk", + "repo": "ghc", + "rev": "95713a6ecce4551240da7c96b6176f980af75cae", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "ref": "release/8.6.5-iohk", + "repo": "ghc", + "type": "github" + } + }, + "ghc910X": { + "flake": false, + "locked": { + "lastModified": 1709693152, + "narHash": "sha256-j7K/oZLy1ZZIpOsjq101IF7cz/i/UxY1ofIeNUfuuXc=", + "ref": "ghc-9.10", + "rev": "21e3f3250e88640087a1a60bee2cc113bf04509f", + "revCount": 62524, + "submodules": true, + "type": "git", + "url": "https://gitlab.haskell.org/ghc/ghc" + }, + "original": { + "ref": "ghc-9.10", + "submodules": true, + "type": "git", + "url": "https://gitlab.haskell.org/ghc/ghc" + } + }, + "ghc911": { + "flake": false, + "locked": { + "lastModified": 1710286031, + "narHash": "sha256-fz71zsU/ZukFMUsRNk2Ro3xTNMKsNrpvQtRtPqRI60c=", + "ref": "refs/heads/master", + "rev": "e6bfb85c842edca36754bb8914e725fbaa1a83a6", + "revCount": 62586, + "submodules": true, + "type": "git", + "url": "https://gitlab.haskell.org/ghc/ghc" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://gitlab.haskell.org/ghc/ghc" + } + }, + "hackage": { + "flake": false, + "locked": { + "lastModified": 1710807758, + "narHash": "sha256-lQY4KSZQlMyKizC+Xbsl29hxNPHV52pRTDZac+vPaeU=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "dc3cafd9dbaeebe37c96613a9d145e162cadcf79", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "hackage.nix", + "type": "github" + } + }, + "haskellNix": { + "inputs": { + "HTTP": "HTTP", + "cabal-32": "cabal-32", + "cabal-34": "cabal-34", + "cabal-36": "cabal-36", + "cardano-shell": "cardano-shell", + "flake-compat": "flake-compat", + "ghc-8.6.5-iohk": "ghc-8.6.5-iohk", + "ghc910X": "ghc910X", + "ghc911": "ghc911", + "hackage": "hackage", + "hls-1.10": "hls-1.10", + "hls-2.0": "hls-2.0", + "hls-2.2": "hls-2.2", + "hls-2.3": "hls-2.3", + "hls-2.4": "hls-2.4", + "hls-2.5": "hls-2.5", + "hls-2.6": "hls-2.6", + "hpc-coveralls": "hpc-coveralls", + "hydra": "hydra", + "iserv-proxy": "iserv-proxy", + "nix-tools-static": "nix-tools-static", + "nixpkgs": [ + "pslua", + "haskellNix", + "nixpkgs-unstable" + ], + "nixpkgs-2003": "nixpkgs-2003", + "nixpkgs-2105": "nixpkgs-2105", + "nixpkgs-2111": "nixpkgs-2111", + "nixpkgs-2205": "nixpkgs-2205", + "nixpkgs-2211": "nixpkgs-2211", + "nixpkgs-2305": "nixpkgs-2305", + "nixpkgs-2311": "nixpkgs-2311", + "nixpkgs-unstable": "nixpkgs-unstable", + "old-ghc-nix": "old-ghc-nix", + "stackage": "stackage" + }, + "locked": { + "lastModified": 1710809412, + "narHash": "sha256-uLn/+4rBqk/+y5OPqe0LqUZHW7uEnWiljO/oGEx3L7c=", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "bc43eea89699683d1659eed3c3cc787e432ebfe7", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "haskell.nix", + "type": "github" + } + }, + "hls-1.10": { + "flake": false, + "locked": { + "lastModified": 1680000865, + "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "1.10.0.0", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.0": { + "flake": false, + "locked": { + "lastModified": 1687698105, + "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "783905f211ac63edf982dd1889c671653327e441", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.0.0.1", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.2": { + "flake": false, + "locked": { + "lastModified": 1693064058, + "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.2.0.0", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.3": { + "flake": false, + "locked": { + "lastModified": 1695910642, + "narHash": "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "458ccdb55c9ea22cd5d13ec3051aaefb295321be", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.3.0.0", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.4": { + "flake": false, + "locked": { + "lastModified": 1699862708, + "narHash": "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "54507ef7e85fa8e9d0eb9a669832a3287ffccd57", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.4.0.1", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.5": { + "flake": false, + "locked": { + "lastModified": 1701080174, + "narHash": "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "27f8c3d3892e38edaef5bea3870161815c4d014c", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.5.0.0", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hls-2.6": { + "flake": false, + "locked": { + "lastModified": 1705325287, + "narHash": "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "2.6.0.0", + "repo": "haskell-language-server", + "type": "github" + } + }, + "hpc-coveralls": { + "flake": false, + "locked": { + "lastModified": 1607498076, + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + }, + "original": { + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "type": "github" + } + }, + "hydra": { + "inputs": { + "nix": "nix", + "nixpkgs": [ + "pslua", + "haskellNix", + "hydra", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1671755331, + "narHash": "sha256-hXsgJj0Cy0ZiCiYdW2OdBz5WmFyOMKuw4zyxKpgUKm4=", + "owner": "NixOS", + "repo": "hydra", + "rev": "f48f00ee6d5727ae3e488cbf9ce157460853fea8", + "type": "github" + }, + "original": { + "id": "hydra", + "type": "indirect" + } + }, + "iserv-proxy": { + "flake": false, + "locked": { + "lastModified": 1708894040, + "narHash": "sha256-Rv+PajrnuJ6AeyhtqzMN+bcR8z9+aEnrUass+N951CQ=", + "owner": "stable-haskell", + "repo": "iserv-proxy", + "rev": "2f2a318fd8837f8063a0d91f329aeae29055fba9", + "type": "github" + }, + "original": { + "owner": "stable-haskell", + "ref": "iserv-syms", + "repo": "iserv-proxy", + "type": "github" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": "nixpkgs_2", + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1661606874, + "narHash": "sha256-9+rpYzI+SmxJn+EbYxjGv68Ucp22bdFUSy/4LkHkkDQ=", + "owner": "NixOS", + "repo": "nix", + "rev": "11e45768b34fdafdcf019ddbd337afa16127ff0f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "2.11.0", + "repo": "nix", + "type": "github" + } + }, + "nix-tools-static": { + "flake": false, + "locked": { + "lastModified": 1706266250, + "narHash": "sha256-9t+GRk3eO9muCtKdNAwBtNBZ5dH1xHcnS17WaQyftwA=", + "owner": "input-output-hk", + "repo": "haskell-nix-example", + "rev": "580cb6db546a7777dad3b9c0fa487a366c045c4e", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "ref": "nix", + "repo": "haskell-nix-example", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs-2003": { + "locked": { + "lastModified": 1620055814, + "narHash": "sha256-8LEHoYSJiL901bTMVatq+rf8y7QtWuZhwwpKE2fyaRY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-20.03-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2105": { + "locked": { + "lastModified": 1659914493, + "narHash": "sha256-lkA5X3VNMKirvA+SUzvEhfA7XquWLci+CGi505YFAIs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-21.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2111": { + "locked": { + "lastModified": 1659446231, + "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eabc38219184cc3e04a974fe31857d8e0eac098d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-21.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2205": { + "locked": { + "lastModified": 1685573264, + "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "380be19fbd2d9079f677978361792cb25e8a3635", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-22.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2211": { + "locked": { + "lastModified": 1688392541, + "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-22.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2305": { + "locked": { + "lastModified": 1701362232, + "narHash": "sha256-GVdzxL0lhEadqs3hfRLuj+L1OJFGiL/L7gCcelgBlsw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d2332963662edffacfddfad59ff4f709dde80ffe", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-23.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2311": { + "locked": { + "lastModified": 1701386440, + "narHash": "sha256-xI0uQ9E7JbmEy/v8kR9ZQan6389rHug+zOtZeZFiDJk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "293822e55ec1872f715a66d0eda9e592dc14419f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-23.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1694822471, + "narHash": "sha256-6fSDCj++lZVMZlyqOe9SIOL8tYSBz1bI8acwovRwoX8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47585496bcb13fb72e4a90daeea2f434e2501998", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47585496bcb13fb72e4a90daeea2f434e2501998", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1657693803, + "narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "365e1b3a859281cf11b94f87231adeabbdd878a2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.05-small", + "repo": "nixpkgs", + "type": "github" + } + }, + "old-ghc-nix": { + "flake": false, + "locked": { + "lastModified": 1631092763, + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + }, + "original": { + "owner": "angerman", + "ref": "master", + "repo": "old-ghc-nix", + "type": "github" + } + }, + "pslua": { + "inputs": { + "easy-purescript-nix": "easy-purescript-nix", + "flake-utils": "flake-utils_3", + "haskellNix": "haskellNix", + "nixpkgs": [ + "pslua", + "haskellNix", + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1711822377, + "narHash": "sha256-3cqI8lL04RZA7RrLImYzGsOOrE2Z5UpXzEvnvT9HqmA=", + "owner": "Unisay", + "repo": "purescript-lua", + "rev": "ccc2df825af5a6abe33d663ecdd8eb3ab9feb63a", + "type": "github" + }, + "original": { + "owner": "Unisay", + "repo": "purescript-lua", + "type": "github" + } + }, + "root": { + "inputs": { + "easyps": "easyps", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pslua": "pslua" + } + }, + "stackage": { + "flake": false, + "locked": { + "lastModified": 1710461339, + "narHash": "sha256-l2/ekwA4Z4NjiaCZytZrBTag2VaAOBUvsNttsH6kH4E=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "724970b7dc837bf0d813b91f821948c3c5cc719f", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "stackage.nix", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fbde00f --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Purescript-Lua Flake"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "nixpkgs/nixos-unstable"; + easyps = { + url = "github:justinwoo/easy-purescript-nix"; + flake = false; + }; + pslua.url = "github:Unisay/purescript-lua"; + }; + + outputs = { self, nixpkgs, flake-utils, easyps, pslua }: + flake-utils.lib.eachDefaultSystem (system: + let + p = nixpkgs.legacyPackages.${system}; + e = import easyps { pkgs = p; }; + l = p.lua51Packages; + in { + devShell = p.mkShell { + buildInputs = [ + p.dhall + l.lua + l.luacheck + p.luaformatter + p.nixfmt + pslua.packages.${system}.default + e.purs-0_15_15 + e.purs-tidy + e.spago + p.treefmt + ]; + }; + }); +} + diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..0319420 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,9 @@ +let upstream-ps = + https://github.com/purescript/package-sets/releases/download/psc-0.15.15-20240320/packages.dhall + sha256:ae8a25645e81ff979beb397a21e5d272fae7c9ebdb021a96b1b431388c8f3c34 + +let upstream-lua = + https://github.com/Unisay/purescript-lua-package-sets/releases/download/psc-0.15.15-20240342/packages.dhall + sha256:c7b900b5f26717504a50b14fdcc24796ce505801ad068c9e2496519e6042e139 + +in upstream-ps // upstream-lua diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..2520d0d --- /dev/null +++ b/scripts/build @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +echo "Building..." + +spago build -u '-g corefn' + +pslua --foreign-path . --ps-output output --entry Data.Char --lua-output-file dist/Data.Char.lua +pslua --foreign-path . --ps-output output --entry Data.Char.Gen --lua-output-file dist/Data.Char.Gen.lua +pslua --foreign-path . --ps-output output --entry Data.String --lua-output-file dist/Data.String.lua +pslua --foreign-path . --ps-output output --entry Data.String.CaseInsensitive --lua-output-file dist/Data.String.CaseInsensitive.lua +pslua --foreign-path . --ps-output output --entry Data.String.CodePoints --lua-output-file dist/Data.String.CodePoints.lua +pslua --foreign-path . --ps-output output --entry Data.String.CodeUnits --lua-output-file dist/Data.String.CodeUnits.lua +pslua --foreign-path . --ps-output output --entry Data.String.Common --lua-output-file dist/Data.String.Common.lua +pslua --foreign-path . --ps-output output --entry Data.String.Gen --lua-output-file dist/Data.String.Gen.lua +pslua --foreign-path . --ps-output output --entry Data.String.NonEmpty --lua-output-file dist/Data.String.NonEmpty.lua +pslua --foreign-path . --ps-output output --entry Data.String.NonEmpty.CaseInsensitive --lua-output-file dist/Data.String.NonEmpty.CaseInsensitive.lua +pslua --foreign-path . --ps-output output --entry Data.String.NonEmpty.CodePoints --lua-output-file dist/Data.String.NonEmpty.CodePoints.lua +pslua --foreign-path . --ps-output output --entry Data.String.NonEmpty.CodeUnits --lua-output-file dist/Data.String.NonEmpty.CodeUnits.lua +pslua --foreign-path . --ps-output output --entry Data.String.NonEmpty.Internal --lua-output-file dist/Data.String.NonEmpty.Internal.lua +pslua --foreign-path . --ps-output output --entry Data.String.Pattern --lua-output-file dist/Data.String.Pattern.lua +pslua --foreign-path . --ps-output output --entry Data.String.Unsafe --lua-output-file dist/Data.String.Unsafe.lua diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..990d2e2 --- /dev/null +++ b/scripts/test @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +echo "Testing..." + +spago build --config spago-test.dhall --quiet + +if lua -e 'dofile("dist/test.lua").main()'; then + echo "✅ Tests succeeded." +else + echo "❌ Tests failed." +fi diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..a3e1a1d --- /dev/null +++ b/spago.dhall @@ -0,0 +1,20 @@ +{ name = "purescript-lua-strings" +, dependencies = + [ "arrays" + , "enums" + , "foldable-traversable" + , "gen" + , "integers" + , "maybe" + , "newtype" + , "nonempty" + , "partial" + , "prelude" + , "tailrec" + , "tuples" + , "unfoldable" + , "unsafe-coerce" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs" ] +} diff --git a/src/Data/String/CodePoints.lua b/src/Data/String/CodePoints.lua new file mode 100644 index 0000000..0c3837d --- /dev/null +++ b/src/Data/String/CodePoints.lua @@ -0,0 +1,8 @@ +return { + _toCodePointArray = (function (str) + error("Not implemented: _toCodePointArray") + end), + _fromCodePointArray = (function (codePoints) + error("Not implemented: _fromCodePointArray") + end), +} diff --git a/src/Data/String/CodeUnits.lua b/src/Data/String/CodeUnits.lua new file mode 100644 index 0000000..c786f68 --- /dev/null +++ b/src/Data/String/CodeUnits.lua @@ -0,0 +1,105 @@ +return { + fromCharArray = (function(a) return table.concat(a) end), + toCharArray = (function(s) + local t = {} + for i = 1, #s do t[i] = s:sub(i, i) end + return t + end), + singleton = (function(c) return c end), + _charAt = (function(just) + return function(nothing) + return function(i) + return function(s) + if i >= 1 and i <= #s then + return just(s:sub(i, i)) + else + return nothing + end + end + end + end + end), + _toChar = (function(just) + return function(nothing) + return function(s) + if #s == 1 then + return just(s) + else + return nothing + end + end + end + end), + length = (function(s) return #s end), + countPrefix = (function(p) + return function(s) + local i = 1 + while i <= #s and p(s:sub(i, i)) do i = i + 1 end + return i - 1 + end + end), + _indexOf = (function(just) + return function(nothing) + return function(x) + return function(s) + local i = s:find(x, 1, true) + if i then + return just(i) + else + return nothing + end + end + end + end + end), + _indexOfStartingAt = (function(just) + return function(nothing) + return function(x) + return function(startAt) + return function(s) + local i = s:find(x, startAt, true) + if i then + return just(i) + else + return nothing + end + end + end + end + end + end), + _lastIndexOf = (function(just) + return function(nothing) + return function(x) + return function(s) + local i = s:reverse():find(x:reverse(), 1, true) + if i then + return just(#s - i + 1) + else + return nothing + end + end + end + end + end), + _lastIndexOfStartingAt = (function(just) + return function(nothing) + return function(x) + return function(startAt) + return function(s) + local i = s:reverse():find(x:reverse(), #s - startAt + 1, true) + if i then + return just(#s - i + 1) + else + return nothing + end + end + end + end + end + end), + take = (function(n) return function(s) return s:sub(1, n) end end), + drop = (function(n) return function(s) return s:sub(n + 1) end end), + slice = (function(b) return function(e) return function(s) return s:sub(b + 1, e) end end end), + splitAt = (function(i) return function(s) return {before = s:sub(1, i), after = s:sub(i + 1)} end end) +} diff --git a/src/Data/String/Common.lua b/src/Data/String/Common.lua new file mode 100644 index 0000000..0e7b606 --- /dev/null +++ b/src/Data/String/Common.lua @@ -0,0 +1,26 @@ +return { + _localeCompare = (function(lt) + return function(eq) + return function(gt) + return function(s1) return function(s2) return (s1 < s2) and lt or (s2 < s1) and gt or eq end end + end + end + end), + replace = (function(pattern) + return function(replacement) return function(string) return string:gsub(pattern, replacement, 1) end end + end), + replaceAll = (function(pattern) + return function(replacement) return function(string) return string:gsub(pattern, replacement) end end + end), + split = (function(sep) + return function(s) + local t = {} + for str in s:gmatch("([^" .. sep .. "]+)") do table.insert(t, str) end + return t + end + end), + toLower = (function(s) return s:lower() end), + toUpper = (function(s) return s:upper() end), + trim = (function(s) return s:match("^%s*(.-)%s*$") end), + joinWith = (function(sep) return function(xs) return table.concat(xs, sep) end end) +} diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js deleted file mode 100644 index 3196034..0000000 --- a/src/Data/String/Regex.js +++ /dev/null @@ -1,103 +0,0 @@ -export const showRegexImpl = function (r) { - return "" + r; -}; - -export const regexImpl = function (left) { - return function (right) { - return function (s1) { - return function (s2) { - try { - return right(new RegExp(s1, s2)); - } catch (e) { - return left(e.message); - } - }; - }; - }; -}; - -export const source = function (r) { - return r.source; -}; - -export const flagsImpl = function (r) { - return { - multiline: r.multiline, - ignoreCase: r.ignoreCase, - global: r.global, - dotAll: r.dotAll, - sticky: !!r.sticky, - unicode: !!r.unicode - }; -}; - -export const test = function (r) { - return function (s) { - var lastIndex = r.lastIndex; - var result = r.test(s); - r.lastIndex = lastIndex; - return result; - }; -}; - -export const _match = function (just) { - return function (nothing) { - return function (r) { - return function (s) { - var m = s.match(r); - if (m == null || m.length === 0) { - return nothing; - } else { - for (var i = 0; i < m.length; i++) { - m[i] = m[i] == null ? nothing : just(m[i]); - } - return just(m); - } - }; - }; - }; -}; - -export const replace = function (r) { - return function (s1) { - return function (s2) { - return s2.replace(r, s1); - }; - }; -}; - -export const _replaceBy = function (just) { - return function (nothing) { - return function (r) { - return function (f) { - return function (s) { - return s.replace(r, function (match) { - var groups = []; - var group, i = 1; - while (typeof (group = arguments[i++]) !== "number") { - groups.push(group == null ? nothing : just(group)); - } - return f(match)(groups); - }); - }; - }; - }; - }; -}; - -export const _search = function (just) { - return function (nothing) { - return function (r) { - return function (s) { - var result = s.search(r); - return result === -1 ? nothing : just(result); - }; - }; - }; -}; - -export const split = function (r) { - return function (s) { - return s.split(r); - }; -}; diff --git a/src/Data/String/Regex.purs b/src/Data/String/Regex.purs deleted file mode 100644 index aae56e1..0000000 --- a/src/Data/String/Regex.purs +++ /dev/null @@ -1,131 +0,0 @@ --- | Wraps Javascript's `RegExp` object that enables matching strings with --- | patterns defined by regular expressions. --- | For details of the underlying implementation, see [RegExp Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp). -module Data.String.Regex - ( Regex(..) - , regex - , source - , flags - , renderFlags - , parseFlags - , test - , match - , replace - , replace' - , search - , split - ) where - -import Prelude - -import Data.Array.NonEmpty (NonEmptyArray) -import Data.Either (Either(..)) -import Data.Maybe (Maybe(..)) -import Data.String (contains) -import Data.String.Pattern (Pattern(..)) -import Data.String.Regex.Flags (RegexFlags(..), RegexFlagsRec) - --- | Wraps Javascript `RegExp` objects. -foreign import data Regex :: Type - -foreign import showRegexImpl :: Regex -> String - -instance showRegex :: Show Regex where - show = showRegexImpl - -foreign import regexImpl - :: (String -> Either String Regex) - -> (Regex -> Either String Regex) - -> String - -> String - -> Either String Regex - --- | Constructs a `Regex` from a pattern string and flags. Fails with --- | `Left error` if the pattern contains a syntax error. -regex :: String -> RegexFlags -> Either String Regex -regex s f = regexImpl Left Right s $ renderFlags f - --- | Returns the pattern string used to construct the given `Regex`. -foreign import source :: Regex -> String - --- | Returns the `RegexFlags` used to construct the given `Regex`. -flags :: Regex -> RegexFlags -flags = RegexFlags <<< flagsImpl - --- | Returns the `RegexFlags` inner record used to construct the given `Regex`. -foreign import flagsImpl :: Regex -> RegexFlagsRec - --- | Returns the string representation of the given `RegexFlags`. -renderFlags :: RegexFlags -> String -renderFlags (RegexFlags f) = - (if f.global then "g" else "") <> - (if f.ignoreCase then "i" else "") <> - (if f.multiline then "m" else "") <> - (if f.dotAll then "s" else "") <> - (if f.sticky then "y" else "") <> - (if f.unicode then "u" else "") - --- | Parses the string representation of `RegexFlags`. -parseFlags :: String -> RegexFlags -parseFlags s = RegexFlags - { global: contains (Pattern "g") s - , ignoreCase: contains (Pattern "i") s - , multiline: contains (Pattern "m") s - , dotAll: contains (Pattern "s") s - , sticky: contains (Pattern "y") s - , unicode: contains (Pattern "u") s - } - --- | Returns `true` if the `Regex` matches the string. In contrast to --- | `RegExp.prototype.test()` in JavaScript, `test` does not affect --- | the `lastIndex` property of the Regex. -foreign import test :: Regex -> String -> Boolean - -foreign import _match - :: (forall r. r -> Maybe r) - -> (forall r. Maybe r) - -> Regex - -> String - -> Maybe (NonEmptyArray (Maybe String)) - --- | Matches the string against the `Regex` and returns an array of matches --- | if there were any. Each match has type `Maybe String`, where `Nothing` --- | represents an unmatched optional capturing group. --- | See [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match). -match :: Regex -> String -> Maybe (NonEmptyArray (Maybe String)) -match = _match Just Nothing - --- | Replaces occurrences of the `Regex` with the first string. The replacement --- | string can include special replacement patterns escaped with `"$"`. --- | See [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). -foreign import replace :: Regex -> String -> String -> String - -foreign import _replaceBy - :: (forall r. r -> Maybe r) - -> (forall r. Maybe r) - -> Regex - -> (String -> Array (Maybe String) -> String) - -> String - -> String - --- | Transforms occurrences of the `Regex` using a function of the matched --- | substring and a list of captured substrings of type `Maybe String`, --- | where `Nothing` represents an unmatched optional capturing group. --- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). -replace' :: Regex -> (String -> Array (Maybe String) -> String) -> String -> String -replace' = _replaceBy Just Nothing - -foreign import _search - :: (forall r. r -> Maybe r) - -> (forall r. Maybe r) - -> Regex - -> String - -> Maybe Int - --- | Returns `Just` the index of the first match of the `Regex` in the string, --- | or `Nothing` if there is no match. -search :: Regex -> String -> Maybe Int -search = _search Just Nothing - --- | Split the string into an array of substrings along occurrences of the `Regex`. -foreign import split :: Regex -> String -> Array String diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs deleted file mode 100644 index 6d7dd71..0000000 --- a/src/Data/String/Regex/Flags.purs +++ /dev/null @@ -1,129 +0,0 @@ -module Data.String.Regex.Flags where - -import Prelude - -import Control.MonadPlus (guard) -import Data.Newtype (class Newtype) -import Data.String (joinWith) - -type RegexFlagsRec = - { global :: Boolean - , ignoreCase :: Boolean - , multiline :: Boolean - , dotAll :: Boolean - , sticky :: Boolean - , unicode :: Boolean - } - --- | Flags that control matching. -newtype RegexFlags = RegexFlags RegexFlagsRec - -derive instance newtypeRegexFlags :: Newtype RegexFlags _ - --- | All flags set to false. -noFlags :: RegexFlags -noFlags = RegexFlags - { global: false - , ignoreCase: false - , multiline: false - , dotAll: false - , sticky: false - , unicode: false - } - --- | Only global flag set to true -global :: RegexFlags -global = RegexFlags - { global: true - , ignoreCase: false - , multiline: false - , dotAll: false - , sticky: false - , unicode: false - } - --- | Only ignoreCase flag set to true -ignoreCase :: RegexFlags -ignoreCase = RegexFlags - { global: false - , ignoreCase: true - , multiline: false - , dotAll: false - , sticky: false - , unicode: false - } - --- | Only multiline flag set to true -multiline :: RegexFlags -multiline = RegexFlags - { global: false - , ignoreCase: false - , multiline: true - , dotAll: false - , sticky: false - , unicode: false - } - --- | Only sticky flag set to true -sticky :: RegexFlags -sticky = RegexFlags - { global: false - , ignoreCase: false - , multiline: false - , dotAll: false - , sticky: true - , unicode: false - } - --- | Only unicode flag set to true -unicode :: RegexFlags -unicode = RegexFlags - { global: false - , ignoreCase: false - , multiline: false - , dotAll: false - , sticky: false - , unicode: true - } - --- | Only dotAll flag set to true -dotAll :: RegexFlags -dotAll = RegexFlags - { global: false - , ignoreCase: false - , multiline: false - , dotAll: true - , sticky: false - , unicode: false - } - -instance semigroupRegexFlags :: Semigroup RegexFlags where - append (RegexFlags x) (RegexFlags y) = RegexFlags - { global: x.global || y.global - , ignoreCase: x.ignoreCase || y.ignoreCase - , multiline: x.multiline || y.multiline - , dotAll: x.dotAll || y.dotAll - , sticky: x.sticky || y.sticky - , unicode: x.unicode || y.unicode - } - -instance monoidRegexFlags :: Monoid RegexFlags where - mempty = noFlags - -derive newtype instance eqRegexFlags :: Eq RegexFlags - -instance showRegexFlags :: Show RegexFlags where - show (RegexFlags flags) = - let - usedFlags = - [] - <> (guard flags.global $> "global") - <> (guard flags.ignoreCase $> "ignoreCase") - <> (guard flags.multiline $> "multiline") - <> (guard flags.dotAll $> "dotAll") - <> (guard flags.sticky $> "sticky") - <> (guard flags.unicode $> "unicode") - in - if usedFlags == [] - then "noFlags" - else "(" <> joinWith " <> " usedFlags <> ")" diff --git a/src/Data/String/Regex/Unsafe.purs b/src/Data/String/Regex/Unsafe.purs deleted file mode 100644 index 8afd1a2..0000000 --- a/src/Data/String/Regex/Unsafe.purs +++ /dev/null @@ -1,14 +0,0 @@ -module Data.String.Regex.Unsafe - ( unsafeRegex - ) where - -import Control.Category (identity) -import Data.Either (either) -import Data.String.Regex (Regex, regex) -import Data.String.Regex.Flags (RegexFlags) -import Partial.Unsafe (unsafeCrashWith) - --- | Constructs a `Regex` from a pattern string and flags. Fails with --- | an exception if the pattern contains a syntax error. -unsafeRegex :: String -> RegexFlags -> Regex -unsafeRegex s f = either unsafeCrashWith identity (regex s f) diff --git a/src/Data/String/Unsafe.lua b/src/Data/String/Unsafe.lua new file mode 100644 index 0000000..a626a5c --- /dev/null +++ b/src/Data/String/Unsafe.lua @@ -0,0 +1,12 @@ +return { + charAt = (function(i) + return function(s) + if i >= 0 and i < #s then return s:sub(i + 1, i + 1) end + error("Data.String.Unsafe.charAt: Invalid index.") + end + end), + char = (function(s) + if #s == 1 then return s end + error("Data.String.Unsafe.char: Expected string of length 1.") + end) +} diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 0000000..3ef86f0 --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,4 @@ +[formatter.lua] +command = "lua-format" +options = ["--in-place"] +includes = ["src/**/*.lua", "test/**/*.lua", "dist/*.lua"]