mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-13 22:29:35 +03:00
renamed String => Text
This commit is contained in:
parent
83074085c6
commit
232c63e8c5
@ -244,7 +244,7 @@ main =
|
||||
|
||||
localInfos =
|
||||
let
|
||||
z = (Term.Lit (Term.Str "woot"), [])
|
||||
z = (Term.Lit (Term.Text "@#$!@#"), [])
|
||||
match r = case r of
|
||||
Just (ExplorerRequest (TermExplorer.LocalInfo focus)) ->
|
||||
Just (focus.closedSubterm, focus.pathFromClosedSubterm)
|
||||
|
@ -62,12 +62,12 @@ float = Parser.map (Term.Lit << Term.Number) Parser.Number.float
|
||||
|
||||
string : Parser Term
|
||||
string = Parser.Char.between quote quote (until quote)
|
||||
|> Parser.map (Term.Lit << Term.Str)
|
||||
|> Parser.map (Term.Lit << Term.Text)
|
||||
|
||||
openString : Parser Term
|
||||
openString =
|
||||
Parser.symbol quote `Parser.andThen` \_ -> until quote
|
||||
|> Parser.map (Term.Lit << Term.Str)
|
||||
|> Parser.map (Term.Lit << Term.Text)
|
||||
|
||||
distance : Parser Term
|
||||
distance =
|
||||
|
@ -20,7 +20,6 @@ import Maybe
|
||||
import Set
|
||||
import Set (Set)
|
||||
import String
|
||||
import Text
|
||||
import Unison.Reference as R
|
||||
import Unison.Hash (Hash)
|
||||
import Unison.Hash as H
|
||||
@ -35,7 +34,7 @@ type alias E = Path.E
|
||||
|
||||
type Literal
|
||||
= Number Float
|
||||
| Str String
|
||||
| Text String
|
||||
| Distance Distance.Distance
|
||||
|
||||
type Term
|
||||
@ -73,7 +72,7 @@ checkLiteral lit admissible = case (lit,admissible) of
|
||||
(Blank, _) -> True
|
||||
-- weird parser bug prevents use of T.Unit T.Distance as a pattern
|
||||
(Lit (Distance _), T.Unit d) -> d == T.Distance
|
||||
(Lit (Str _), T.Unit s) -> s == T.String
|
||||
(Lit (Text _), T.Unit s) -> s == T.Text
|
||||
(Lit (Number _), T.Unit n) -> n == T.Number
|
||||
(_, T.Forall n (T.Universal n')) -> if n == n' then True else False
|
||||
_ -> False
|
||||
@ -248,12 +247,12 @@ encodeDistance e = case e of
|
||||
decodeLiteral : Decoder Literal
|
||||
decodeLiteral = Decoder.union' <| \t ->
|
||||
if | t == "Number" -> Decoder.map Number Decoder.float
|
||||
| t == "String" -> Decoder.map Str Decoder.string
|
||||
| t == "Text" -> Decoder.map Text Decoder.string
|
||||
| t == "Distance" -> Decoder.map Distance decodeDistance
|
||||
|
||||
encodeLiteral l = case l of
|
||||
Number n -> Encoder.tag' "Number" Encoder.float n
|
||||
Str s -> Encoder.tag' "String" Encoder.string s
|
||||
Text s -> Encoder.tag' "Text" Encoder.string s
|
||||
Distance d -> Encoder.tag' "Distance" encodeDistance d
|
||||
|
||||
decodeTerm : Decoder Term
|
||||
|
@ -11,7 +11,7 @@ import Unison.Reference as R
|
||||
ap = E.App
|
||||
builtin s = E.Ref (R.Builtin s)
|
||||
derived s = E.Ref (R.Derived s)
|
||||
str s = E.Lit (E.Str s)
|
||||
str s = E.Lit (E.Text s)
|
||||
int n = E.Lit (E.Number (toFloat n))
|
||||
vec es = E.Vector (Array.fromList es)
|
||||
|
||||
@ -39,9 +39,9 @@ panel v e = builtin "View.panel" `ap` v `ap` e
|
||||
function1 f = builtin "View.function1" `ap` f
|
||||
source e = builtin "View.source" `ap` e
|
||||
verticalPanel es = panel (builtin "View.vertical") (vec es)
|
||||
string s = E.Lit (E.Str s)
|
||||
string s = E.Lit (E.Text s)
|
||||
text s = builtin "View.text" `ap` s
|
||||
centered s = builtin "View.textbox" `ap` builtin "Text.center" `ap` full `ap` s
|
||||
h1 s = cell (text E.Blank) (E.Lit (E.Str s))
|
||||
body s = cell (text E.Blank) (E.Lit (E.Str s))
|
||||
h1 s = cell (text E.Blank) (E.Lit (E.Text s))
|
||||
body s = cell (text E.Blank) (E.Lit (E.Text s))
|
||||
full = E.Lit (E.Distance (Distance.Fraction 1.0))
|
||||
|
@ -15,7 +15,7 @@ import Unison.Var as V
|
||||
|
||||
type Literal
|
||||
= Number
|
||||
| String
|
||||
| Text
|
||||
| Vector
|
||||
| Distance
|
||||
| Ref Reference
|
||||
@ -78,7 +78,7 @@ decodeKind = Decoder.union' <| \t ->
|
||||
decodeLiteral : Decoder Literal
|
||||
decodeLiteral = Decoder.union' <| \t ->
|
||||
if | t == "Number" -> Decoder.unit Number
|
||||
| t == "String" -> Decoder.unit String
|
||||
| t == "Text" -> Decoder.unit Text
|
||||
| t == "Vector" -> Decoder.unit Vector
|
||||
| t == "Distance" -> Decoder.unit Distance
|
||||
| t == "Ref" -> Decoder.map Ref Reference.decode
|
||||
@ -102,7 +102,7 @@ encodeKind k = case k of
|
||||
encodeLiteral : Encoder Literal
|
||||
encodeLiteral l = case l of
|
||||
Number -> Encoder.tag' "Number" Encoder.product0 ()
|
||||
String -> Encoder.tag' "String" Encoder.product0 ()
|
||||
Text -> Encoder.tag' "Text" Encoder.product0 ()
|
||||
Vector -> Encoder.tag' "Vector" Encoder.product0 ()
|
||||
Distance -> Encoder.tag' "Distance" Encoder.product0 ()
|
||||
Ref r -> Encoder.tag' "Ref" Reference.encode r
|
||||
|
@ -54,7 +54,7 @@ type alias Cur = { path : Path, term : Term }
|
||||
literalKey : Term -> Maybe String
|
||||
literalKey e = case e of
|
||||
Lit (Number n) -> Just <| toString n
|
||||
Lit (Str s) -> Just <| toString s
|
||||
Lit (Text s) -> Just <| toString s
|
||||
Lit (Distance d) -> Just <| toString d
|
||||
Blank -> Just "_"
|
||||
_ -> Nothing
|
||||
@ -66,7 +66,7 @@ key env cur = case cur.term of
|
||||
Blank -> "_"
|
||||
Var v -> "v" ++ toString v
|
||||
Lit (Number n) -> toString n
|
||||
Lit (Str s) -> "\"" ++ toString s ++ "\""
|
||||
Lit (Text s) -> toString s
|
||||
Lit (Distance d) -> toString d
|
||||
Ref r -> Metadata.firstName "anonymous" (env.metadata r)
|
||||
App f arg -> key env { cur | path <- cur.path `snoc` Fn, term <- f } ++
|
||||
@ -132,7 +132,7 @@ impl env allowBreak ambientPrec availableWidth cur =
|
||||
Ref h -> codeText (Metadata.firstName (R.toKey h) (env.metadata h)) |> L.embed (tag cur.path)
|
||||
Blank -> Styles.blank |> L.embed (tag cur.path)
|
||||
Lit (Number n) -> Styles.numericLiteral (toString n) |> L.embed (tag cur.path)
|
||||
Lit (Str s) -> Styles.stringLiteral ("\"" ++ s ++ "\"") |> L.embed (tag cur.path)
|
||||
Lit (Text s) -> Styles.stringLiteral ("\"" ++ s ++ "\"") |> L.embed (tag cur.path)
|
||||
Ann e t -> let ann = Styles.codeText (" : " ++ Type.key env t)
|
||||
in L.beside (tag cur.path)
|
||||
(impl env allowBreak 9 (availableWidth - E.widthOf ann)
|
||||
@ -321,10 +321,10 @@ builtins env allowBreak availableWidth ambientPrec cur =
|
||||
in Just (L.embed t (E.spacer w' h'))
|
||||
App (Ref (R.Builtin "View.text")) style -> case e of
|
||||
-- todo, actually interpret style
|
||||
Lit (Str s) -> Just (L.embed t (Text.leftAligned (Text.style Text.defaultStyle (Text.fromString s))))
|
||||
Lit (Text s) -> Just (L.embed t (Text.leftAligned (Text.style Text.defaultStyle (Text.fromString s))))
|
||||
App (App (App (Ref (R.Builtin "View.textbox")) (Ref (R.Builtin alignment))) (Lit (Term.Distance d))) style ->
|
||||
case e of
|
||||
Lit (Str s) ->
|
||||
Lit (Text s) ->
|
||||
-- todo, actually interpret style
|
||||
let f = case alignment of
|
||||
"Text.left" -> Text.leftAligned
|
||||
@ -375,6 +375,6 @@ reactivePaths e =
|
||||
declaredPaths : Term -> Trie Path.E String
|
||||
declaredPaths e =
|
||||
let ok e = case e of
|
||||
App (App (Ref (R.Builtin "View.declare")) (Lit (Str s))) e -> Just s
|
||||
App (App (Ref (R.Builtin "View.declare")) (Lit (Text s))) e -> Just s
|
||||
_ -> Nothing
|
||||
in Term.collectPaths ok e
|
||||
|
@ -45,7 +45,7 @@ string2 sym f = I.Primop 2 $ \xs -> case xs of
|
||||
xr <- whnf x
|
||||
yr <- whnf y
|
||||
pure $ case (xr, yr) of
|
||||
(Term.Lit (Term.String x), Term.Lit (Term.String y)) -> Term.Lit (Term.String (f x y))
|
||||
(Term.Lit (Term.Text x), Term.Lit (Term.Text y)) -> Term.Lit (Term.Text (f x y))
|
||||
(x,y) -> sym `Term.App` x `Term.App` y
|
||||
_ -> error "unpossible"
|
||||
|
||||
@ -180,7 +180,7 @@ builtins =
|
||||
num = Type.Unit Type.Number
|
||||
numOpTyp = num `arr` (num `arr` num)
|
||||
styleT = Type.Unit (Type.Ref (R.Builtin "Text.Style"))
|
||||
str = Type.Unit Type.String
|
||||
str = Type.Unit Type.Text
|
||||
strOpTyp = str `arr` (str `arr` str)
|
||||
unitT = Type.Unit (Type.Ref (R.Builtin "Unit"))
|
||||
vec a = Type.App (Type.Unit Type.Vector) a
|
||||
|
@ -6,7 +6,6 @@ import Control.Monad
|
||||
import Data.List
|
||||
import Data.Ord
|
||||
import Data.Traversable (traverse)
|
||||
import Debug.Trace
|
||||
import Unison.Eval as Eval
|
||||
import Unison.TermPath as Path
|
||||
import Unison.Metadata as MD
|
||||
@ -15,17 +14,12 @@ import Unison.Node.Store
|
||||
import Unison.Note (Noted)
|
||||
import Unison.Term (Term)
|
||||
import Unison.Type (Type)
|
||||
import qualified Data.Foldable as Foldable
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Set as S
|
||||
import qualified Unison.Note as Note
|
||||
import qualified Unison.Reference as R
|
||||
import qualified Unison.Term as E
|
||||
import qualified Unison.TermEdit as TE
|
||||
import qualified Unison.Typechecker as Typechecker
|
||||
import qualified Unison.Type as Type
|
||||
|
||||
watch msg a = trace (msg ++ " : " ++ show a) a
|
||||
|
||||
node :: (Applicative f, Monad f) => Eval (Noted f) -> Store f -> Node f R.Reference Type Term
|
||||
node eval store =
|
||||
|
@ -26,10 +26,12 @@ import qualified Unison.Type as T
|
||||
-- | Literals in the Unison language
|
||||
data Literal
|
||||
= Number Double
|
||||
| String Txt.Text
|
||||
| Text Txt.Text
|
||||
| Distance Distance.Distance
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
deriveJSON defaultOptions ''Literal
|
||||
|
||||
-- | Terms in the Unison language
|
||||
data Term
|
||||
= Var V.Var
|
||||
@ -42,12 +44,15 @@ data Term
|
||||
| Lam Term
|
||||
deriving (Eq,Ord)
|
||||
|
||||
deriveJSON defaultOptions ''Term
|
||||
makePrisms ''Term
|
||||
|
||||
instance Show Term where
|
||||
show Blank = "_"
|
||||
show (Var v) = show v
|
||||
show (Ref v) = show v
|
||||
show (Lit (Number d)) = show d
|
||||
show (Lit (String s)) = show s
|
||||
show (Lit (Text s)) = show s
|
||||
show (Lit l) = show l
|
||||
show (Vector v) = show v
|
||||
show (App f x@(App _ _)) = show f ++ " (" ++ show x ++ ")"
|
||||
@ -207,10 +212,10 @@ number :: Double -> Term
|
||||
number n = Lit (Number n)
|
||||
|
||||
string :: String -> Term
|
||||
string s = Lit (String (Txt.pack s))
|
||||
string s = Lit (Text (Txt.pack s))
|
||||
|
||||
text :: Txt.Text -> Term
|
||||
text s = Lit (String s)
|
||||
text s = Lit (Text s)
|
||||
|
||||
-- | Order a collection of declarations such that no declaration
|
||||
-- references hashes declared later in the returned list
|
||||
@ -263,7 +268,3 @@ finalizeHash = H.finalize . hash
|
||||
hashes :: [Term] -> [H.Hash]
|
||||
hashes _ = error "todo: Term.hashes"
|
||||
|
||||
deriveJSON defaultOptions ''Literal
|
||||
deriveJSON defaultOptions ''Term
|
||||
|
||||
makePrisms ''Term
|
||||
|
@ -32,7 +32,7 @@ type Env f = R.Reference -> Noted f Type
|
||||
-- | Type literals
|
||||
data Literal
|
||||
= Number
|
||||
| String
|
||||
| Text
|
||||
| Vector
|
||||
| Distance
|
||||
| Ref R.Reference -- ^ A type literal uniquely defined by some nameless Hash
|
||||
|
@ -345,7 +345,7 @@ check _ _ _ = Left $ note "type not well formed wrt context"
|
||||
synthLit :: Term.Literal -> Type
|
||||
synthLit lit = T.Unit $ case lit of
|
||||
Term.Number _ -> T.Number
|
||||
Term.String _ -> T.String
|
||||
Term.Text _ -> T.Text
|
||||
Term.Distance _ -> T.Distance
|
||||
|
||||
-- | Synthesize the type of the given term, updating the context in the process.
|
||||
|
Loading…
Reference in New Issue
Block a user