mirror of
https://github.com/idris-lang/Idris2.git
synced 2025-01-07 00:07:19 +03:00
[ doc ] Type aliases for documentation
Use this opportunity to move definitions around and do some small refactoring.
This commit is contained in:
parent
60855adddf
commit
3869233ce0
@ -25,9 +25,16 @@ import System.File
|
|||||||
|
|
||||||
%default covering
|
%default covering
|
||||||
|
|
||||||
|
||| A series of updates is a mapping from `RawName` to `String`
|
||||||
|
||| `RawName` is currently just an alias for `String`
|
||||||
|
||| `String` is a rendered `List SourcePart`
|
||||||
|
Updates : Type
|
||||||
|
Updates = List (RawName, String)
|
||||||
|
|
||||||
|
||| Convert a RawImp update to a SourcePart one
|
||||||
toStrUpdate : {auto c : Ref Ctxt Defs} ->
|
toStrUpdate : {auto c : Ref Ctxt Defs} ->
|
||||||
{auto s : Ref Syn SyntaxInfo} ->
|
{auto s : Ref Syn SyntaxInfo} ->
|
||||||
(Name, RawImp) -> Core (List (String, String))
|
(Name, RawImp) -> Core Updates
|
||||||
toStrUpdate (UN n, term)
|
toStrUpdate (UN n, term)
|
||||||
= do clause <- pterm term
|
= do clause <- pterm term
|
||||||
pure [(n, show (bracket clause))]
|
pure [(n, show (bracket clause))]
|
||||||
@ -42,19 +49,10 @@ toStrUpdate (UN n, term)
|
|||||||
bracket tm = PBracketed emptyFC tm
|
bracket tm = PBracketed emptyFC tm
|
||||||
toStrUpdate _ = pure [] -- can't replace non user names
|
toStrUpdate _ = pure [] -- can't replace non user names
|
||||||
|
|
||||||
dump : SourcePart -> String
|
|
||||||
dump (Whitespace str) = str
|
|
||||||
dump (Name n) = n
|
|
||||||
dump (HoleName n) = "?" ++ n
|
|
||||||
dump LBrace = "{"
|
|
||||||
dump RBrace = "}"
|
|
||||||
dump Equal = "="
|
|
||||||
dump (Other str) = str
|
|
||||||
|
|
||||||
data UPD : Type where
|
data UPD : Type where
|
||||||
|
|
||||||
doUpdates : {auto u : Ref UPD (List String)} ->
|
doUpdates : {auto u : Ref UPD (List String)} ->
|
||||||
Defs -> List (String, String) -> List SourcePart ->
|
Defs -> Updates -> List SourcePart ->
|
||||||
Core (List SourcePart)
|
Core (List SourcePart)
|
||||||
doUpdates defs ups [] = pure []
|
doUpdates defs ups [] = pure []
|
||||||
doUpdates defs ups (LBrace :: xs)
|
doUpdates defs ups (LBrace :: xs)
|
||||||
@ -90,20 +88,20 @@ doUpdates defs ups (x :: xs)
|
|||||||
-- Update the token list with the string replacements for each match, and return
|
-- Update the token list with the string replacements for each match, and return
|
||||||
-- the newly generated strings.
|
-- the newly generated strings.
|
||||||
updateAll : {auto u : Ref UPD (List String)} ->
|
updateAll : {auto u : Ref UPD (List String)} ->
|
||||||
Defs -> List SourcePart -> List (List (String, String)) ->
|
Defs -> List SourcePart -> List Updates ->
|
||||||
Core (List String)
|
Core (List String)
|
||||||
updateAll defs l [] = pure []
|
updateAll defs l [] = pure []
|
||||||
updateAll defs l (rs :: rss)
|
updateAll defs l (rs :: rss)
|
||||||
= do l' <- doUpdates defs rs l
|
= do l' <- doUpdates defs rs l
|
||||||
rss' <- updateAll defs l rss
|
rss' <- updateAll defs l rss
|
||||||
pure (concat (map dump l') :: rss')
|
pure (concatMap toString l' :: rss')
|
||||||
|
|
||||||
-- Turn the replacements we got from 'getSplits' into a list of actual string
|
-- Turn the replacements we got from 'getSplits' into a list of actual string
|
||||||
-- replacements
|
-- replacements
|
||||||
getReplaces : {auto c : Ref Ctxt Defs} ->
|
getReplaces : {auto c : Ref Ctxt Defs} ->
|
||||||
{auto s : Ref Syn SyntaxInfo} ->
|
{auto s : Ref Syn SyntaxInfo} ->
|
||||||
{auto o : Ref ROpts REPLOpts} ->
|
{auto o : Ref ROpts REPLOpts} ->
|
||||||
List (Name, RawImp) -> Core (List (String, String))
|
List (Name, RawImp) -> Core Updates
|
||||||
getReplaces updates
|
getReplaces updates
|
||||||
= do strups <- traverse toStrUpdate updates
|
= do strups <- traverse toStrUpdate updates
|
||||||
pure (concat strups)
|
pure (concat strups)
|
||||||
|
@ -4,16 +4,38 @@ module Idris.IDEMode.TokenLine
|
|||||||
import Parser.Lexer.Source
|
import Parser.Lexer.Source
|
||||||
import Text.Lexer
|
import Text.Lexer
|
||||||
|
|
||||||
|
public export
|
||||||
|
RawName : Type
|
||||||
|
RawName = String
|
||||||
|
|
||||||
public export
|
public export
|
||||||
data SourcePart
|
data SourcePart
|
||||||
= Whitespace String
|
= Whitespace String
|
||||||
| Name String
|
| Name RawName
|
||||||
| HoleName String
|
| HoleName String
|
||||||
| LBrace
|
| LBrace
|
||||||
| RBrace
|
| RBrace
|
||||||
| Equal
|
| Equal
|
||||||
| Other String
|
| Other String
|
||||||
|
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
-- Printer
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export
|
||||||
|
toString : SourcePart -> String
|
||||||
|
toString (Whitespace str) = str
|
||||||
|
toString (Name n) = n
|
||||||
|
toString (HoleName n) = "?" ++ n
|
||||||
|
toString LBrace = "{"
|
||||||
|
toString RBrace = "}"
|
||||||
|
toString Equal = "="
|
||||||
|
toString (Other str) = str
|
||||||
|
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
-- Parser
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
holeIdent : Lexer
|
holeIdent : Lexer
|
||||||
holeIdent = is '?' <+> identNormal
|
holeIdent = is '?' <+> identNormal
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user