-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoken.cpp
More file actions
36 lines (30 loc) · 1.24 KB
/
token.cpp
File metadata and controls
36 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "token.h"
#include <iostream>
#include <boost/optional/optional_io.hpp>
namespace pyjamas
{
std::ostream& operator<<( std::ostream& os, const Token& tok )
{
switch (tok.type)
{
case TokenType::Invalid: return os << "Invalid \"" << tok.text << '"';
case TokenType::Null: return os << "Null";
case TokenType::True: return os << "True";
case TokenType::False: return os << "False";
case TokenType::String: return os << "String \"" << *tok.text << '"';
case TokenType::ArrayBegin: return os << "ArrayBegin";
case TokenType::ArrayEnd: return os << "ArrayEnd";
case TokenType::ObjectBegin: return os << "ObjectBegin";
case TokenType::ObjectEnd: return os << "ObjectEnd";
case TokenType::ItemSeparator: return os << "ItemSeparator";
case TokenType::KeyValueSeparator: return os << "KeyValueSeparator";
default: return os << "<- ERROR: unknown token type (" << static_cast<int>(tok.type) << ") ->";
}
}
bool operator==( const Token& a, const Token& b )
{
return
a.type == b.type &&
a.text == b.text;
}
}