41 std::string BoolLiteral::str()
const
43 return (value() ?
"true" :
"false");
49 << Bytestream::Literal << str()
53 void BoolLiteral::Accept(
Visitor& v)
const { v.Enter(*
this); v.Leave(*
this); }
55 dag::ValuePtr BoolLiteral::evaluate(
EvalContext&)
const
57 return dag::ValuePtr(
new dag::Boolean(value(), type(), source()));
61 std::string IntLiteral::str()
const
63 return std::to_string(value());
68 out << Bytestream::Literal << value() << Bytestream::Reset;
71 void IntLiteral::Accept(
Visitor& v)
const { v.Enter(*
this); v.Leave(*
this); }
73 dag::ValuePtr IntLiteral::evaluate(
EvalContext&)
const
75 return dag::ValuePtr(
new dag::Integer(value(), type(), source()));
79 std::string StringLiteral::str()
const {
return value(); }
83 out << Bytestream::Literal <<
"'";
85 std::string s = value();
90 size_t dollarSign = s.find(
"$", i);
91 out << s.substr(i, dollarSign - i);
93 if (dollarSign == std::string::npos)
97 if (s[dollarSign + 1] ==
'{')
98 end = s.find(
"}", dollarSign + 1) + 1;
102 s.find(
" ", dollarSign + 1),
103 s.find(
".", dollarSign + 1)
107 << Bytestream::Reference
108 << s.substr(dollarSign, end - dollarSign)
109 << Bytestream::Literal
114 }
while (i < s.length());
116 out <<
"'" << Bytestream::Reset;
119 void StringLiteral::Accept(
Visitor& v)
const { v.Enter(*
this); v.Leave(*
this); }
121 dag::ValuePtr StringLiteral::evaluate(
EvalContext&)
const
123 return dag::ValuePtr(
new dag::String(value(), type(), source()));
An integer (of unspecified precision).
virtual void PrettyPrint(Bytestream &, size_t indent=0) const override
Print a human-readable representation to an output stream and return that output stream.
virtual void PrettyPrint(Bytestream &, size_t indent=0) const override
Print a human-readable representation to an output stream and return that output stream.
Representation of the Abstract Syntax Tree for Fabrique source code.
An ASCII string (for now, we should make this Unicode soon).
Declaration of several literal expression types.
Declaration of fabrique::dag::Primitive.
virtual void PrettyPrint(Bytestream &, size_t indent=0) const override
Print a human-readable representation to an output stream and return that output stream.
A ostream-like class that may support formatting.
Declaration of fabrique::ast::Visitor.
A context for evaluating AST Expression objects.
Declaration of fabrique::Bytestream.
Interface for visitors that walk the AST.
A boolean (true/false) value.