jarhart / rattler Goto Github PK
View Code? Open in Web Editor NEWRuby Tool for Language Recognition
License: MIT License
Ruby Tool for Language Recognition
License: MIT License
Take this grammar:
require 'rattler'
parser DynagramParser < Rattler::Runtime::ExtendedPackratParser
%whitespace SPACE+
script <- string EOF
string <- @('"' . '"')
Feed it the file
"x"
and you get:
[~/.p/d/ruby] ruby lib/dynagram/bug.rb samples/boxes.dyna
"\"x\""
(which is correct).
Change the input to:
"∆"
and when you run it, you get:
[~/.p/d/ruby] ruby lib/dynagram/bug.rb samples/boxes.dyna
"\"∆\"\n"
It looks as if somewhere the parser is using the byte length of the match, not the character length. I spent an hour or so poking around, but couldn't see where.
Thanks for a great tool.
I'm trying to add comments to my language. So I added a %whitespace
directive, similar to the JSON and INI examples. But when my source code starts with a comment, the parser always reports a syntax error, expecting the source code to end with a comment — even if it does end with a comment.
My RTLR file looks something like this:
%start program
%whitespace ( SPACE+ / comment )*
program <- expression+ EOF <AST::Program.new>
expression <- literal_integer
literal_integer <- @DIGIT+ <AST::LiteralInteger.new>
comment <- ~([#] [^\n]*)
If I try to parse this:
# Comment
123
then I get an error like this:
bundler/gems/rattler-5b3806afad53/lib/rattler/runtime/parser.rb:179:in `raise_error': parse error at line 3, column 1: (Rattler::Runtime::SyntaxError)
comment expected
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.