tiny.smt.smtlib.parse.sort
Defined in smtlib.parse.
Reads an SMT-LIB sort, or a parenthesized list of sorts, because every declaration gives the sort of a constant or the argument and result sorts of a function.
API (2)
Actions
Public operations.
list: Reads a parenthesized list of sorts, possibly empty, and returns them as a slice.parse: Reads one sort and returns it.
Source
Source: lib/smt/src/smtlib/parse/root.zig:11
zig
pub const sort = @import("sort.zig");Source: lib/smt/src/smtlib/parse/sort.zig
zig
//! Reads an SMT-LIB sort, or a parenthesized list of sorts, because every declaration gives the//! sort of a constant or the argument and result sorts of a function.//!//! The reader accepts the Boolean sort `Bool`, the integer sort `Int`, the bit-vector sort//! `(_ BitVec n)` and the array sort `(Array I E)`. The index sort `I` and the element sort `E` of//! an array are each a bit-vector sort `(_ BitVec n)`.const std = @import("std");const smt = @import("../../root.zig");const errors = @import("error.zig");const state = @import("state.zig");const token = @import("token.zig");const Error = errors.Error;const ParseError = errors.ParseError;const Parser = state.Parser;const term = smt.term;/// Reads one sort and returns it. The command reader calls it for the sort of each declaration. The/// call returns `ExpectedSort` for any other sort, arrays over other sorts included, and/// `InvalidNumber` for a width other than a decimal 32-bit unsigned number. The function accepts/// any width, 0 included.pub fn parse(parser: *Parser) Error!term.Sort { if (token.peekLeft(parser)) { try token.expectLeft(parser); const head = try token.atom(parser); if (std.mem.eql(u8, head, "_")) { const kind = try token.atom(parser); if (!std.mem.eql(u8, kind, "BitVec")) return ParseError.ExpectedSort; const width = std.fmt.parseInt(u32, try token.atom(parser), 10) catch return ParseError.InvalidNumber; try token.expectRight(parser); return .{ .bitvec = width }; } if (std.mem.eql(u8, head, "Array")) { const index = try parse(parser); const element = try parse(parser); try token.expectRight(parser); const index_width = switch (index) { .bitvec => |width| width, else => return ParseError.ExpectedSort, }; const element_width = switch (element) { .bitvec => |width| width, else => return ParseError.ExpectedSort, }; return .{ .array = .{ .index_width = index_width, .element_width = element_width } }; } return ParseError.ExpectedSort; } const sort = try token.atom(parser); if (std.mem.eql(u8, sort, "Bool")) return .bool; if (std.mem.eql(u8, sort, "Int")) return .int; return ParseError.ExpectedSort;}/// Reads a parenthesized list of sorts, possibly empty, and returns them as a slice. The command/// reader calls it for the argument sorts of `declare-fun`. The slice is allocated with the/// `Context`'s allocator, and the caller frees it. The call returns `ExpectedList` when the list/// does not open with a parenthesis, and the errors of reading one sort.pub fn list(parser: *Parser) Error![]term.Sort { try token.expectLeft(parser); var sorts: std.ArrayList(term.Sort) = .empty; errdefer sorts.deinit(parser.ctx.allocator); while (!token.peekRight(parser)) { try sorts.append(parser.ctx.allocator, try parse(parser)); } try token.expectRight(parser); return try sorts.toOwnedSlice(parser.ctx.allocator);}Audit
| Definitions | 3 |
|---|---|
| Public names | 3 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |