-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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 |