Skip to content

Commit

Permalink
Exposing symbol entry point to kore_pareser
Browse files Browse the repository at this point in the history
  • Loading branch information
Robertorosmaninho committed May 21, 2024
1 parent 5553a29 commit dc2785f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
9 changes: 6 additions & 3 deletions bindings/python/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,12 @@ void bind_parser(py::module_ &mod) {
"pattern",
[](kore_parser &parser) { return std::shared_ptr(parser.pattern()); })
.def("sort", [](kore_parser &parser) { return parser.sort(); })
.def("definition", [](kore_parser &parser) {
return std::shared_ptr(parser.definition());
});
.def(
"definition",
[](kore_parser &parser) {
return std::shared_ptr(parser.definition());
})
.def("symbol", &kore_parser::symbol);
}

void bind_proof_trace(py::module_ &m) {
Expand Down
1 change: 1 addition & 0 deletions include/kllvm/parser/KOREParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class kore_parser {
ptr<kore_definition> definition();
sptr<kore_pattern> pattern();
sptr<kore_sort> sort();
ptr<kore_symbol> symbol();
std::vector<ptr<kore_declaration>> declarations();

std::pair<std::string, std::vector<sptr<kore_sort>>> symbol_sort_list();
Expand Down
18 changes: 16 additions & 2 deletions lib/parser/KOREParser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "kllvm/parser/KOREParser.h"
#include "kllvm/ast/AST.h"
#include "kllvm/parser/KOREParser.h"
#include "kllvm/parser/KOREScanner.h"
#include "kllvm/util/temporary_file.h"

Expand Down Expand Up @@ -90,6 +90,7 @@ ptr<kore_definition> kore_parser::definition() {
}

sptr<kore_pattern> kore_parser::pattern() {
std::cerr << "Parsing pattern\n";
auto result = pattern_internal();
consume(token::TokenEof);
return result;
Expand Down Expand Up @@ -312,6 +313,7 @@ sptr<kore_sort> kore_parser::sort() {
}

sptr<kore_pattern> kore_parser::pattern_internal() {
std::cerr << "Parsing pattern internal\n";
token current = peek();
switch (current) {
case token::Id: {
Expand All @@ -321,7 +323,9 @@ sptr<kore_pattern> kore_parser::pattern_internal() {
case token::Colon:
consume(token::Colon);
return kore_variable_pattern::create(name, sort());
case token::LeftBrace: return application_pattern(name);
case token::LeftBrace:
std::cerr << "Passing through LeftBrace\n";
return application_pattern(name);
default: error(loc_, "Expected: [:, {] Actual: " + str(current));
}
}
Expand Down Expand Up @@ -402,6 +406,16 @@ sptr<kore_pattern> kore_parser::application_pattern(std::string const &name) {
return result;
}

ptr<kore_symbol> kore_parser::symbol() {
std::string symbol = consume(token::Id);
consume(token::LeftBrace);
auto pat = kore_composite_pattern::create(symbol);
sorts(pat->get_constructor());
pat->get_constructor()->init_pattern_arguments();
consume(token::RightBrace);
return std::make_unique<kore_symbol>(*pat->get_constructor());
}

ptr<kore_composite_pattern>
kore_parser::application_pattern_internal(std::string const &name) {
consume(token::LeftBrace);
Expand Down
11 changes: 11 additions & 0 deletions test/python/test_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_equal(self):
b1 = kllvm.ast.Symbol("B")
self.assertNotEqual(a1, b1)

def test_parse_symbol_name(self):
sym_base = kllvm.ast.Symbol("Lbl'Plus")
self.assertEqual(str(sym_base), "Lbl'Plus{}")

parser = kllvm.parser.Parser.from_string(str(sym_base))
sym_parsed = parser.symbol()
self.assertEqual(sym_base, sym_parsed)

self.assertEqual(sym_parsed.name, "Lbl'Plus")
self.assertTrue(sym_parsed.is_concrete)
self.assertFalse(sym_parsed.is_builtin)

class TestVariables(unittest.TestCase):

Expand Down

0 comments on commit dc2785f

Please sign in to comment.