diff --git a/aeria-compiler/src/Aeria/Codegen/Collection.purs b/aeria-compiler/src/Aeria/Codegen/Collection.purs index af180a6..47aa333 100644 --- a/aeria-compiler/src/Aeria/Codegen/Collection.purs +++ b/aeria-compiler/src/Aeria/Codegen/Collection.purs @@ -117,7 +117,8 @@ cIcon :: CollectionIcon -> Js.Tree cIcon (CollectionIcon icon) = Js.string icon cOwned :: CollectionOwned -> Js.Tree -cOwned (CollectionOwned owned) = Js.boolean owned +cOwned (CollectionOwnedBoolean _ owned) = Js.boolean owned +cOwned (CollectionOwnedCustom _ owned) = Js.string owned cTimestamps :: CollectionTimestamps -> Js.Tree cTimestamps (CollectionTimestamps timestamps) = Js.boolean timestamps diff --git a/aeria-compiler/src/Aeria/Semantic.purs b/aeria-compiler/src/Aeria/Semantic.purs index bf323c1..615e27a 100644 --- a/aeria-compiler/src/Aeria/Semantic.purs +++ b/aeria-compiler/src/Aeria/Semantic.purs @@ -28,6 +28,7 @@ sDescription :: Collection -> SemanticM Context sDescription (Collection { name , properties + , owned , getters , table , tableMeta @@ -51,6 +52,7 @@ sDescription (Collection where go = do sProperties name properties + sOwned owned sRequired name required sTableLayout name tableLayout sLayout name layout @@ -69,6 +71,14 @@ sDescription (Collection sSearch name search ask +sOwned :: Maybe CollectionOwned -> SemanticM Unit +sOwned (Just (CollectionOwnedCustom span owned)) = + case owned of + "always" -> pure unit + "on-write" -> pure unit + _ -> throwDiagnostic span "Expected value \"always\", \"on-write\" or boolean" +sOwned _ = pure unit + sFiltersPresets :: CollectionFiltersPresets -> SemanticM Unit sFiltersPresets = traverse_ go where diff --git a/aeria-compiler/src/Aeria/Syntax/Parser.purs b/aeria-compiler/src/Aeria/Syntax/Parser.purs index e71bcec..0399e9a 100644 --- a/aeria-compiler/src/Aeria/Syntax/Parser.purs +++ b/aeria-compiler/src/Aeria/Syntax/Parser.purs @@ -50,7 +50,7 @@ sourcePos = do pName :: forall a. (Span -> String -> a) -> ParserM a pName constructor = do begin <- sourcePos - ident <- lang.identifier "Expected an identifier" + ident <- lang.identifier "an identifier" end <- sourcePos pure $ constructor (Span begin end) ident @@ -79,7 +79,7 @@ pPropertyType p = fix \self -> choice , try tPrimitives , try tCollection , try (tObject self) - ] "Expected a property type" + ] "a property type" where tPrimitives = choice [tConst, tStr, tBool, tInt, tNum, tEnum] tArray self = pArrayType self @@ -88,7 +88,7 @@ pPropertyType p = fix \self -> choice pArrayType self = do begin <- sourcePos - _ <- string "[]" "Expected \"[]\" for array type" + _ <- string "[]" "\"[]\" for array type" arrType <- self end <- sourcePos pure $ PArray (Span begin end) arrType @@ -124,12 +124,12 @@ pPropertyType p = fix \self -> choice pSimpleType constructor keyword = do begin <- sourcePos - _ <- lang.reservedOp keyword ("Expected \"" <> keyword <> "\"") + _ <- lang.reservedOp keyword ("\"" <> keyword <> "\"") end <- sourcePos pure $ constructor (Span begin end) pBoolean :: ParserM Boolean -pBoolean = pTrue <|> pFalse "Expected a boolean (\"true\" or \"false\")" +pBoolean = pTrue <|> pFalse "a boolean (\"true\" or \"false\")" where pTrue :: ParserM Boolean pTrue = lang.reserved "true" $> true @@ -147,7 +147,7 @@ pLiteral = fix \self -> choice , try pBoolean' , try pProp , pArray self - ] "Expected a literal value" + ] "a literal value" where pInteger = pLiteralValue LInteger lang.integer pNum = pLiteralValue LNum lang.float @@ -201,13 +201,13 @@ pExpr = fix \self -> buildExprParser table (expr self) binary name fun assoc = Infix go assoc where go = do - lang.reservedOp name ("Expected binary operator \"" <> name <> "\"") + lang.reservedOp name ("binary operator \"" <> name <> "\"") pure fun unary name fun = Prefix go where go = do - lang.reservedOp name ("Expected unary operator \"" <> name <> "\"") + lang.reservedOp name ("unary operator \"" <> name <> "\"") pure fun expr self = lang.parens self <|> value @@ -217,7 +217,7 @@ pExpr = fix \self -> buildExprParser table (expr self) pAttribute :: ParserM Attribute pAttribute = do begin <- sourcePos - attributeName <- lang.reservedOp "@" *> pAttributeName "Expected attribute name starting with \"@\"" + attributeName <- lang.reservedOp "@" *> pAttributeName "attribute name starting with \"@\"" attributeValue <- case attributeName of AttributeName _ "constraints" -> do beginAttributeValue <- sourcePos @@ -250,7 +250,7 @@ pCond :: ParserM Cond pCond = do lang.reserved "@cond" begin <- sourcePos - expr <- lang.parens pExpr "Expected condition expression" + expr <- lang.parens pExpr "condition expression" end <- sourcePos pure (Cond (Span begin end) expr) @@ -337,7 +337,18 @@ pCollectionIcon :: ParserM CollectionIcon pCollectionIcon = CollectionIcon <$> lang.stringLiteral pCollectionOwned :: ParserM CollectionOwned -pCollectionOwned = CollectionOwned <$> pBoolean +pCollectionOwned = pCollectionOwnedBoolean <|> pCollectionOwnedCustom + where + pCollectionOwnedBoolean = do + start <- sourcePos + value <- pBoolean + end <- sourcePos + pure $ CollectionOwnedBoolean (Span start end) value + pCollectionOwnedCustom = do + start <- sourcePos + value <- lang.stringLiteral + end <- sourcePos + pure $ CollectionOwnedCustom (Span start end) value pCollectionTimestamps :: ParserM CollectionTimestamps pCollectionTimestamps = CollectionTimestamps <$> pBoolean @@ -680,7 +691,7 @@ pCollectionLayout = lang.braces $ do , name: name' , options } - Nothing -> fail "Expected 'name' property in layout" + Nothing -> fail "'name' property in layout" where allParsers' = diff --git a/aeria-compiler/src/Aeria/Syntax/Tree.purs b/aeria-compiler/src/Aeria/Syntax/Tree.purs index 234de2a..0775c9b 100644 --- a/aeria-compiler/src/Aeria/Syntax/Tree.purs +++ b/aeria-compiler/src/Aeria/Syntax/Tree.purs @@ -565,7 +565,9 @@ instance WriteForeign CollectionIcon where , icon: writeImpl icon } -data CollectionOwned = CollectionOwned Boolean +data CollectionOwned + = CollectionOwnedBoolean Span Boolean + | CollectionOwnedCustom Span String derive instance genericCollectionOwned :: Generic CollectionOwned _ @@ -576,9 +578,14 @@ instance eqCollectionOwned :: Eq CollectionOwned where eq = genericEq instance WriteForeign CollectionOwned where - writeImpl (CollectionOwned owned) = + writeImpl (CollectionOwnedBoolean _ owned) = writeImpl - { kind: "CollectionOwned" + { kind: "CollectionOwnedBoolean" + , owned: writeImpl owned + } + writeImpl (CollectionOwnedCustom _ owned) = + writeImpl + { kind: "CollectionOwnedCustom" , owned: writeImpl owned } diff --git a/aeria-compiler/test/Suite/Syntax/collection_owned.golden b/aeria-compiler/test/Suite/Syntax/collection_owned.golden index a86bedf..81ff096 100644 --- a/aeria-compiler/test/Suite/Syntax/collection_owned.golden +++ b/aeria-compiler/test/Suite/Syntax/collection_owned.golden @@ -9,7 +9,7 @@ "kind": "Collection", "owned": { "owned": true, - "kind": "CollectionOwned" + "kind": "CollectionOwnedBoolean" } } ]