Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion prqlc/bindings/elixir/native/prql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn target_from_atom(a: Atom) -> prqlc::Target {
impl From<CompileOptions> for prqlc::Options {
/// Get `prqlc::Options` options from `CompileOptions`
fn from(o: CompileOptions) -> Self {
prqlc::Options {
Self {
format: o.format,
target: target_from_atom(o.target),
signature_comment: o.signature_comment,
Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/prqlc-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl CompileOptions {
color: bool,
display: String,
) -> Self {
CompileOptions {
Self {
format,
target,
signature_comment,
Expand Down
22 changes: 11 additions & 11 deletions prqlc/prqlc-parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum Reason {

impl Error {
pub fn new(reason: Reason) -> Self {
Error {
Self {
kind: MessageKind::Error,
span: None,
reason,
Expand All @@ -83,19 +83,19 @@ impl Error {
}

pub fn new_simple<S: ToString>(reason: S) -> Self {
Error::new(Reason::Simple(reason.to_string()))
Self::new(Reason::Simple(reason.to_string()))
}

pub fn new_bug(issue_no: i32) -> Self {
Error::new(Reason::Bug {
Self::new(Reason::Bug {
issue: Some(issue_no),
details: None,
})
}

/// Used for things that you *think* should never happen, but are not sure.
pub fn new_assert<S: ToString>(details: S) -> Self {
Error::new(Reason::Bug {
Self::new(Reason::Bug {
issue: None,
details: Some(details.to_string()),
})
Expand All @@ -105,8 +105,8 @@ impl Error {
impl std::fmt::Display for Reason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Reason::Simple(text) => f.write_str(text),
Reason::Expected {
Self::Simple(text) => f.write_str(text),
Self::Expected {
who,
expected,
found,
Expand All @@ -116,9 +116,9 @@ impl std::fmt::Display for Reason {
}
write!(f, "expected {expected}, but found {found}")
}
Reason::Unexpected { found } => write!(f, "unexpected {found}"),
Reason::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"),
Reason::Bug { issue, details } => {
Self::Unexpected { found } => write!(f, "unexpected {found}"),
Self::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"),
Self::Bug { issue, details } => {
write!(f, "internal compiler error")?;
if let Some(details) = details {
write!(f, "; {details}")?;
Expand All @@ -131,7 +131,7 @@ impl std::fmt::Display for Reason {
}
Ok(())
}
Reason::Internal { message } => {
Self::Internal { message } => {
write!(f, "internal error: {message}")
}
}
Expand All @@ -140,7 +140,7 @@ impl std::fmt::Display for Reason {

impl From<Error> for Errors {
fn from(error: Error) -> Self {
Errors(vec![error])
Self(vec![error])
}
}

Expand Down
2 changes: 1 addition & 1 deletion prqlc/prqlc-parser/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Range<T> {

impl<T> Range<T> {
pub const fn unbounded() -> Self {
Range {
Self {
start: None,
end: None,
}
Expand Down
74 changes: 37 additions & 37 deletions prqlc/prqlc-parser/src/lexer/lr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub enum Literal {

impl TokenKind {
pub fn range(bind_left: bool, bind_right: bool) -> Self {
TokenKind::Range {
Self::Range {
bind_left,
bind_right,
}
Expand All @@ -109,27 +109,27 @@ pub struct ValueAndUnit {
impl std::fmt::Display for Literal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Literal::Null => write!(f, "null")?,
Literal::Integer(i) => write!(f, "{i}")?,
Literal::Float(i) => write!(f, "{i}")?,
Self::Null => write!(f, "null")?,
Self::Integer(i) => write!(f, "{i}")?,
Self::Float(i) => write!(f, "{i}")?,

Literal::String(s) => {
Self::String(s) => {
write!(f, "{}", quote_string(escape_all_except_quotes(s).as_str()))?;
}

Literal::RawString(s) => {
Self::RawString(s) => {
write!(f, "r{}", quote_string(s))?;
}

Literal::Boolean(b) => {
Self::Boolean(b) => {
f.write_str(if *b { "true" } else { "false" })?;
}

Literal::Date(inner) | Literal::Time(inner) | Literal::Timestamp(inner) => {
Self::Date(inner) | Self::Time(inner) | Self::Timestamp(inner) => {
write!(f, "@{inner}")?;
}

Literal::ValueAndUnit(i) => {
Self::ValueAndUnit(i) => {
write!(f, "{}{}", i.n, i.unit)?;
}
}
Expand Down Expand Up @@ -206,36 +206,36 @@ impl std::cmp::Eq for TokenKind {}
impl std::fmt::Display for TokenKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TokenKind::NewLine => write!(f, "new line"),
TokenKind::Ident(s) => {
Self::NewLine => write!(f, "new line"),
Self::Ident(s) => {
if s.is_empty() {
// FYI this shows up in errors
write!(f, "an identifier")
} else {
write!(f, "{s}")
}
}
TokenKind::Keyword(s) => write!(f, "keyword {s}"),
TokenKind::Literal(lit) => write!(f, "{lit}"),
TokenKind::Control(c) => write!(f, "{c}"),

TokenKind::ArrowThin => f.write_str("->"),
TokenKind::ArrowFat => f.write_str("=>"),
TokenKind::Eq => f.write_str("=="),
TokenKind::Ne => f.write_str("!="),
TokenKind::Gte => f.write_str(">="),
TokenKind::Lte => f.write_str("<="),
TokenKind::RegexSearch => f.write_str("~="),
TokenKind::And => f.write_str("&&"),
TokenKind::Or => f.write_str("||"),
TokenKind::Coalesce => f.write_str("??"),
TokenKind::DivInt => f.write_str("//"),
TokenKind::Pow => f.write_str("**"),
TokenKind::Annotate => f.write_str("@{"),

TokenKind::Param(id) => write!(f, "${id}"),

TokenKind::Range {
Self::Keyword(s) => write!(f, "keyword {s}"),
Self::Literal(lit) => write!(f, "{lit}"),
Self::Control(c) => write!(f, "{c}"),

Self::ArrowThin => f.write_str("->"),
Self::ArrowFat => f.write_str("=>"),
Self::Eq => f.write_str("=="),
Self::Ne => f.write_str("!="),
Self::Gte => f.write_str(">="),
Self::Lte => f.write_str("<="),
Self::RegexSearch => f.write_str("~="),
Self::And => f.write_str("&&"),
Self::Or => f.write_str("||"),
Self::Coalesce => f.write_str("??"),
Self::DivInt => f.write_str("//"),
Self::Pow => f.write_str("**"),
Self::Annotate => f.write_str("@{"),

Self::Param(id) => write!(f, "${id}"),

Self::Range {
bind_left,
bind_right,
} => write!(
Expand All @@ -244,23 +244,23 @@ impl std::fmt::Display for TokenKind {
if *bind_left { "" } else { " " },
if *bind_right { "" } else { " " }
),
TokenKind::Interpolation(c, s) => {
Self::Interpolation(c, s) => {
write!(f, "{c}\"{s}\"")
}
TokenKind::Comment(s) => {
Self::Comment(s) => {
writeln!(f, "#{s}")
}
TokenKind::DocComment(s) => {
Self::DocComment(s) => {
writeln!(f, "#!{s}")
}
TokenKind::LineWrap(comments) => {
Self::LineWrap(comments) => {
write!(f, "\n\\ ")?;
for comment in comments {
write!(f, "{comment}")?;
}
Ok(())
}
TokenKind::Start => write!(f, "start of input"),
Self::Start => write!(f, "start of input"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions prqlc/prqlc-parser/src/parser/perror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ where
}

impl<'a> From<Rich<'a, crate::lexer::lr::Token, Span>> for Error {
fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Error {
fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Self {
rich_error_to_error(
*rich.span(),
rich.reason(),
Expand All @@ -94,7 +94,7 @@ impl<'a> From<Rich<'a, crate::lexer::lr::Token, Span>> for Error {
}

impl<'a> From<Rich<'a, TokenKind, Span>> for Error {
fn from(rich: Rich<'a, TokenKind, Span>) -> Error {
fn from(rich: Rich<'a, TokenKind, Span>) -> Self {
rich_error_to_error(
*rich.span(),
rich.reason(),
Expand Down
6 changes: 3 additions & 3 deletions prqlc/prqlc-parser/src/parser/pr/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{generic, parser::SupportsDocComment};

impl Expr {
pub fn new<K: Into<ExprKind>>(kind: K) -> Self {
Expr {
Self {
kind: kind.into(),
span: None,
alias: None,
Expand Down Expand Up @@ -171,12 +171,12 @@ pub type SwitchCase = generic::SwitchCase<Box<Expr>>;

impl From<Literal> for ExprKind {
fn from(value: Literal) -> Self {
ExprKind::Literal(value)
Self::Literal(value)
}
}

impl From<Func> for ExprKind {
fn from(value: Func) -> Self {
ExprKind::Func(Box::new(value))
Self::Func(Box::new(value))
}
}
24 changes: 12 additions & 12 deletions prqlc/prqlc-parser/src/parser/pr/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Ident {

impl Ident {
pub fn from_name<S: ToString>(name: S) -> Self {
Ident {
Self {
path: Vec::new(),
name: name.to_string(),
}
Expand All @@ -24,7 +24,7 @@ impl Ident {
/// Panics if path is empty.
pub fn from_path<S: ToString>(mut path: Vec<S>) -> Self {
let name = path.pop().unwrap().to_string();
Ident {
Self {
path: path.into_iter().map(|x| x.to_string()).collect(),
name,
}
Expand All @@ -42,10 +42,10 @@ impl Ident {
/// Result will generally refer to the parent of this ident.
pub fn pop(self) -> Option<Self> {
let mut path = self.path;
path.pop().map(|name| Ident { path, name })
path.pop().map(|name| Self { path, name })
}

pub fn pop_front(mut self) -> (String, Option<Ident>) {
pub fn pop_front(mut self) -> (String, Option<Self>) {
if self.path.is_empty() {
(self.name, None)
} else {
Expand All @@ -54,9 +54,9 @@ impl Ident {
}
}

pub fn prepend(self, mut parts: Vec<String>) -> Ident {
pub fn prepend(self, mut parts: Vec<String>) -> Self {
parts.extend(self);
Ident::from_path(parts)
Self::from_path(parts)
}

pub fn push(&mut self, name: String) {
Expand All @@ -73,7 +73,7 @@ impl Ident {
self.path.iter().chain(std::iter::once(&self.name))
}

pub fn starts_with(&self, prefix: &Ident) -> bool {
pub fn starts_with(&self, prefix: &Self) -> bool {
if prefix.len() > self.len() {
return false;
}
Expand Down Expand Up @@ -126,11 +126,11 @@ impl IntoIterator for Ident {
}
}

impl std::ops::Add<Ident> for Ident {
type Output = Ident;
impl std::ops::Add<Self> for Ident {
type Output = Self;

fn add(self, rhs: Ident) -> Self::Output {
Ident {
fn add(self, rhs: Self) -> Self::Output {
Self {
path: self.into_iter().chain(rhs.path).collect(),
name: rhs.name,
}
Expand All @@ -156,7 +156,7 @@ impl<'de> Deserialize<'de> for Ident {
where
D: Deserializer<'de>,
{
<Vec<String> as Deserialize>::deserialize(deserializer).map(Ident::from_path)
<Vec<String> as Deserialize>::deserialize(deserializer).map(Self::from_path)
}
}

Expand Down
6 changes: 3 additions & 3 deletions prqlc/prqlc-parser/src/parser/pr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Stmt {

impl SupportsDocComment for Stmt {
fn with_doc_comment(self, doc_comment: Option<String>) -> Self {
Stmt {
Self {
doc_comment,
..self
}
Expand Down Expand Up @@ -91,8 +91,8 @@ pub struct Annotation {
}

impl Stmt {
pub fn new(kind: StmtKind) -> Stmt {
Stmt {
pub fn new(kind: StmtKind) -> Self {
Self {
kind,
span: None,
annotations: Vec::new(),
Expand Down
Loading
Loading