Sign in

    sqlparser

    Extensible SQL Lexer and Parser in MoonBit

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

    #Extensible SQL Lexer and Parser for MoonBit

    BinaryOperator

    pub 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 enum DatetimeUnit {
    Year
    Month
    Day
    Hour
    Minute
    Second
    }

    impl Eq for DatetimeUnit

    Expr

    pub 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)
    InList(Bool, Expr, Array[Expr])
    InSubQuery(Bool, Expr, SelectStmt)
    }

    impl Eq for Expr
    impl Show for Expr

    IntervalQualifier

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

    Join

    pub struct Join {
    table_ref : TableRef
    join_operator : JoinOperator
    }

    impl Eq for Join
    impl Show for Join

    JoinConstraint

    pub enum JoinConstraint {
    On(Expr)
    Using(Array[String])
    None
    }

    JoinOperator

    pub enum JoinOperator {
    Join(JoinConstraint)
    Left(JoinConstraint)
    LeftOuter(JoinConstraint)
    Right(JoinConstraint)
    RightOuter(JoinConstraint)
    Full(JoinConstraint)
    FullOuter(JoinConstraint)
    Inner(JoinConstraint)
    Cross
    }

    impl Eq for JoinOperator

    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
    In
    Join
    Left
    Right
    Full
    Outer
    Inner
    Cross
    On
    Using
    }

    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 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
    }

    Parser::parse

    fn Parser::parse(self : Parser) -> Statement raise ParserError

    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 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 enum Statement {
    Select(SelectStmt)
    }

    impl Eq for Statement
    impl Show for Statement

    TableAlias

    pub struct TableAlias {
    name : String
    columns : Array[String]
    }

    impl Eq for TableAlias
    impl Show for TableAlias

    TableFactor

    pub enum TableFactor {
    Column(String, TableAlias?)
    SubQuery(SelectStmt, TableAlias?)
    }

    impl Eq for TableFactor
    impl Show for TableFactor

    TableRef

    pub struct TableRef {
    factor : TableFactor
    joins : Array[Join]
    }

    impl Eq for TableRef
    impl Show for TableRef

    Token

    pub(all) enum Token {
    Keyword(Keyword)
    Identifier(String)
    Number(String)
    StringLiteral(String)
    Boolean(Bool)
    Null
    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 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