All tests and transcripts passing

This commit is contained in:
Paul Chiusano 2020-11-19 14:05:07 -05:00
parent a606fba006
commit 0a5c9bb648
3 changed files with 19 additions and 25 deletions

View File

@ -108,7 +108,10 @@ pos = do
-- successful parse, and also takes care of emitting layout tokens -- successful parse, and also takes care of emitting layout tokens
-- (such as virtual semicolons and closing tokens). -- (such as virtual semicolons and closing tokens).
token' :: (a -> Pos -> Pos -> [Token Lexeme]) -> P a -> P [Token Lexeme] token' :: (a -> Pos -> Pos -> [Token Lexeme]) -> P a -> P [Token Lexeme]
token' tok p = LP.lexeme space $ do token' tok p = LP.lexeme space (token'' tok p)
token'' :: (a -> Pos -> Pos -> [Token Lexeme]) -> P a -> P [Token Lexeme]
token'' tok p = do
start <- pos start <- pos
-- We save the current state so we can backtrack the state if `p` fails. -- We save the current state so we can backtrack the state if `p` fails.
env <- S.get env <- S.get
@ -219,10 +222,9 @@ lexemes = P.optional space >> do
tok p = do start <- pos; a <- p; stop <- pos; pure [Token a start stop] tok p = do start <- pos; a <- p; stop <- pos; pure [Token a start stop]
doc :: P [Token Lexeme] doc :: P [Token Lexeme]
doc = open <+> (CP.space *> fmap merge body) <+> close' where doc = open <+> (CP.space *> fmap merge body) <+> (close <* space) where
open = tok (Open <$> lit "[:") open = token'' (\t _ _ -> t) $ tok (Open <$> lit "[:")
close = tok (Close <$ lit ":]") close = tok (Close <$ lit ":]")
close' = token' (\ts _ _ -> ts) close -- consumes trailing spaces, comments
at = lit "@" at = lit "@"
back = (Textual ":]" <$ lit "\\:]") <|> (Textual "@" <$ lit "\\@") back = (Textual ":]" <$ lit "\\:]") <|> (Textual "@" <$ lit "\\@")
merge [] = [] merge [] = []
@ -239,13 +241,14 @@ lexemes = P.optional space >> do
txt = tok (Textual <$> P.manyTill CP.anyChar (P.lookAhead sep)) txt = tok (Textual <$> P.manyTill CP.anyChar (P.lookAhead sep))
sep = void at <|> void back <|> void close sep = void at <|> void back <|> void close
backk = tok back <+> body backk = tok back <+> body
ref = at *> (tok wordyId <|> tok symbolyId) ref = at *> (tok wordyId <|> tok symbolyId <|> docTyp)
atk = (ref <|> docTyp) <+> body atk = (ref <|> docTyp) <+> body
docTyp = do docTyp = do
_ <- lit "[" _ <- lit "["
typ <- tok (P.manyTill CP.anyChar (P.lookAhead (lit "]"))) typ <- tok (P.manyTill CP.anyChar (P.lookAhead (lit "]")))
_ <- lit "]" *> CP.space _ <- lit "]" *> CP.space
pure $ fmap Reserved <$> typ t <- tok wordyId <|> tok symbolyId
pure $ (fmap Reserved <$> typ) <> t
blank = separated wordySep $ blank = separated wordySep $
char '_' *> P.optional wordyIdSeg <&> (Blank . fromMaybe "") char '_' *> P.optional wordyIdSeg <&> (Blank . fromMaybe "")

View File

@ -82,11 +82,9 @@ commented = [:
commented : Doc commented : Doc
commented = commented =
[: [: example:
example:
-- a comment -- a comment f x = x + 1
f x = x + 1
:] :]
``` ```
@ -291,8 +289,7 @@ doc6 = [:
doc6 : Doc doc6 : Doc
doc6 = doc6 =
[: [: - foo
- foo
- bar - bar
and the rest. and the rest.
:] :]
@ -382,9 +379,8 @@ para line lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolo
test1 : Doc test1 : Doc
test1 = test1 =
[: [: The internal logic starts to get hairy when you use the \@
The internal logic starts to get hairy when you use the \@ features, features, for example referencing a name like @List.take. Internally,
for example referencing a name like @List.take. Internally,
the text between each such usage is its own blob (blob ends here the text between each such usage is its own blob (blob ends here
--> @List.take), so paragraph reflow has to be aware of multiple --> @List.take), so paragraph reflow has to be aware of multiple
blobs to do paragraph reflow (or, more accurately, to do the blobs to do paragraph reflow (or, more accurately, to do the
@ -491,8 +487,7 @@ View is fine.
test2 : Doc test2 : Doc
test2 = test2 =
[: [: Take a look at this:
Take a look at this:
@[source] foo ▶ bar @[source] foo ▶ bar
:] :]
@ -501,7 +496,6 @@ But note it's not obvious how display should best be handling this. At the mome
```ucm ```ucm
.> display test2 .> display test2
Take a look at this: Take a look at this:
foo n = foo n =
use Nat + use Nat +

View File

@ -140,7 +140,6 @@ Now that documentation is linked to the definition. We can view it if we like:
.> display 1 .> display 1
`builtin.List.take n xs` returns the first `n` elements of `xs`. `builtin.List.take n xs` returns the first `n` elements of `xs`.
(No need to add line breaks manually. The display command will (No need to add line breaks manually. The display command will
do wrapping of text for you. Indent any lines where you don't do wrapping of text for you. Indent any lines where you don't
@ -164,7 +163,6 @@ Or there's also a convenient function, `docs`, which shows the `Doc` values that
```ucm ```ucm
.> docs builtin.List.take .> docs builtin.List.take
`builtin.List.take n xs` returns the first `n` elements of `xs`. `builtin.List.take n xs` returns the first `n` elements of `xs`.
(No need to add line breaks manually. The display command will (No need to add line breaks manually. The display command will
do wrapping of text for you. Indent any lines where you don't do wrapping of text for you. Indent any lines where you don't
@ -190,11 +188,10 @@ Note that if we view the source of the documentation, the various references are
docs.List.take : Doc docs.List.take : Doc
docs.List.take = docs.List.take =
[: [: `@builtin.List.take n xs` returns the first `n` elements of
`@builtin.List.take n xs` returns the first `n` elements of `xs`. `xs`. (No need to add line breaks manually. The display command
(No need to add line breaks manually. The display command will will do wrapping of text for you. Indent any lines where you
do wrapping of text for you. Indent any lines where you don't don't want it to do this.)
want it to do this.)
## Examples: ## Examples: