Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quoted identifiers #909

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/lib/structures/symbols.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,25 @@ let string_of_form f = match f with
| F_Iff -> "<->"
| F_Xor -> "xor"

let name_to_string =
let no_need_to_quote s =
String.length s > 0 &&
(match s.[0] with | '0'..'9' -> false | _ -> true) &&
String.for_all
(function
| 'a' .. 'z'
| 'A' .. 'Z'
| '0' .. '9'
| '~' | '!' | '@' | '$' | '%' | '^' | '&'
| '*' | '_' | '-' | '+' | '=' | '<' | '>'
| '.' | '?' | '/' -> true
| _ -> false
) s
in
fun s -> if no_need_to_quote s then s else Format.sprintf "|%s|" s

let to_string ?(show_vars=true) x = match x with
| Name (n, _, _) -> Hstring.view n
| Name (n, _, _) -> name_to_string @@ Hstring.view n
| Var v when show_vars -> Format.sprintf "'%s'" (Var.to_string v)
| Var v -> Var.to_string v
| Int n -> Z.to_string n
Expand Down
21 changes: 21 additions & 0 deletions tests/dune.inc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/smtlib/testfile-quoted1.dolmen.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

unknown
(
(define-fun |fail))| () Int 0)
)
6 changes: 6 additions & 0 deletions tests/smtlib/testfile-quoted1.dolmen.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic ALL)
(set-option :produce-models true)
(declare-const |fail))| Int)
(assert (= |fail))| 0))
(check-sat)
(get-model)
Loading