|
|
@ -73,6 +73,9 @@ ASTNode* Reader::readImpl() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (peek().type) { |
|
|
|
switch (peek().type) { |
|
|
|
|
|
|
|
case Token::Type::Special: // ~@
|
|
|
|
|
|
|
|
return readSpliceUnquote(); |
|
|
|
|
|
|
|
break; |
|
|
|
case Token::Type::ParenOpen: // (
|
|
|
|
case Token::Type::ParenOpen: // (
|
|
|
|
return readList(); |
|
|
|
return readList(); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -81,6 +84,15 @@ ASTNode* Reader::readImpl() |
|
|
|
m_error_character = ')'; |
|
|
|
m_error_character = ')'; |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case Token::Type::Quote: // '
|
|
|
|
|
|
|
|
return readQuote(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Token::Type::Backtick: // `
|
|
|
|
|
|
|
|
return readQuasiQuote(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Token::Type::Tilde: // ~
|
|
|
|
|
|
|
|
return readUnquote(); |
|
|
|
|
|
|
|
break; |
|
|
|
case Token::Type::String: |
|
|
|
case Token::Type::String: |
|
|
|
return readString(); |
|
|
|
return readString(); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -88,10 +100,28 @@ ASTNode* Reader::readImpl() |
|
|
|
return readValue(); |
|
|
|
return readValue(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
// Unimplemented token
|
|
|
|
break; |
|
|
|
VERIFY_NOT_REACHED(); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unimplemented token
|
|
|
|
|
|
|
|
VERIFY_NOT_REACHED(); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readSpliceUnquote() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ignore(); // ~@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEOF()) { |
|
|
|
|
|
|
|
Error::the().addError("expected form, got EOF"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List* list = new List(); |
|
|
|
|
|
|
|
list->addNode(new Symbol("splice-unquote")); |
|
|
|
|
|
|
|
list->addNode(readImpl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readList() |
|
|
|
ASTNode* Reader::readList() |
|
|
@ -111,6 +141,54 @@ ASTNode* Reader::readList() |
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readQuote() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ignore(); // '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEOF()) { |
|
|
|
|
|
|
|
Error::the().addError("expected form, got EOF"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List* list = new List(); |
|
|
|
|
|
|
|
list->addNode(new Symbol("quote")); |
|
|
|
|
|
|
|
list->addNode(readImpl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readQuasiQuote() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ignore(); // `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEOF()) { |
|
|
|
|
|
|
|
Error::the().addError("expected form, got EOF"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List* list = new List(); |
|
|
|
|
|
|
|
list->addNode(new Symbol("quasiquote")); |
|
|
|
|
|
|
|
list->addNode(readImpl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readUnquote() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ignore(); // ~
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEOF()) { |
|
|
|
|
|
|
|
Error::the().addError("expected form, got EOF"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List* list = new List(); |
|
|
|
|
|
|
|
list->addNode(new Symbol("unquote")); |
|
|
|
|
|
|
|
list->addNode(readImpl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ASTNode* Reader::readString() |
|
|
|
ASTNode* Reader::readString() |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string symbol = consume().symbol; |
|
|
|
std::string symbol = consume().symbol; |
|
|
|