This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error in line 1 | |
Error: while requiring "./spec/language_spec.cr" | |
In spec/language_spec.cr:5:25 | |
5 | language = Language.create do | |
^----- | |
Error: instantiating 'Language.class#create()' | |
In spec/language_spec.cr:5:25 | |
5 | language = Language.create do | |
^----- | |
Error: instantiating 'Language.class#create()' | |
In spec/language_spec.cr:7:9 | |
7 | any.repeat.in(:text) | |
^-- | |
Error: undefined local variable or method 'any' for top-level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./language/*" | |
class Language | |
VERSION = "0.1.0" | |
def initialize | |
@rules = [] of Definition | |
end | |
def self.create(&block) | |
instance = new | |
with instance yield | |
instance | |
end | |
def parse(input) | |
input | |
end | |
def root(&block) | |
rule(:root, &block) | |
end | |
def rule(name, &block) | |
definition = Definition.new | |
with definition yield | |
definition | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./spec_helper" | |
describe Language do | |
context "text" do | |
language = Language.create do | |
root do | |
any.repeat.in(:text) | |
end | |
end | |
it "parses" do | |
language.parse("Hello World").should eq({ text: "Hello World" }) | |
end | |
end | |
context "nothing" do | |
language = Language.create do | |
root do | |
str("nothing").in(:nothing) | |
end | |
end | |
it %(parses "nothing") do | |
language.parse("nothing").should eq({ nothing: "nothing" }) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment