syntaks
Version, currently 0.0.513 versions
- 0.3.2latestMay 4, 2021
- 0.3.1not indexedMay 4, 2021
- 0.3.0not indexedMay 4, 2021
- 0.2.0not indexedMay 4, 2021
- 0.1.0not indexedMay 4, 2021
- 0.0.9not indexedMay 4, 2021
- 0.0.8not indexedMay 4, 2021
- 0.0.7not indexedMay 4, 2021
- 0.0.6not indexedMay 4, 2021
- 0.0.5not indexedMay 4, 2021
- 0.0.4not indexedMay 4, 2021
- 0.0.3not indexedMay 4, 2021
- 0.0.2not indexedMay 4, 2021
github.com/Ragmaanir/syntaks
Parser combinators for crystal
Nothing has been indexed for 0.0.5 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
syntaks:
github: Ragmaanir/syntaks
version: ~> 0.0.5Then run:
shards installshard.yml
No shard.yml has been indexed for 0.0.5. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
syntaks 
Version 0.3.2
A parser combinator framework.
Usage
require "syntaks"
Example
class ListParser < Syntaks::Parser
rule(:root, Array(String), _os >> "(" >> _os & item_list & ")") { |v| v[3] }
rule(:item_list, Array(String), item >> ~item_list_tail) do |v|
if tail = v[1]
[v[0]] + tail
else
[v[0]]
end
end
rule(:item_list_tail, Array(String), {"," & _os & item >> _os}) do |list|
list.map(&.[2])
end
rule(:item, String, id >> _os) do |t|
t[0]
end
rule(:id, String, /[_a-z][_a-z0-9]*/, &.content)
ignored(:_os, /\s*/)
end
res = ListParser.new.call("(v1,v2)").as(Success)
assert res.value == ["v1", "v2"]
Usage
Rules are specified in a format similar to EBNF:
# literals/tokens
ignored(:space, /\s+/) # generates nil as AST-node
rule(:int, String, /[1-9][0-9]*/) { |m| m.content } # generates String as AST-node
# sequence
rule(:root, String, "var " >> id) { |m| m[1] } # use the second match (id) as AST-node
# sequence with backtracking disabled
rule(:root, String, "var " & id) { |m| m[1] }
# alternatives
rule(:root, String, a | b)
# repetition
rule(:root, Array(Int32), {"," >> int}) { |m| m.map(&.[1]) }
When backtracking is disabled an parsing fails, a syntax error is produced:
class ErrorParser < Syntaks::Parser
rule(:root, String, "var" >> space & /[a-z]+/) { |m| m[2].content }
ignored(:space, /\s+/)
end
res = ErrorParser.new.call("var 1337").as(Error)
assert res.message == <<-MSG
Syntax error at 1:9:
1>var 1337
----------^
Rule: "var" >> space & /[a-z]+/
MSG
A parse log can be printed to inspect the parsing process:
source = <<-SRC
def main
if true
x = 1
⬤
end
end
SRC
ctx = LoggingContext.new(ParseLog.new(Source.new(source)))
res = ExampleParsers::MethodParser.new.call(source, ctx).as(Error)
log = ctx.parse_log.to_s
# The syntax error entry marked with ⚡ should be on the line that contains ⬤
assert(/⚡[^\n]+(29-33)[^\n]+⬤/ === log)
TODO
- simple token macro
- rules that do not generate ast nodes
- error-recovery productions / synchronization tokens
- optional whitespace skippers
- Simple lexer?
- Packrat parsing / memoization
- remember longest parsed prefix when parsing fails
DONE
- Use ameba
- Generated
README.mdwith examples - LoggingContext with a ParseLog
- ProfilingContext
- EBNF DSL
- Selectively disable backtracking
- Detailed syntax errors: display production that failed and the location where exactly it failed
Contributing
- Fork it ( https://github.com/ragmaanir/syntaks/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Ragmaanir - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.0.5- Tagged
- May 4, 2021
- Commit
746f6baae546- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/Ragmaanir/syntaks
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 13