Run the format tool.

This commit is contained in:
Danila Fedorin 2018-07-25 13:53:35 -07:00
parent fa00bda8ab
commit df2a00fd66
7 changed files with 570 additions and 551 deletions

View File

@ -1,10 +1,10 @@
require "./builder.cr" require "./builder.cr"
module Chalk module Chalk
abstract class BasicParser(T) abstract class BasicParser(T)
abstract def parse?(tokens : Array(Token), abstract def parse?(tokens : Array(Token),
index : Int64) : Tuple(T, Int64)? index : Int64) : Tuple(T, Int64)?
def parse(tokens : Array(Token), def parse(tokens : Array(Token),
index : Int64) : Tuple(T, Int64) index : Int64) : Tuple(T, Int64)
return parse?(tokens, index).not_nil! return parse?(tokens, index).not_nil!
@ -15,9 +15,7 @@ module Chalk
end end
def then(other : BasicParser(R)) : BasicParser(Array(T | R)) forall R def then(other : BasicParser(R)) : BasicParser(Array(T | R)) forall R
return NextParser return NextParser.new(self, other).as(BasicParser(Array(T | R)))
.new(self, other)
.as(BasicParser(Array(T | R)))
end end
end end

View File

@ -16,19 +16,25 @@ module Chalk
class TreeId < Tree class TreeId < Tree
property id : String property id : String
def initialize(@id : String) end
def initialize(@id : String)
end
end end
class TreeLit < Tree class TreeLit < Tree
property lit : Int64 property lit : Int64
def initialize(@lit : Int64) end
def initialize(@lit : Int64)
end
end end
class TreeCall < Tree class TreeCall < Tree
property name : String property name : String
property params : Array(Tree) property params : Array(Tree)
def initialize(@name : String, @params : Array(Tree)) end def initialize(@name : String, @params : Array(Tree))
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@params.each &.accept(v) @params.each &.accept(v)
@ -40,7 +46,9 @@ module Chalk
property op : TokenType property op : TokenType
property left : Tree property left : Tree
property right : Tree property right : Tree
def initialize(@op : TokenType, @left : Tree, @right : Tree) end
def initialize(@op : TokenType, @left : Tree, @right : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@ -51,7 +59,8 @@ module Chalk
end end
class TreeBlock < Tree class TreeBlock < Tree
def initialize(@children : Array(Tree)) end def initialize(@children : Array(Tree))
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@ -65,7 +74,9 @@ module Chalk
property params : Array(String) property params : Array(String)
property block : Tree property block : Tree
def initialize(@name : String, @params : Array(String), @block : Tree) end def initialize(@name : String, @params : Array(String), @block : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@block.accept(v) @block.accept(v)
@ -77,7 +88,9 @@ module Chalk
property name : String property name : String
property expr : Tree property expr : Tree
def initialize(@name : String, @expr : Tree) end def initialize(@name : String, @expr : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@expr.accept(v) @expr.accept(v)
@ -89,7 +102,9 @@ module Chalk
property name : String property name : String
property expr : Tree property expr : Tree
def initialize(@name : String, @expr : Tree) end def initialize(@name : String, @expr : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@expr.accept(v) @expr.accept(v)
@ -102,7 +117,9 @@ module Chalk
property block : Tree property block : Tree
property otherwise : Tree? property otherwise : Tree?
def initialize(@condition : Tree, @block : Tree, @otherwise : Tree? = nil) end def initialize(@condition : Tree, @block : Tree, @otherwise : Tree? = nil)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@condition.accept(v) @condition.accept(v)
@ -116,7 +133,9 @@ module Chalk
property condition : Tree property condition : Tree
property block : Tree property block : Tree
def initialize(@condition : Tree, @block : Tree) end def initialize(@condition : Tree, @block : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@condition.accept(v) @condition.accept(v)
@ -128,7 +147,9 @@ module Chalk
class TreeReturn < Tree class TreeReturn < Tree
property rvalue : Tree property rvalue : Tree
def initialize(@rvalue : Tree) end def initialize(@rvalue : Tree)
end
def accept(v : Visitor) def accept(v : Visitor)
v.visit(self) v.visit(self)
@rvalue.accept(v) @rvalue.accept(v)