rantlr-core 0.2.0

Rantlr core: .gr lexer, parser, linter, and in-process runtime
Documentation
// High-concurrency API Gateway DSL (Rails/Kong-style routing surface)
grammar ApiGateway;

token Id = Identifier;
token Num = Number;
token Str = QuotedString;
token Ws = " " -> skip;
token Tab = "\t" -> skip;
token Nl = "\n" -> skip;

rule gateway {
    "gateway"
    Id
    "{"
    repeat {
        route_block
    }
    "}"
}

rule route_block {
    "route"
    path
    "{"
    optional { methods_clause }
    optional { rate_limit }
    optional { balance_clause }
    optional { auth_chain }
    repeat {
        nested_resource
    }
    "}"
}

rule path {
    "/"
    path_segment
    repeat {
        "/"
        path_segment
    }
}

rule path_segment {
    match Id | param
}

rule param {
    ":"
    Id
}

rule methods_clause {
    "methods"
    Id
    repeat {
        Id
    }
}

rule rate_limit {
    "limit"
    Num
    "per"
    Id
}

rule balance_clause {
    "balance"
    match "RoundRobin" | "LeastConn"
}

rule auth_chain {
    "auth"
    Id
    repeat {
        Id
    }
}

rule nested_resource {
    "nested"
    Id
    "{"
    optional { constraint_clause }
    optional { methods_clause }
    optional { rate_limit }
    optional { balance_clause }
    optional { auth_chain }
    "}"
}

rule constraint_clause {
    "constraint"
    Str
}