Skip to content

Instantly share code, notes, and snippets.

@dorianmariefr
Last active June 4, 2022 21:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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
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
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