mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Tests run again.
This commit is contained in:
parent
30fff46963
commit
cd96ccbf39
@ -5,8 +5,8 @@
|
||||
(register find (Fn [&Pattern &String] Int))
|
||||
(doc find-all "Finds all indices of a pattern in a string. Returns [] otherwise.")
|
||||
(register find-all (Fn [&Pattern &String] (Array Int)))
|
||||
(doc match "Finds the match groups of the first match of a pattern in a string. Returns [] otherwise.")
|
||||
(register match (Fn [&Pattern &String] (Array String)))
|
||||
(doc match-groups "Finds the match groups of the first match of a pattern in a string. Returns [] otherwise.")
|
||||
(register match-groups (Fn [&Pattern &String] (Array String)))
|
||||
(doc match-str "Finds the first match of a pattern in a string. Returns [] otherwise.")
|
||||
(register match-str (Fn [&Pattern &String] String))
|
||||
(doc global-match "Finds all matches of a pattern in a string as a nested array. Returns [] otherwise.")
|
||||
|
@ -492,7 +492,7 @@ Array Pattern_find_MINUS_all(Pattern* p, String* s) {
|
||||
}
|
||||
|
||||
|
||||
Array Pattern_match(Pattern* p, String* s) {
|
||||
Array Pattern_match_MINUS_groups(Pattern* p, String* s) {
|
||||
String str = *s;
|
||||
Pattern pat = *p;
|
||||
int lstr = strlen(str);
|
||||
|
@ -281,9 +281,9 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#match">
|
||||
<h3 id="match">
|
||||
match
|
||||
<a class="anchor" href="#match-groups">
|
||||
<h3 id="match-groups">
|
||||
match-groups
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
|
@ -14,14 +14,13 @@
|
||||
(defn g []
|
||||
(Flip.B true))
|
||||
|
||||
;; (defn f []
|
||||
;; ())
|
||||
|
||||
;; (deftype (Blah t)
|
||||
;; [x Int])
|
||||
|
||||
(defn m []
|
||||
(Maybe.Just 123))
|
||||
|
||||
(defn n []
|
||||
(the (Maybe Int) (Maybe.Nothing)))
|
||||
|
||||
(defn main []
|
||||
(match (Flip.A 100)
|
||||
(A a) 1
|
||||
(B b) 2))
|
||||
|
@ -77,6 +77,10 @@ genConstraints root = fmap sort (gen root)
|
||||
wholeStatementConstraint : insideConditionConstraints ++
|
||||
insideTrueConstraints ++ insideFalseConstraints)
|
||||
|
||||
-- Match
|
||||
XObj Match _ _ : expr : cases ->
|
||||
return []
|
||||
|
||||
-- While
|
||||
[XObj While _ _, expr, body] ->
|
||||
do insideConditionConstraints <- gen expr
|
||||
|
@ -233,6 +233,22 @@ initialTypes typeEnv rootEnv root = evalState (visit rootEnv root) 0
|
||||
|
||||
XObj If _ _ : _ -> return (Left (InvalidObj If xobj))
|
||||
|
||||
-- Match
|
||||
matchExpr@(XObj Match _ _) : expr : cases ->
|
||||
do visitedExpr <- visit env expr
|
||||
visitedCases <- fmap sequence $ mapM (\(tag, x) -> do visitedX <- visit env x
|
||||
case visitedX of
|
||||
Left e -> return (Left e)
|
||||
Right okX -> return (Right (tag, okX)))
|
||||
(pairwise cases)
|
||||
returnType <- genVarTy
|
||||
return $ do okExpr <- visitedExpr
|
||||
okCases <- visitedCases
|
||||
return (XObj (Lst ([matchExpr, okExpr] ++ concatMap (\(a, b) -> [a, b]) okCases))
|
||||
i (Just returnType))
|
||||
|
||||
XObj Match _ _ : _ -> return (Left (InvalidObj Match xobj))
|
||||
|
||||
-- While (always return Unit)
|
||||
[whileExpr@(XObj While _ _), expr, body] ->
|
||||
do visitedExpr <- visit env expr
|
||||
|
@ -63,6 +63,7 @@ data Obj = Sym SymPath SymbolMode
|
||||
| While
|
||||
| Break
|
||||
| If
|
||||
| Match
|
||||
| Mod Env
|
||||
| Typ Ty -- TODO: Rename to Deftype!
|
||||
| DefSumtype Ty
|
||||
@ -268,6 +269,7 @@ pretty = visit 0
|
||||
Def -> "def"
|
||||
Fn _ captures -> "fn" -- ++ " <" ++ joinWithComma (map getName (Set.toList captures)) ++ ">"
|
||||
If -> "if"
|
||||
Match -> "match"
|
||||
While -> "while"
|
||||
Do -> "do"
|
||||
Let -> "let"
|
||||
|
@ -224,6 +224,7 @@ symbol = do i <- createInfo
|
||||
"let" -> return (XObj Let i Nothing)
|
||||
"break" -> return (XObj Break i Nothing)
|
||||
"if" -> return (XObj If i Nothing)
|
||||
"match" -> return (XObj Match i Nothing)
|
||||
"true" -> return (XObj (Bol True) i Nothing)
|
||||
"false" -> return (XObj (Bol False) i Nothing)
|
||||
"address" -> return (XObj Address i Nothing)
|
||||
|
@ -41,11 +41,11 @@
|
||||
"find-all works as expected if not found")
|
||||
(assert-equal test
|
||||
&[@"12"]
|
||||
&(match #"(\d+)" " 12")
|
||||
&(match-groups #"(\d+)" " 12")
|
||||
"match works as expected")
|
||||
(assert-equal test
|
||||
&[]
|
||||
&(match #"(\d+)" " ")
|
||||
&(match-groups #"(\d+)" " ")
|
||||
"match works as expected if not found")
|
||||
(assert-equal test
|
||||
true
|
||||
|
Loading…
Reference in New Issue
Block a user