use super::{
escape_html, lean_dquote_escape, mysql_squote_escape, nix_dquote_escape, py_dquote_escape,
sh_dquote_escape, sql_squote_escape, ts_dquote_escape, Bash, Html, Lean, LiftTo, MySql, Nix,
Python, Sql, TypeScript, Wgsl, Zsh,
};
use crate::qterm::{leaf, sym, tb, QTerm};
use std::sync::Arc;
pub fn wgsl_int_term(text: &str) -> Arc<QTerm> {
leaf("int_literal", text)
}
impl LiftTo<Wgsl> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}u"))
}
}
impl LiftTo<Wgsl> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}u"))
}
}
impl LiftTo<Wgsl> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}u"))
}
}
impl LiftTo<Wgsl> for usize {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}u"))
}
}
impl LiftTo<Wgsl> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}i"))
}
}
impl LiftTo<Wgsl> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}i"))
}
}
impl LiftTo<Wgsl> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}i"))
}
}
impl LiftTo<Wgsl> for isize {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_int_term(&format!("{self}i"))
}
}
pub fn wgsl_float_term(text: &str) -> Arc<QTerm> {
leaf("float_literal", text)
}
impl LiftTo<Wgsl> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_float_term(&format!("{self}f"))
}
}
pub fn wgsl_bool_term(b: bool) -> Arc<QTerm> {
if b {
tb("bool_literal").c(&sym("true")).b()
} else {
tb("bool_literal").c(&sym("false")).b()
}
}
impl LiftTo<Wgsl> for bool {
fn lift_to(&self) -> Arc<QTerm> {
wgsl_bool_term(*self)
}
}
pub fn py_int_term(text: &str) -> Arc<QTerm> {
leaf("integer", text)
}
impl LiftTo<Python> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for usize {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
impl LiftTo<Python> for isize {
fn lift_to(&self) -> Arc<QTerm> {
py_int_term(&self.to_string())
}
}
pub fn py_float_term(text: &str) -> Arc<QTerm> {
leaf("float", text)
}
impl LiftTo<Python> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
py_float_term(&format!("{self:?}"))
}
}
impl LiftTo<Python> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
py_float_term(&format!("{self:?}"))
}
}
pub fn py_bool_term(b: bool) -> Arc<QTerm> {
if b {
leaf("true", "True")
} else {
leaf("false", "False")
}
}
impl LiftTo<Python> for bool {
fn lift_to(&self) -> Arc<QTerm> {
py_bool_term(*self)
}
}
pub fn py_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("string")
.c(&leaf("string_start", "\""))
.c(&leaf("string_end", "\""))
.b()
} else {
tb("string")
.c(&leaf("string_start", "\""))
.c(&leaf("string_content", &py_dquote_escape(s)))
.c(&leaf("string_end", "\""))
.b()
}
}
impl LiftTo<Python> for str {
fn lift_to(&self) -> Arc<QTerm> {
py_string_term(self)
}
}
impl LiftTo<Python> for String {
fn lift_to(&self) -> Arc<QTerm> {
py_string_term(self)
}
}
pub fn py_list_term(items: &[Arc<QTerm>]) -> Arc<QTerm> {
let mut b = tb("list");
b.child(&sym("["));
for (i, x) in items.iter().enumerate() {
if i > 0 {
b.child(&sym(","));
b.write(" ");
}
b.child(x);
}
b.child(&sym("]"));
b.b()
}
impl<T: LiftTo<Python>> LiftTo<Python> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
py_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<Python>> LiftTo<Python> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}
pub fn bash_number_term(text: &str) -> Arc<QTerm> {
leaf("number", text)
}
impl LiftTo<Bash> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for usize {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
impl LiftTo<Bash> for isize {
fn lift_to(&self) -> Arc<QTerm> {
bash_number_term(&self.to_string())
}
}
pub fn bash_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("string").c(&sym("\"")).c(&sym("\"")).b()
} else {
tb("string")
.c(&sym("\""))
.c(&leaf("string_content", &sh_dquote_escape(s)))
.c(&sym("\""))
.b()
}
}
impl LiftTo<Bash> for str {
fn lift_to(&self) -> Arc<QTerm> {
bash_string_term(self)
}
}
impl LiftTo<Bash> for String {
fn lift_to(&self) -> Arc<QTerm> {
bash_string_term(self)
}
}
pub fn zsh_number_term(text: &str) -> Arc<QTerm> {
leaf("number", text)
}
impl LiftTo<Zsh> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for usize {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
impl LiftTo<Zsh> for isize {
fn lift_to(&self) -> Arc<QTerm> {
zsh_number_term(&self.to_string())
}
}
pub fn zsh_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("string").c(&sym("\"")).c(&sym("\"")).b()
} else {
tb("string")
.c(&sym("\""))
.c(&leaf("string_content", &sh_dquote_escape(s)))
.c(&sym("\""))
.b()
}
}
impl LiftTo<Zsh> for str {
fn lift_to(&self) -> Arc<QTerm> {
zsh_string_term(self)
}
}
impl LiftTo<Zsh> for String {
fn lift_to(&self) -> Arc<QTerm> {
zsh_string_term(self)
}
}
pub fn nix_int_term(text: &str) -> Arc<QTerm> {
leaf("integer_expression", text)
}
impl LiftTo<Nix> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for usize {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
impl LiftTo<Nix> for isize {
fn lift_to(&self) -> Arc<QTerm> {
nix_int_term(&self.to_string())
}
}
pub fn nix_float_term(text: &str) -> Arc<QTerm> {
leaf("float_expression", text)
}
impl LiftTo<Nix> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
nix_float_term(&format!("{self:?}"))
}
}
impl LiftTo<Nix> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
nix_float_term(&format!("{self:?}"))
}
}
pub fn nix_bool_term(b: bool) -> Arc<QTerm> {
if b {
tb("variable_expression").c(&leaf("identifier", "true")).b()
} else {
tb("variable_expression")
.c(&leaf("identifier", "false"))
.b()
}
}
impl LiftTo<Nix> for bool {
fn lift_to(&self) -> Arc<QTerm> {
nix_bool_term(*self)
}
}
pub fn nix_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("string_expression").c(&sym("\"")).c(&sym("\"")).b()
} else {
tb("string_expression")
.c(&sym("\""))
.c(&leaf("string_fragment", &nix_dquote_escape(s)))
.c(&sym("\""))
.b()
}
}
impl LiftTo<Nix> for str {
fn lift_to(&self) -> Arc<QTerm> {
nix_string_term(self)
}
}
impl LiftTo<Nix> for String {
fn lift_to(&self) -> Arc<QTerm> {
nix_string_term(self)
}
}
pub fn nix_list_term(items: &[Arc<QTerm>]) -> Arc<QTerm> {
let mut b = tb("list_expression");
b.child(&sym("["));
b.write(" ");
for (i, x) in items.iter().enumerate() {
if i > 0 {
b.write(" ");
}
b.child(x);
}
if !items.is_empty() {
b.write(" ");
}
b.child(&sym("]"));
b.b()
}
impl<T: LiftTo<Nix>> LiftTo<Nix> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
nix_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<Nix>> LiftTo<Nix> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}
pub fn lean_num_term(negative: bool, text: &str) -> Arc<QTerm> {
if negative {
tb("unary_op").c(&sym("-")).c(&leaf("num_lit", text)).b()
} else {
leaf("num_lit", text)
}
}
impl LiftTo<Lean> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for usize {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(false, &self.to_string())
}
}
impl LiftTo<Lean> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Lean> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Lean> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Lean> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Lean> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Lean> for isize {
fn lift_to(&self) -> Arc<QTerm> {
lean_num_term(*self < 0, &self.unsigned_abs().to_string())
}
}
pub fn lean_float_term(negative: bool, text: &str) -> Arc<QTerm> {
if negative {
tb("unary_op")
.c(&sym("-"))
.c(&leaf("scientific_lit", text))
.b()
} else {
leaf("scientific_lit", text)
}
}
impl LiftTo<Lean> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => lean_float_term(true, mag),
None => lean_float_term(false, &s),
}
}
}
}
impl LiftTo<Lean> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => lean_float_term(true, mag),
None => lean_float_term(false, &s),
}
}
}
}
pub fn lean_bool_term(b: bool) -> Arc<QTerm> {
if b {
tb("true_const").c(&sym("true")).b()
} else {
tb("false_const").c(&sym("false")).b()
}
}
impl LiftTo<Lean> for bool {
fn lift_to(&self) -> Arc<QTerm> {
lean_bool_term(*self)
}
}
pub fn lean_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("str_lit").c(&sym("\"")).c(&sym("\"")).b()
} else {
tb("str_lit")
.c(&sym("\""))
.w(&lean_dquote_escape(s))
.c(&sym("\""))
.b()
}
}
impl LiftTo<Lean> for str {
fn lift_to(&self) -> Arc<QTerm> {
lean_string_term(self)
}
}
impl LiftTo<Lean> for String {
fn lift_to(&self) -> Arc<QTerm> {
lean_string_term(self)
}
}
pub fn lean_list_term(items: &[Arc<QTerm>]) -> Arc<QTerm> {
let mut b = tb("list_lit");
b.child(&sym("["));
for (i, x) in items.iter().enumerate() {
if i > 0 {
b.child(&sym(","));
b.write(" ");
}
b.child(x);
}
b.child(&sym("]"));
b.b()
}
pub fn sql_number_term(negative: bool, text: &str) -> Arc<QTerm> {
if negative {
tb("literal").c(&sym("-")).w(text).b()
} else {
leaf("literal", text)
}
}
impl LiftTo<Sql> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for usize {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<Sql> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for isize {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<Sql> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => sql_number_term(true, mag),
None => sql_number_term(false, &s),
}
}
}
}
impl LiftTo<Sql> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => sql_number_term(true, mag),
None => sql_number_term(false, &s),
}
}
}
}
pub fn sql_bool_term(b: bool) -> Arc<QTerm> {
if b {
tb("literal").c(&leaf("keyword_true", "TRUE")).b()
} else {
tb("literal").c(&leaf("keyword_false", "FALSE")).b()
}
}
impl LiftTo<Sql> for bool {
fn lift_to(&self) -> Arc<QTerm> {
sql_bool_term(*self)
}
}
pub fn sql_string_term(s: &str) -> Arc<QTerm> {
leaf("literal", &format!("'{}'", sql_squote_escape(s)))
}
impl LiftTo<Sql> for str {
fn lift_to(&self) -> Arc<QTerm> {
sql_string_term(self)
}
}
impl LiftTo<Sql> for String {
fn lift_to(&self) -> Arc<QTerm> {
sql_string_term(self)
}
}
pub fn sql_list_term(items: &[Arc<QTerm>]) -> Arc<QTerm> {
let mut b = tb("list");
b.child(&sym("("));
for (i, x) in items.iter().enumerate() {
if i > 0 {
b.child(&sym(","));
b.write(" ");
}
b.child(x);
}
b.child(&sym(")"));
b.b()
}
impl<T: LiftTo<Sql>> LiftTo<Sql> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
sql_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<Sql>> LiftTo<Sql> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}
impl LiftTo<MySql> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for usize {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(false, &self.to_string())
}
}
impl LiftTo<MySql> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for isize {
fn lift_to(&self) -> Arc<QTerm> {
sql_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<MySql> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => sql_number_term(true, mag),
None => sql_number_term(false, &s),
}
}
}
}
impl LiftTo<MySql> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => sql_number_term(true, mag),
None => sql_number_term(false, &s),
}
}
}
}
impl LiftTo<MySql> for bool {
fn lift_to(&self) -> Arc<QTerm> {
sql_bool_term(*self)
}
}
pub fn mysql_string_term(s: &str) -> Arc<QTerm> {
leaf("literal", &format!("'{}'", mysql_squote_escape(s)))
}
impl LiftTo<MySql> for str {
fn lift_to(&self) -> Arc<QTerm> {
mysql_string_term(self)
}
}
impl LiftTo<MySql> for String {
fn lift_to(&self) -> Arc<QTerm> {
mysql_string_term(self)
}
}
impl<T: LiftTo<MySql>> LiftTo<MySql> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
sql_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<MySql>> LiftTo<MySql> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}
pub fn ts_number_term(negative: bool, text: &str) -> Arc<QTerm> {
if negative {
tb("unary_expression")
.c(&sym("-"))
.c(&leaf("number", text))
.b()
} else {
leaf("number", text)
}
}
impl LiftTo<TypeScript> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for usize {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(false, &self.to_string())
}
}
impl LiftTo<TypeScript> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for isize {
fn lift_to(&self) -> Arc<QTerm> {
ts_number_term(*self < 0, &self.unsigned_abs().to_string())
}
}
impl LiftTo<TypeScript> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => ts_number_term(true, mag),
None => ts_number_term(false, &s),
}
}
}
}
impl LiftTo<TypeScript> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
{
let s = format!("{self:?}");
match s.strip_prefix('-') {
Some(mag) => ts_number_term(true, mag),
None => ts_number_term(false, &s),
}
}
}
}
pub fn ts_bool_term(b: bool) -> Arc<QTerm> {
if b {
sym("true")
} else {
sym("false")
}
}
impl LiftTo<TypeScript> for bool {
fn lift_to(&self) -> Arc<QTerm> {
ts_bool_term(*self)
}
}
pub fn ts_string_term(s: &str) -> Arc<QTerm> {
if s.is_empty() {
tb("string").c(&sym("\"")).c(&sym("\"")).b()
} else {
tb("string")
.c(&sym("\""))
.c(&leaf("string_fragment", &ts_dquote_escape(s)))
.c(&sym("\""))
.b()
}
}
impl LiftTo<TypeScript> for str {
fn lift_to(&self) -> Arc<QTerm> {
ts_string_term(self)
}
}
impl LiftTo<TypeScript> for String {
fn lift_to(&self) -> Arc<QTerm> {
ts_string_term(self)
}
}
pub fn ts_list_term(items: &[Arc<QTerm>]) -> Arc<QTerm> {
let mut b = tb("array");
b.child(&sym("["));
for (i, x) in items.iter().enumerate() {
if i > 0 {
b.child(&sym(","));
b.write(" ");
}
b.child(x);
}
b.child(&sym("]"));
b.b()
}
impl<T: LiftTo<TypeScript>> LiftTo<TypeScript> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
ts_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<TypeScript>> LiftTo<TypeScript> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}
pub fn html_text_term(text: &str) -> Arc<QTerm> {
leaf("text", text)
}
impl LiftTo<Html> for u8 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for u16 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for u32 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for u64 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for u128 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for usize {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for i8 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for i16 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for i32 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for i64 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for i128 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for isize {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for bool {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&self.to_string())
}
}
impl LiftTo<Html> for f32 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&format!("{self:?}"))
}
}
impl LiftTo<Html> for f64 {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&format!("{self:?}"))
}
}
impl LiftTo<Html> for str {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&escape_html(self))
}
}
impl LiftTo<Html> for String {
fn lift_to(&self) -> Arc<QTerm> {
html_text_term(&escape_html(self))
}
}
impl<T: LiftTo<Lean>> LiftTo<Lean> for [T] {
fn lift_to(&self) -> Arc<QTerm> {
lean_list_term(&self.iter().map(|x| x.lift_to()).collect::<Vec<_>>())
}
}
impl<T: LiftTo<Lean>> LiftTo<Lean> for Vec<T> {
fn lift_to(&self) -> Arc<QTerm> {
self.as_slice().lift_to()
}
}