Kumi::Parser
Text parser for Kumi schemas. Direct tokenizer → AST construction with ~4ms parse time.
Installation
gem 'kumi-parser'
Usage
require 'kumi/parser'
schema = <<~KUMI
schema do
input do
float :income
string :status
end
trait :adult, input.age >= 18
value :tax, fn(:calculate_tax, input.income)
end
KUMI
# Parse to AST
ast = Kumi::Parser::TextParser.parse(schema)
# Validate
Kumi::Parser::TextParser.valid?(schema) # => true
API
-
parse(text)
→ AST -
valid?(text)
→ Boolean -
validate(text)
→ Array of error hashes
Syntax
schema do
input do
<type> :<name>[, domain: <spec>]
end
trait :<name>, <expression>
value :<name>, <expression>
value :<name> do
on <condition>, <result>
base <result>
end
end
Function calls: fn(:name, arg1, arg2, ...)
Operators: +
-
*
/
%
>
<
>=
<=
==
!=
&
|
References: input.field
, value_name
, array[index]
Architecture
-
smart_tokenizer.rb
- Context-aware tokenization with embedded metadata -
direct_ast_parser.rb
- Recursive descent parser, direct AST construction -
token_metadata.rb
- Token types, precedence, and semantic hints
See docs/
for technical details.
License
MIT