Skip to content

Commit

Permalink
Adding a dict ast node
Browse files Browse the repository at this point in the history
  • Loading branch information
freyamade committed Feb 28, 2019
1 parent 1c0e2a2 commit 1ebb973
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/drizzle/ast/dict_literal.cr
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
require "./expression"
require "../token"

module Drizzle
module AST
# Node class for handling dict literals
class DictLiteral < Expression
@token : Token
@pairs : Hash(Expression, Expression)

def initialize(@token : Token, @pairs : Hash(Expression, Expression))
end

def literal : String
return @token.literal
end

def to_s : String
pairs = [] of String
@pairs.each do |k, v|
pairs << "#{k}: #{v}"
end

return "{#{pairs.join ", "}}"
end

# The token that caused the creation of this node instance
getter token

# The hash of elements in the dictionary
getter pairs
end
end
end

0 comments on commit 1ebb973

Please sign in to comment.