diff --git a/ccl/core/include/ccl/api/RSFormJA.h b/ccl/core/include/ccl/api/RSFormJA.h index ce5c10f..418f105 100644 --- a/ccl/core/include/ccl/api/RSFormJA.h +++ b/ccl/core/include/ccl/api/RSFormJA.h @@ -25,7 +25,7 @@ public: [[nodiscard]] std::string ToMinimalJSON() const; [[nodiscard]] std::string CheckExpression(const std::string& text, rslang::Syntax syntaxHint = rslang::Syntax::UNDEF) const; - [[nodiscard]] std::string CheckConstituenta(const std::string& alias, const std::string& definition, semantic::CstType targetType) const; + [[nodiscard]] std::string CheckConstituenta(const std::string& alias, const std::string& definition, const std::string& targetType) const; }; diff --git a/ccl/core/src/api/RSFormJA.cpp b/ccl/core/src/api/RSFormJA.cpp index 2fa5c9d..4f83965 100644 --- a/ccl/core/src/api/RSFormJA.cpp +++ b/ccl/core/src/api/RSFormJA.cpp @@ -71,12 +71,11 @@ std::string RSFormJA::ToMinimalJSON() const { } std::string RSFormJA::CheckExpression(const std::string& text, const rslang::Syntax syntaxHint) const { - JSON result{}; - auto analyser = schema->Core().RSLang().MakeAuditor(); const auto typeOK = analyser->CheckExpression(text, syntaxHint); const auto valueOK = typeOK && analyser->CheckValue(); + JSON result{}; result["parseResult"] = typeOK; result["syntax"] = analyser->GetSyntax(); result["prefixLen"] = 0; @@ -111,14 +110,16 @@ std::string RSFormJA::CheckExpression(const std::string& text, const rslang::Syn std::string RSFormJA::CheckConstituenta( const std::string& alias, const std::string& definition, - semantic::CstType targetType + const std::string& targetType ) const { - JSON result{}; + JSON jType = targetType; + const auto type = jType.template get(); auto analyser = schema->Core().RSLang().MakeAuditor(); - const auto typeOK = analyser->CheckConstituenta(alias, definition, targetType); + const auto typeOK = analyser->CheckConstituenta(alias, definition, type); const auto valueOK = typeOK && analyser->CheckValue(); + JSON result{}; result["parseResult"] = typeOK; result["syntax"] = analyser->GetSyntax(); result["prefixLen"] = analyser->prefixLen; diff --git a/ccl/core/test/src/testRSFormJA.cpp b/ccl/core/test/src/testRSFormJA.cpp index cd7d515..38508ce 100644 --- a/ccl/core/test/src/testRSFormJA.cpp +++ b/ccl/core/test/src/testRSFormJA.cpp @@ -135,7 +135,7 @@ TEST_F(UTRSFormJA, CheckExpression) { TEST_F(UTRSFormJA, CheckConstituenta) { auto wrapper = RSFormJA::FromData(SetupSchema()); - auto reponse = JSON::parse(wrapper.CheckConstituenta("A100", "X1=X1", CstType::axiom)); + auto reponse = JSON::parse(wrapper.CheckConstituenta("A100", "X1=X1", "axiom")); EXPECT_EQ(reponse.at("parseResult").get(), true); EXPECT_EQ(reponse.at("prefixLen"), 7); EXPECT_EQ(reponse.at("syntax"), "math"); diff --git a/pyconcept/CHANGELOG.md b/pyconcept/CHANGELOG.md index 28daf42..9ab1e4d 100644 --- a/pyconcept/CHANGELOG.md +++ b/pyconcept/CHANGELOG.md @@ -19,10 +19,16 @@ Here we write upgrading notes. Make them as straightforward as possible. ### Fixed -## [0.1.7] - 2024-09-22 +## [0.1.8] - 2024-09-22 ### Fixed +- Change check-constituenta to use string representation of CstType + +## [0.1.7] - 2024-09-22 + +### Added + - Improve error messages for invalid types - Add API for checking constituenta expressions diff --git a/pyconcept/VERSION b/pyconcept/VERSION index a1e1395..84aa3a7 100644 --- a/pyconcept/VERSION +++ b/pyconcept/VERSION @@ -1 +1 @@ -0.1.7 \ No newline at end of file +0.1.8 \ No newline at end of file diff --git a/pyconcept/include/pyconcept.h b/pyconcept/include/pyconcept.h index 7ad6e0d..8f69390 100644 --- a/pyconcept/include/pyconcept.h +++ b/pyconcept/include/pyconcept.h @@ -19,7 +19,7 @@ std::string CheckConstituenta( const std::string& jSchema, const std::string& alias, const std::string& expression, - int cstType + const std::string& cstType ); PYBIND11_MODULE(pyconcept, m) { diff --git a/pyconcept/src/pyconcept.cpp b/pyconcept/src/pyconcept.cpp index aa8eede..ca80bd8 100644 --- a/pyconcept/src/pyconcept.cpp +++ b/pyconcept/src/pyconcept.cpp @@ -40,8 +40,8 @@ std::string CheckConstituenta( const std::string& jSchema, const std::string& alias, const std::string& expression, - int cstType + const std::string& cstType ) { auto schema = RSFormJA::FromJSON(jSchema); - return schema.CheckConstituenta(alias, expression, static_cast(cstType)); + return schema.CheckConstituenta(alias, expression, cstType); } \ No newline at end of file diff --git a/pyconcept/tests/testBinding.py b/pyconcept/tests/testBinding.py index 483b1b5..f4fd529 100644 --- a/pyconcept/tests/testBinding.py +++ b/pyconcept/tests/testBinding.py @@ -59,12 +59,15 @@ class TestBinding(unittest.TestCase): def test_check_constituenta(self): ''' Test checking expression against given schema ''' schema = self._get_default_schema() - out1 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X1', 5)) + out1 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X1', 'axiom')) self.assertEqual(out1['parseResult'], True) - out2 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X2', 5)) + out2 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X2', 'axiom')) self.assertEqual(out2['parseResult'], False) + out3 = json.loads(pc.check_constituenta(schema, 'D100', 'X1=X1', 'term')) + self.assertEqual(out3['parseResult'], False) + def test_reset_aliases(self): ''' Test reset aliases in schema ''' schema = self._get_default_schema()