This repository was archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
WIP: Support parsing theories #40
Open
djrenren
wants to merge
1
commit into
facebookarchive:main
Choose a base branch
from
djrenren:smt_theories
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ pub use internal::{Parser, Token}; | |
|
|
||
| pomelo! { | ||
| %module internal; | ||
| %include { use crate::visitors; } | ||
| %include { use crate::visitors; use crate::parser::ParseResult; } | ||
|
|
||
| %stack_size 0; | ||
|
|
||
|
|
@@ -34,6 +34,10 @@ pomelo! { | |
|
|
||
| %type command T::Command; | ||
|
|
||
| %type theory T::Theory; | ||
|
|
||
| %type mode ParseResult<T::Command, T::Theory>; | ||
|
|
||
| %type term T::Term; | ||
| %type terms Vec<T::Term>; | ||
|
|
||
|
|
@@ -89,7 +93,7 @@ pomelo! { | |
| %type sort_dec (T::Symbol, crate::Numeral); | ||
| %type sort_decs Vec<(T::Symbol, crate::Numeral)>; | ||
|
|
||
| %start_symbol command; | ||
| %start_symbol mode; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
|
|
||
| bound_symbol ::= Symbol(s) { extra.0.visit_bound_symbol(s)? } | ||
| fresh_symbol ::= Symbol(s) { extra.0.visit_fresh_symbol(s, crate::visitors::SymbolKind::Unknown)? } | ||
|
|
@@ -355,6 +359,18 @@ pomelo! { | |
| command ::= LeftParen SetLogic bound_symbol(x) RightParen { extra.0.visit_set_logic(x)? } | ||
| // ( set-option ⟨attribute⟩ ) | ||
| command ::= LeftParen SetOption keyword(k) attribute_value(v) RightParen { extra.0.visit_set_option(k, v)? } | ||
|
|
||
|
|
||
| // ( theory ⟨symbol⟩ ⟨theory_attributes⟩+ ) | ||
| theory ::= LeftParen Theory fresh_symbol(s) RightParen { extra.0.visit_theory(s)? } | ||
|
|
||
| mode ::= command(c) { ParseResult::Command(c) } | ||
| mode ::= theory(td) { ParseResult::Theory(td) } | ||
| } | ||
|
|
||
| pub enum ParseResult<C, T> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems reasonable. (Need inline doc comment for public API though :)) |
||
| Command(C), | ||
| Theory(T), | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
|
|
@@ -369,7 +385,10 @@ pub(crate) mod tests { | |
| for token in tokens.into_iter() { | ||
| p.parse(token)?; | ||
| } | ||
| Ok(p.end_of_input()?.0) | ||
| match p.end_of_input()?.0 { | ||
| ParseResult::Command(c) => Ok(c), | ||
| ParseResult::Theory(t) => panic!("Expected command"), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,6 +482,10 @@ pub trait Smt2Visitor: | |
| <Self as Smt2Visitor>::SExpr, | ||
| T = <Self as Smt2Visitor>::Command, | ||
| E = <Self as Smt2Visitor>::Error, | ||
| > + TheoryVisitor< | ||
| <Self as Smt2Visitor>::Symbol, | ||
| T = <Self as Smt2Visitor>::Theory, | ||
| E = <Self as Smt2Visitor>::Error, | ||
| > | ||
| { | ||
| type Error; | ||
|
|
@@ -493,11 +497,20 @@ pub trait Smt2Visitor: | |
| type Symbol; | ||
| type Term; | ||
| type Command; | ||
| type Theory; | ||
|
|
||
| fn syntax_error(&mut self, position: crate::Position, s: String) -> Self::Error; | ||
| fn parsing_error(&mut self, position: crate::Position, s: String) -> Self::Error; | ||
| } | ||
|
|
||
| /// A visitor for the entire SMT2 syntax. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to fix comment |
||
| pub trait TheoryVisitor<Symbol> { | ||
| type E; | ||
| type T; | ||
|
|
||
| fn visit_theory(&mut self, name: Symbol) -> Result<Self::T, Self::E>; | ||
| } | ||
|
|
||
| impl<Symbol> std::fmt::Display for Index<Symbol> | ||
| where | ||
| Symbol: std::fmt::Display, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will return an error value here, obviously.