Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1664694134 | |||
| ebda9e1d12 | |||
| 82eb8435ab | |||
| 08dc87a307 |
12 changed files with 453 additions and 54 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use nix
|
||||||
2
.forgejo/workflows/ci.yml
Normal file
2
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
runs-on: self-hosted
|
||||||
|
|
||||||
99
.forgejo/workflows/test.yaml
Normal file
99
.forgejo/workflows/test.yaml
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
name: Haskell CI
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
- main
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: elland/haddock2:latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check versions
|
||||||
|
run: |
|
||||||
|
ghc --version
|
||||||
|
cabal --version
|
||||||
|
node --version
|
||||||
|
- name: Cache Cabal packages
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cabal/packages
|
||||||
|
~/.cabal/store
|
||||||
|
dist-newstyle
|
||||||
|
key: ${{ runner.os }}-haskell-9.10-cabal-${{ hashFiles('**/*.cabal', '**/cabal.project') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-haskell-9.10-cabal-
|
||||||
|
- name: Update Cabal package index
|
||||||
|
run: cabal update
|
||||||
|
- name: Configure project
|
||||||
|
run: cabal configure --enable-tests --enable-benchmarks
|
||||||
|
- name: Build dependencies
|
||||||
|
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
|
||||||
|
- name: Build project
|
||||||
|
run: cabal build --enable-tests --enable-benchmarks
|
||||||
|
- name: Run documentation build
|
||||||
|
run: cabal haddock
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: elland/haddock2:latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Cache Cabal packages
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cabal/packages
|
||||||
|
~/.cabal/store
|
||||||
|
dist-newstyle
|
||||||
|
key: ${{ runner.os }}-haskell-9.10-cabal-${{ hashFiles('**/*.cabal', '**/cabal.project') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-haskell-9.10-cabal-
|
||||||
|
- name: Update Cabal package index
|
||||||
|
run: cabal update
|
||||||
|
- name: Configure project
|
||||||
|
run: cabal configure --enable-tests --enable-benchmarks
|
||||||
|
- name: Build dependencies
|
||||||
|
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
|
||||||
|
- name: Build project
|
||||||
|
run: cabal build --enable-tests --enable-benchmarks
|
||||||
|
- name: Run tests
|
||||||
|
run: cabal test --test-show-details=direct
|
||||||
|
|
||||||
|
fourmolu:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: elland/haddock2:latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Run fourmolu
|
||||||
|
run: |
|
||||||
|
find src test app -name "*.hs" -exec fourmolu --check-idempotence {} \; 2>/dev/null || true
|
||||||
|
find src test app -name "*.hs" -exec fourmolu --mode check {} \;
|
||||||
|
|
||||||
|
hlint:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: elland/haddock2:latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Run hlint
|
||||||
|
run: |
|
||||||
|
if [ -d src ]; then hlint src/; fi
|
||||||
|
if [ -d test ]; then hlint test/; fi
|
||||||
|
if [ -d app ]; then hlint app/; fi
|
||||||
36
Dockerfile
Normal file
36
Dockerfile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
FROM haskell:9.10.2-bullseye AS builder
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
|
||||||
|
apt-get install -y nodejs && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN cabal update && \
|
||||||
|
cabal install --install-method=copy --installdir=/usr/local/bin \
|
||||||
|
fourmolu hlint cabal-gild
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
|
||||||
|
FROM haskell:9.10.2-bullseye
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
libgmp10 \
|
||||||
|
curl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
|
||||||
|
apt-get install -y nodejs && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN cabal update
|
||||||
|
|
||||||
|
COPY --from=builder /usr/local/bin/cabal /usr/local/bin/
|
||||||
|
COPY --from=builder /usr/local/bin/fourmolu /usr/local/bin/
|
||||||
|
COPY --from=builder /usr/local/bin/hlint /usr/local/bin/
|
||||||
|
COPY --from=builder /usr/local/bin/cabal-gild /usr/local/bin/
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
|
||||||
|
CMD [ "bash" ]
|
||||||
|
|
||||||
41
Makefile
41
Makefile
|
|
@ -1,9 +1,44 @@
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help: ## Show this help.
|
help: ## Show this help
|
||||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
.PHONY: format
|
.PHONY: build
|
||||||
format:
|
build: ## Build the project
|
||||||
|
cabal build
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: ## Run tests
|
||||||
|
cabal test --test-show-details=direct
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean: ## Clean build artifacts
|
||||||
|
cabal clean
|
||||||
|
|
||||||
|
.PHONY: fourmolu
|
||||||
|
fourmolu: ## Format Haskell code
|
||||||
find . -type f -name "*.hs" ! -path "./dist-newstyle/*" -exec fourmolu -i {} +
|
find . -type f -name "*.hs" ! -path "./dist-newstyle/*" -exec fourmolu -i {} +
|
||||||
|
|
||||||
|
.PHONY: fourmolu-check
|
||||||
|
fourmolu-check: ## Check if code is formatted
|
||||||
|
find . -type f -name "*.hs" ! -path "./dist-newstyle/*" -exec fourmolu --mode check {} \;
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: ## Run hlint
|
||||||
|
hlint src test app
|
||||||
|
|
||||||
|
.PHONY: cabal-gild
|
||||||
|
cabal-gild: ## Format cabal file
|
||||||
cabal-gild --io=haddock2.cabal
|
cabal-gild --io=haddock2.cabal
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format: fourmolu cabal-gild ## Run all formatters
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: fourmolu-check lint ## Run all checks (CI-style)
|
||||||
|
|
||||||
|
.PHONY: ci
|
||||||
|
ci: build test check ## Run full CI pipeline locally
|
||||||
|
|
||||||
|
.PHONY: docs
|
||||||
|
docs: ## Generate documentation
|
||||||
|
cabal haddock --haddock-hyperlink-source
|
||||||
|
|
|
||||||
146
npins/default.nix
Normal file
146
npins/default.nix
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
This file is provided under the MIT licence:
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
# Generated by npins. Do not modify; will be overwritten regularly
|
||||||
|
let
|
||||||
|
data = builtins.fromJSON (builtins.readFile ./sources.json);
|
||||||
|
version = data.version;
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
|
||||||
|
range =
|
||||||
|
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
|
||||||
|
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
|
||||||
|
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
|
||||||
|
concatMapStrings = f: list: concatStrings (map f list);
|
||||||
|
concatStrings = builtins.concatStringsSep "";
|
||||||
|
|
||||||
|
# If the environment variable NPINS_OVERRIDE_${name} is set, then use
|
||||||
|
# the path directly as opposed to the fetched source.
|
||||||
|
# (Taken from Niv for compatibility)
|
||||||
|
mayOverride =
|
||||||
|
name: path:
|
||||||
|
let
|
||||||
|
envVarName = "NPINS_OVERRIDE_${saneName}";
|
||||||
|
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
|
||||||
|
ersatz = builtins.getEnv envVarName;
|
||||||
|
in
|
||||||
|
if ersatz == "" then
|
||||||
|
path
|
||||||
|
else
|
||||||
|
# this turns the string into an actual Nix path (for both absolute and
|
||||||
|
# relative paths)
|
||||||
|
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
|
||||||
|
if builtins.substring 0 1 ersatz == "/" then
|
||||||
|
/. + ersatz
|
||||||
|
else
|
||||||
|
/. + builtins.getEnv "PWD" + "/${ersatz}"
|
||||||
|
);
|
||||||
|
|
||||||
|
mkSource =
|
||||||
|
name: spec:
|
||||||
|
assert spec ? type;
|
||||||
|
let
|
||||||
|
path =
|
||||||
|
if spec.type == "Git" then
|
||||||
|
mkGitSource spec
|
||||||
|
else if spec.type == "GitRelease" then
|
||||||
|
mkGitSource spec
|
||||||
|
else if spec.type == "PyPi" then
|
||||||
|
mkPyPiSource spec
|
||||||
|
else if spec.type == "Channel" then
|
||||||
|
mkChannelSource spec
|
||||||
|
else if spec.type == "Tarball" then
|
||||||
|
mkTarballSource spec
|
||||||
|
else
|
||||||
|
builtins.throw "Unknown source type ${spec.type}";
|
||||||
|
in
|
||||||
|
spec // { outPath = mayOverride name path; };
|
||||||
|
|
||||||
|
mkGitSource =
|
||||||
|
{
|
||||||
|
repository,
|
||||||
|
revision,
|
||||||
|
url ? null,
|
||||||
|
submodules,
|
||||||
|
hash,
|
||||||
|
branch ? null,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
assert repository ? type;
|
||||||
|
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
|
||||||
|
# In the latter case, there we will always be an url to the tarball
|
||||||
|
if url != null && !submodules then
|
||||||
|
builtins.fetchTarball {
|
||||||
|
inherit url;
|
||||||
|
sha256 = hash; # FIXME: check nix version & use SRI hashes
|
||||||
|
}
|
||||||
|
else
|
||||||
|
let
|
||||||
|
url =
|
||||||
|
if repository.type == "Git" then
|
||||||
|
repository.url
|
||||||
|
else if repository.type == "GitHub" then
|
||||||
|
"https://github.com/${repository.owner}/${repository.repo}.git"
|
||||||
|
else if repository.type == "GitLab" then
|
||||||
|
"${repository.server}/${repository.repo_path}.git"
|
||||||
|
else
|
||||||
|
throw "Unrecognized repository type ${repository.type}";
|
||||||
|
urlToName =
|
||||||
|
url: rev:
|
||||||
|
let
|
||||||
|
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
|
||||||
|
|
||||||
|
short = builtins.substring 0 7 rev;
|
||||||
|
|
||||||
|
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
|
||||||
|
in
|
||||||
|
"${if matched == null then "source" else builtins.head matched}${appendShort}";
|
||||||
|
name = urlToName url revision;
|
||||||
|
in
|
||||||
|
builtins.fetchGit {
|
||||||
|
rev = revision;
|
||||||
|
inherit name;
|
||||||
|
# hash = hash;
|
||||||
|
inherit url submodules;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkPyPiSource =
|
||||||
|
{ url, hash, ... }:
|
||||||
|
builtins.fetchurl {
|
||||||
|
inherit url;
|
||||||
|
sha256 = hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkChannelSource =
|
||||||
|
{ url, hash, ... }:
|
||||||
|
builtins.fetchTarball {
|
||||||
|
inherit url;
|
||||||
|
sha256 = hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkTarballSource =
|
||||||
|
{
|
||||||
|
url,
|
||||||
|
locked_url ? url,
|
||||||
|
hash,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
builtins.fetchTarball {
|
||||||
|
url = locked_url;
|
||||||
|
sha256 = hash;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
if version == 5 then
|
||||||
|
builtins.mapAttrs mkSource data.pins
|
||||||
|
else
|
||||||
|
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
|
||||||
11
npins/sources.json
Normal file
11
npins/sources.json
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"pins": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"type": "Channel",
|
||||||
|
"name": "nixpkgs-unstable",
|
||||||
|
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.11pre868532.647e5c14cbd5/nixexprs.tar.xz",
|
||||||
|
"hash": "0i6mgl7pm7y4ydrrll7szmv8hhxb3cyny8x1g1a8sp3g5wl3yd9g"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": 5
|
||||||
|
}
|
||||||
25
shell.nix
Normal file
25
shell.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
let
|
||||||
|
sources = import ./npins;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
pkgs ? import sources.nixpkgs { },
|
||||||
|
}:
|
||||||
|
|
||||||
|
pkgs.mkShell rec {
|
||||||
|
name = "haddock2";
|
||||||
|
|
||||||
|
packages =
|
||||||
|
with pkgs;
|
||||||
|
[
|
||||||
|
haskell.packages.ghc912.ghc
|
||||||
|
haskell.packages.ghc912.haskell-language-server
|
||||||
|
zlib
|
||||||
|
]
|
||||||
|
++ map haskell.lib.justStaticExecutables [
|
||||||
|
haskellPackages.cabal-gild
|
||||||
|
haskellPackages.fourmolu
|
||||||
|
cabal-install
|
||||||
|
];
|
||||||
|
|
||||||
|
env.LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath packages;
|
||||||
|
}
|
||||||
32
src/Lexer.hs
32
src/Lexer.hs
|
|
@ -8,10 +8,11 @@ module Lexer (
|
||||||
where
|
where
|
||||||
|
|
||||||
import Control.Monad (mfilter, void)
|
import Control.Monad (mfilter, void)
|
||||||
|
import Data.Char (ord, toLower)
|
||||||
import Data.Functor (($>))
|
import Data.Functor (($>))
|
||||||
import Data.Text (Text, intercalate)
|
import Data.Text (Text, intercalate)
|
||||||
import Data.Text qualified as Text
|
import Data.Text qualified as Text
|
||||||
import GHC.Unicode (isAlphaNum, isControl, isPrint, isSpace, isUpper)
|
import GHC.Unicode (isAlphaNum, isControl, isDigit, isPrint, isSpace, isUpper)
|
||||||
import ParserMonad (Parser, initialParserState)
|
import ParserMonad (Parser, initialParserState)
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec qualified as Parsec
|
import Text.Parsec qualified as Parsec
|
||||||
|
|
@ -69,7 +70,7 @@ located :: Parser a -> Parser (SourcePos, a)
|
||||||
located p = (,) <$> getPosition <*> p
|
located p = (,) <$> getPosition <*> p
|
||||||
|
|
||||||
tokenise :: [Parser a] -> Parser [(SourcePos, a)]
|
tokenise :: [Parser a] -> Parser [(SourcePos, a)]
|
||||||
tokenise = sequence . map located
|
tokenise = mapM located
|
||||||
|
|
||||||
lexer :: String -> Either ParseError [LocatedToken]
|
lexer :: String -> Either ParseError [LocatedToken]
|
||||||
lexer = Parsec.runParser lexText initialParserState "input" . Text.pack
|
lexer = Parsec.runParser lexText initialParserState "input" . Text.pack
|
||||||
|
|
@ -94,6 +95,7 @@ lexText = go
|
||||||
, labeledLink
|
, labeledLink
|
||||||
, module_
|
, module_
|
||||||
, anchor
|
, anchor
|
||||||
|
, numericEntity
|
||||||
, textElement
|
, textElement
|
||||||
, quotes
|
, quotes
|
||||||
, birdTrack
|
, birdTrack
|
||||||
|
|
@ -146,7 +148,7 @@ delimitedNoTrailing openP closeP openTok = asList <$> delimitedAsTuple (openTok
|
||||||
asList (a, tok, _) = [a, tok]
|
asList (a, tok, _) = [a, tok]
|
||||||
|
|
||||||
delimitedSymmetric :: Parser a -> Token -> Token -> Parser [LocatedToken]
|
delimitedSymmetric :: Parser a -> Token -> Token -> Parser [LocatedToken]
|
||||||
delimitedSymmetric s t1 t2 = delimited s s t1 t2
|
delimitedSymmetric s = delimited s s
|
||||||
|
|
||||||
eol :: Parser ()
|
eol :: Parser ()
|
||||||
eol = void "\n" <|> void "\r\n" <|> Parsec.eof
|
eol = void "\n" <|> void "\r\n" <|> Parsec.eof
|
||||||
|
|
@ -255,6 +257,30 @@ bold = delimitedSymmetric "__" BoldOpen BoldClose
|
||||||
monospace :: Lexer
|
monospace :: Lexer
|
||||||
monospace = delimitedSymmetric "@" MonospaceOpen MonospaceClose
|
monospace = delimitedSymmetric "@" MonospaceOpen MonospaceClose
|
||||||
|
|
||||||
|
decimal :: Parser Int
|
||||||
|
decimal = read . Text.unpack <$> takeWhile1_ isDigit
|
||||||
|
|
||||||
|
hexadecimal :: Parser Int
|
||||||
|
hexadecimal = "x" *> (convert 0 . fmap (normalise . toLower) <$> many1 hexDigit)
|
||||||
|
where
|
||||||
|
normalise :: Char -> Int
|
||||||
|
normalise c
|
||||||
|
| ord '0' <= n && n <= ord '9' = n - ord '0'
|
||||||
|
| ord 'A' <= n && n <= ord 'F' = n - ord 'A' + 10
|
||||||
|
| ord 'a' <= n && n <= ord 'f' = n - ord 'a' + 10
|
||||||
|
| otherwise = error "unexpected: invalid hex number"
|
||||||
|
where
|
||||||
|
n = ord c
|
||||||
|
|
||||||
|
convert :: Int -> [Int] -> Int
|
||||||
|
convert acc [] = acc
|
||||||
|
convert acc (x : xs) = convert (acc * 16 + x) xs
|
||||||
|
|
||||||
|
numericEntity :: Lexer
|
||||||
|
numericEntity = do
|
||||||
|
x <- located $ between "&#" ";" (NumericEntity <$> (hexadecimal <|> decimal))
|
||||||
|
pure [x]
|
||||||
|
|
||||||
other :: Lexer
|
other :: Lexer
|
||||||
other = do
|
other = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ import Text.Parsec.Pos (updatePosChar)
|
||||||
Return everything consumed except for the end pattern itself.
|
Return everything consumed except for the end pattern itself.
|
||||||
-}
|
-}
|
||||||
takeUntil :: Text -> Parser Text
|
takeUntil :: Text -> Parser Text
|
||||||
takeUntil end_ = Text.dropEnd (Text.length end_) <$> requireEnd (scan p (False, end)) >>= gotSome
|
takeUntil end_ =
|
||||||
|
requireEnd (scan p (False, end))
|
||||||
|
>>= gotSome . Text.dropEnd (Text.length end_)
|
||||||
where
|
where
|
||||||
end = Text.unpack end_
|
end = Text.unpack end_
|
||||||
|
|
||||||
|
|
|
||||||
83
src/Types.hs
83
src/Types.hs
|
|
@ -9,6 +9,8 @@ module Types (
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
import Data.Foldable (fold)
|
||||||
|
|
||||||
newtype Document = Document
|
newtype Document = Document
|
||||||
{ meta :: Meta
|
{ meta :: Meta
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +30,7 @@ data Since = Since
|
||||||
|
|
||||||
-- Could have a better type?
|
-- Could have a better type?
|
||||||
type Version = [Int]
|
type Version = [Int]
|
||||||
|
|
||||||
type Package = String
|
type Package = String
|
||||||
|
|
||||||
data DocMarkup mod id
|
data DocMarkup mod id
|
||||||
|
|
@ -51,78 +54,78 @@ data DocMarkup mod id
|
||||||
| -- | Bold __bold text__
|
| -- | Bold __bold text__
|
||||||
DocBold (DocMarkup mod id)
|
DocBold (DocMarkup mod id)
|
||||||
| {- | Unordered lists
|
| {- | Unordered lists
|
||||||
* this
|
* this
|
||||||
or
|
or
|
||||||
- this
|
- this
|
||||||
-}
|
-}
|
||||||
DocUnorderedList [DocMarkup mod id]
|
DocUnorderedList [DocMarkup mod id]
|
||||||
| {- | Ordered lists
|
| {- | Ordered lists
|
||||||
1. this
|
1. this
|
||||||
or
|
or
|
||||||
(1) this
|
(1) this
|
||||||
-}
|
-}
|
||||||
DocOrderedList [(Int, DocMarkup mod id)]
|
DocOrderedList [(Int, DocMarkup mod id)]
|
||||||
| {- | Definition lists
|
| {- | Definition lists
|
||||||
[term] a term
|
[term] a term
|
||||||
[another term] another definition
|
[another term] another definition
|
||||||
-}
|
-}
|
||||||
DocDefinitionList [(DocMarkup mod id, DocMarkup mod id)]
|
DocDefinitionList [(DocMarkup mod id, DocMarkup mod id)]
|
||||||
| {- | Code blocks
|
| {- | Code blocks
|
||||||
@
|
@
|
||||||
a code block in here
|
a code block in here
|
||||||
with multiple lines
|
with multiple lines
|
||||||
@
|
@
|
||||||
|
|
||||||
Or with bird tracks:
|
Or with bird tracks:
|
||||||
> some code
|
> some code
|
||||||
> goes here
|
> goes here
|
||||||
-}
|
-}
|
||||||
DocCodeBlock (DocMarkup mod id)
|
DocCodeBlock (DocMarkup mod id)
|
||||||
| {- | Hyperlinks
|
| {- | Hyperlinks
|
||||||
__marked__:
|
__marked__:
|
||||||
<http://example.com>
|
<http://example.com>
|
||||||
<http://example.com label text>
|
<http://example.com label text>
|
||||||
__Auto-detected URLs__:
|
__Auto-detected URLs__:
|
||||||
http://example.com
|
http://example.com
|
||||||
https://example.com
|
https://example.com
|
||||||
ftp://example.com
|
ftp://example.com
|
||||||
__Markdown style__
|
__Markdown style__
|
||||||
[link text](http://example.com)
|
[link text](http://example.com)
|
||||||
[link text]("Module.Name")
|
[link text]("Module.Name")
|
||||||
-}
|
-}
|
||||||
DocHyperlink (Hyperlink (DocMarkup mod id))
|
DocHyperlink (Hyperlink (DocMarkup mod id))
|
||||||
| {- | Pictures
|
| {- | Pictures
|
||||||
<<image.png>>
|
<<image.png>>
|
||||||
<<image.png title text>>
|
<<image.png title text>>
|
||||||
|
|
||||||
__Markdown Images__
|
__Markdown Images__
|
||||||
|
|
||||||

|

|
||||||
-}
|
-}
|
||||||
DocPicture Picture
|
DocPicture Picture
|
||||||
| {- | Inline math expressions
|
| {- | Inline math expressions
|
||||||
\(mathematical expression\)
|
\(mathematical expression\)
|
||||||
-}
|
-}
|
||||||
DocMathInline String
|
DocMathInline String
|
||||||
| {- | Math multiline display
|
| {- | Math multiline display
|
||||||
\[
|
\[
|
||||||
mathematical expression
|
mathematical expression
|
||||||
in multiple lines
|
in multiple lines
|
||||||
\]
|
\]
|
||||||
-}
|
-}
|
||||||
DocMathDisplay String
|
DocMathDisplay String
|
||||||
| {- | Anchors, no spaces allowed
|
| {- | Anchors, no spaces allowed
|
||||||
#anchor-name#
|
#anchor-name#
|
||||||
-}
|
-}
|
||||||
DocAnchor String
|
DocAnchor String
|
||||||
| {- | Property descriptions
|
| {- | Property descriptions
|
||||||
prop> property description
|
prop> property description
|
||||||
-}
|
-}
|
||||||
DocProperty String
|
DocProperty String
|
||||||
| {- | Examples
|
| {- | Examples
|
||||||
>>> expression
|
>>> expression
|
||||||
result line 1
|
result line 1
|
||||||
result line 2
|
result line 2
|
||||||
-}
|
-}
|
||||||
DocExamples [Example]
|
DocExamples [Example]
|
||||||
| -- | Header
|
| -- | Header
|
||||||
|
|
@ -136,7 +139,7 @@ instance Semigroup (DocMarkup mod id) where
|
||||||
|
|
||||||
instance Monoid (DocMarkup mod id) where
|
instance Monoid (DocMarkup mod id) where
|
||||||
mempty = DocEmpty
|
mempty = DocEmpty
|
||||||
mconcat = foldr (<>) mempty
|
mconcat = fold
|
||||||
|
|
||||||
data ModuleLink id = ModuleLink
|
data ModuleLink id = ModuleLink
|
||||||
{ name :: String
|
{ name :: String
|
||||||
|
|
|
||||||
27
test/Spec.hs
27
test/Spec.hs
|
|
@ -1,16 +1,15 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# OPTIONS_GHC -Wno-orphans #-}
|
{-# OPTIONS_GHC -Wno-orphans #-}
|
||||||
|
|
||||||
import Test.Hspec
|
import Data.String (IsString (..))
|
||||||
|
import Data.Text (Text)
|
||||||
|
import GHC.Stack
|
||||||
import Identifier (Identifier)
|
import Identifier (Identifier)
|
||||||
import Lexer
|
import Lexer
|
||||||
import Parser
|
import Parser
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
import Data.String (IsString (..))
|
import Test.Hspec
|
||||||
import Data.Text (Text)
|
|
||||||
import GHC.Stack
|
|
||||||
import Text.Parsec.Pos
|
import Text.Parsec.Pos
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
|
@ -30,13 +29,14 @@ main = hspec $ do
|
||||||
it "bird tracks" birdTracks
|
it "bird tracks" birdTracks
|
||||||
it "module names" modules
|
it "module names" modules
|
||||||
it "quotes" quotes
|
it "quotes" quotes
|
||||||
|
it "numeric entity" numericEntity
|
||||||
it "ignores nesting" ignoreNesting
|
it "ignores nesting" ignoreNesting
|
||||||
|
|
||||||
describe "Parser" do
|
describe "Parser" do
|
||||||
it "Bold" do
|
it "Bold" do
|
||||||
"__bold__" `shouldParseTo` (DocBold (DocString "bold"))
|
"__bold__" `shouldParseTo` DocBold (DocString "bold")
|
||||||
it "Emphasis" do
|
it "Emphasis" do
|
||||||
"/emphasis/" `shouldParseTo` (DocEmphasis (DocString "emphasis"))
|
"/emphasis/" `shouldParseTo` DocEmphasis (DocString "emphasis")
|
||||||
|
|
||||||
------------
|
------------
|
||||||
-- Tests
|
-- Tests
|
||||||
|
|
@ -57,6 +57,7 @@ modules = do
|
||||||
`shouldLexTo` [ (1, 2, Module "OtherModule.Name")
|
`shouldLexTo` [ (1, 2, Module "OtherModule.Name")
|
||||||
, (1, 18, Anchor "myAnchor")
|
, (1, 18, Anchor "myAnchor")
|
||||||
]
|
]
|
||||||
|
|
||||||
link :: Expectation
|
link :: Expectation
|
||||||
link =
|
link =
|
||||||
"[link to](http://some.website)"
|
"[link to](http://some.website)"
|
||||||
|
|
@ -152,6 +153,18 @@ space = do
|
||||||
, (1, 2, Newline)
|
, (1, 2, Newline)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
numericEntity :: Expectation
|
||||||
|
numericEntity = do
|
||||||
|
"A λ"
|
||||||
|
`shouldLexTo` [ (1, 1, NumericEntity 65)
|
||||||
|
, (1, 6, Space)
|
||||||
|
, (1, 7, NumericEntity 955) -- lambda
|
||||||
|
]
|
||||||
|
-- Hex
|
||||||
|
"e"
|
||||||
|
`shouldLexTo` [ (1, 1, NumericEntity 101)
|
||||||
|
]
|
||||||
|
|
||||||
monospace :: Expectation
|
monospace :: Expectation
|
||||||
monospace =
|
monospace =
|
||||||
"@mono@"
|
"@mono@"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue