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

Replace print::warn and print::error with macros #1395

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

mmastrac
Copy link
Contributor

Rewrite print::{warn,error} to print::{warn!,error!} macros to remove yet another way of printing.

Most of the work done via this grit script.

engine marzano(0.1)

language rust

function concatcp_to_format($args) {
    $string = "",
    $args <: every or {
        string_literal(content=$str) where { $string += $str },
        `"$other"` where { $string += $other },
        identifier() as $node where { 
            $string += "{",
            $string += $node,
            $string += "}",
        }
    },
    return `"$string"`
}

sequential {
    bubble file($body) where $body <: maybe contains bubble any {
        `print::$level(concatcp!("$str", $expr, "$str2"))` => `"print::$level!($str{$expr}$str2)"`,
        `print::$level(concatcp!($expr, "$str"))` => `"print::$level!({$expr}$str)"`,
        `print::$level(concatcp!("$str", $expr))` => `"print::$level!($str{$expr})"`
    },
    bubble file($body) where $body <: maybe contains bubble any {
        `print::$level(concatcp!($args))` => `print::$level(__concat__($args))` where {
            $level <: `warn`,
            $level <: `error`
        }
    },
    bubble file($body) where $body <: maybe contains bubble any {
        `print::$level(__concat__($args))` as $node where {
            $args = concatcp_to_format($args),
            $node => `print::$level($args)`
        },
        `print::warn(format!($args))` => `print::warn!($args)`,
        `print::error(format!($args))` => `print::error!($args)`,
        `print::$level($args)` as $node where {
            or {
                $level <: `warn`,
                $level <: `error`            
            },
            if ($args <: arguments(args=[])) {
                $node => `print::$level!()`
            } else if ($args <: [string_literal(content=$str)]) {
                $node => `print::$level!("$str")`
            } else if ($args <: [identifier()]) {
                $node => `print::$level!("{$args}")`
            }
        }
    }
}

@mmastrac mmastrac changed the title Warn error Replace print::warn and print::error with macros Nov 12, 2024
@mmastrac mmastrac merged commit 8367287 into edgedb:master Nov 14, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants