Sign in

    sqlparser

    Extensible SQL Lexer and Parser in MoonBit

    sql
    parser
    lexer
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    78

    #username/hello

    Asc

    pub(all) enum Asc {
    Ascending
    Descending
    }

    impl Eq for Asc

    BinaryOperator

    pub(all) enum BinaryOperator {
    Eq
    Neq
    Lt
    Gt
    LtEq
    GtEq
    Spaceship
    Plus
    Minus
    Mul
    Div
    Mod
    }

    DatetimeUnit

    pub(all) enum DatetimeUnit {
    Year
    Month
    Day
    Hour
    Minute
    Second
    }

    impl Eq for DatetimeUnit

    Expr

    pub(all) enum Expr {
    Identifier(String)
    Literal(Literal)
    BinaryOperation(Expr, BinaryOperator, Expr)
    UnaryOperation(UnaryOperator, Expr)
    FunctionCall(String, Array[Expr])
    Wildcard
    Datetime(String)
    Interval(String, IntervalQualifier)
    }

    impl Eq for Expr

    IntervalQualifier

    pub(all) enum IntervalQualifier {
    Single(PrimaryDatetimeField)
    Range(PrimaryDatetimeField, PrimaryDatetimeField)
    }

    Keyword

    pub(all) enum Keyword {
    Select
    From
    Where
    As
    Group
    Order
    By
    Asc
    Desc
    Nulls
    First
    Last
    Year
    Month
    Day
    Hour
    Minute
    Second
    Date
    Interval
    To
    }

    impl Eq for Keyword
    impl Show for Keyword

    Lexer

    type Lexer

    Lexer::lex

    fn Lexer::lex(self : Lexer) -> Array[Token] raise LexerError

    Lexer::new

    fn Lexer::new(input : String) -> Lexer

    LexerError

    type LexerError

    impl Show for LexerError

    Literal

    pub(all) enum Literal {
    Integer(Int)
    Double(Double)
    String(String)
    Boolean(Bool)
    Null
    }

    impl Eq for Literal

    OrderByExpr

    pub struct OrderByExpr {
    expr : Expr
    asc : Bool?
    nulls_first : Bool?
    }

    impl Eq for OrderByExpr

    Parser

    pub struct Parser {
    input : Array[Token]
    offset : Int
    }

    ParserError

    type ParserError

    impl Show for ParserError

    PrimaryDatetimeField

    type PrimaryDatetimeField

    Projection

    pub(all) enum Projection {
    Wildcard
    UnamedExpr(Expr)
    AliasedExpr(Expr, String)
    }

    impl Eq for Projection

    SelectStmt

    pub struct SelectStmt {
    projections : Array[Projection]
    from : Array[TableRef]
    where_clause : Expr?
    group_by : Array[Expr]
    having : Expr?
    order_by : Array[OrderByExpr]
    limit : Int?
    offset : Int?
    }

    impl Eq for SelectStmt

    SqlParserError

    pub enum SqlParserError {
    LexerError(LexerError)
    ParserError(ParserError)
    }

    Statement

    pub(all) enum Statement {
    Select(SelectStmt)
    }

    impl Eq for Statement
    impl Show for Statement

    TableRef

    pub(all) enum TableRef {
    Table(String)
    TableAlias(String, String)
    SubQuery(SelectStmt, String)
    }

    impl Eq for TableRef

    Token

    pub(all) enum Token {
    Keyword(Keyword)
    Identifier(String)
    Number(String)
    StringLiteral(String)
    Comma
    Semicolon
    Eq
    DoubleEq
    Neq
    Lt
    Gt
    LtEq
    GtEq
    Spaceship
    Plus
    Minus
    Mul
    Div
    Mod
    LBracket
    RBracket
    LBrace
    RBrace
    LParen
    RParen
    Unknown(Char)
    Eof
    }

    impl Eq for Token
    impl Show for Token

    UnaryOperator

    pub(all) enum UnaryOperator {
    Negate
    Not
    }

    impl Eq for UnaryOperator

    parse_sql

    fn parse_sql(input : String) -> Statement raise SqlParserError

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io