Sign in

    sqlparser

    Extensible SQL Lexer and Parser in MoonBit

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

    #Extensible SQL Lexer and Parser for MoonBit

    BinaryOperator

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

    BinaryOperator::get_precedence

    fn BinaryOperator::get_precedence(self : BinaryOperator) -> Precedence

    CaseExpr

    pub struct CaseExpr {
    operand : Expr?
    when_then_clauses : Array[(Expr, Expr)]
    else_expr : Expr?
    }

    impl Eq for CaseExpr
    impl Show for CaseExpr

    DatetimeUnit

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

    impl Eq for DatetimeUnit

    Expr

    pub(all) enum Expr {
    Identifier(String)
    CompoundIdentifier(Array[String])
    Literal(Literal)
    BinaryOperation(Expr, BinaryOperator, Expr)
    UnaryOperation(UnaryOperator, Expr)
    FunctionCall(String, Array[Expr])
    Wildcard
    Datetime(String)
    Interval(String, IntervalQualifier)
    Like(Bool, Expr, Expr)
    ILike(Bool, Expr, Expr)
    SubQuery(SelectStmt)
    Exists(Bool, SelectStmt)
    Between(Bool, Expr, Expr, Expr)
    Extract(PrimaryDatetimeField, Expr)
    Case(CaseExpr)
    }

    impl Eq for Expr
    impl Show 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
    Like
    Not
    ILike
    Exists
    Between
    And
    Or
    Extract
    Case
    When
    Then
    Else
    Having
    End
    }

    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
    impl Show for Literal

    OrderByExpr

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

    impl Eq for OrderByExpr
    impl Show for OrderByExpr

    Parser

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

    ParserError

    type ParserError

    impl Show for ParserError

    Precedence

    pub(all) enum Precedence {
    PlusMinus
    MulDivMod
    Eq
    Like
    And
    Or
    Between
    }

    Precedence::value

    fn Precedence::value(self : Precedence) -> Int

    PrimaryDatetimeField

    type PrimaryDatetimeField

    Projection

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

    impl Eq for Projection
    impl Show 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
    impl Show 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, String?)
    SubQuery(SelectStmt, String?)
    }

    impl Eq for TableRef
    impl Show 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
    Period
    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