mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
This commit is contained in:
parent
2e27c5d9c3
commit
d076252dff
6 changed files with 74 additions and 104 deletions
|
@ -18,6 +18,8 @@ namespace YAML
|
||||||
class RequiredSimpleKeyNotFound: public Exception {};
|
class RequiredSimpleKeyNotFound: public Exception {};
|
||||||
class ZeroIndentationInBlockScalar: public Exception {};
|
class ZeroIndentationInBlockScalar: public Exception {};
|
||||||
class UnexpectedCharacterInBlockScalar: public Exception {};
|
class UnexpectedCharacterInBlockScalar: public Exception {};
|
||||||
|
class AnchorNotFound: public Exception {};
|
||||||
|
class IllegalCharacterInAnchor: public Exception {};
|
||||||
|
|
||||||
class UnknownEscapeSequence: public Exception {
|
class UnknownEscapeSequence: public Exception {
|
||||||
public:
|
public:
|
||||||
|
|
3
exp.h
3
exp.h
|
@ -16,6 +16,8 @@ namespace YAML
|
||||||
const RegEx Break = RegEx('\n');
|
const RegEx Break = RegEx('\n');
|
||||||
const RegEx BlankOrBreak = Blank || Break;
|
const RegEx BlankOrBreak = Blank || Break;
|
||||||
const RegEx Digit = RegEx('0', '9');
|
const RegEx Digit = RegEx('0', '9');
|
||||||
|
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
||||||
|
const RegEx AlphaNumeric = Alpha || Digit;
|
||||||
const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
|
const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
|
||||||
|
|
||||||
// actual tags
|
// actual tags
|
||||||
|
@ -28,6 +30,7 @@ namespace YAML
|
||||||
const RegEx Value = RegEx(':'),
|
const RegEx Value = RegEx(':'),
|
||||||
ValueInFlow = RegEx(':') + BlankOrBreak;
|
ValueInFlow = RegEx(':') + BlankOrBreak;
|
||||||
const RegEx Comment = RegEx('#');
|
const RegEx Comment = RegEx('#');
|
||||||
|
const RegEx AnchorEnd = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak;
|
||||||
|
|
||||||
// Plain scalar rules:
|
// Plain scalar rules:
|
||||||
// . Cannot start with a blank.
|
// . Cannot start with a blank.
|
||||||
|
|
27
scanner.cpp
27
scanner.cpp
|
@ -148,9 +148,9 @@ namespace YAML
|
||||||
m_limboTokens.erase(pToken);
|
m_limboTokens.erase(pToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
// ScanNextToken
|
||||||
// The main scanning function
|
// . The main scanning function; here we branch out and
|
||||||
|
// scan whatever the next token should be.
|
||||||
void Scanner::ScanNextToken()
|
void Scanner::ScanNextToken()
|
||||||
{
|
{
|
||||||
if(m_endedStream)
|
if(m_endedStream)
|
||||||
|
@ -159,21 +159,31 @@ namespace YAML
|
||||||
if(!m_startedStream)
|
if(!m_startedStream)
|
||||||
return ScanAndEnqueue(new StreamStartToken);
|
return ScanAndEnqueue(new StreamStartToken);
|
||||||
|
|
||||||
|
// get rid of whitespace, etc. (in between tokens it should be irrelevent)
|
||||||
ScanToNextToken();
|
ScanToNextToken();
|
||||||
|
|
||||||
|
// check the latest simple key
|
||||||
ValidateSimpleKey();
|
ValidateSimpleKey();
|
||||||
|
|
||||||
|
// maybe need to end some blocks
|
||||||
PopIndentTo(m_column);
|
PopIndentTo(m_column);
|
||||||
|
|
||||||
|
// *****
|
||||||
|
// And now branch based on the next few characters!
|
||||||
|
// *****
|
||||||
|
|
||||||
|
// end of stream
|
||||||
if(INPUT.peek() == EOF)
|
if(INPUT.peek() == EOF)
|
||||||
return ScanAndEnqueue(new StreamEndToken);
|
return ScanAndEnqueue(new StreamEndToken);
|
||||||
|
|
||||||
// are we at a document token?
|
// document token
|
||||||
if(IsDocumentStart())
|
if(IsDocumentStart())
|
||||||
return ScanAndEnqueue(new DocumentStartToken);
|
return ScanAndEnqueue(new DocumentStartToken);
|
||||||
|
|
||||||
if(IsDocumentEnd())
|
if(IsDocumentEnd())
|
||||||
return ScanAndEnqueue(new DocumentEndToken);
|
return ScanAndEnqueue(new DocumentEndToken);
|
||||||
|
|
||||||
// are we at a flow start/end/entry?
|
// flow start/end/entry
|
||||||
if(INPUT.peek() == Keys::FlowSeqStart)
|
if(INPUT.peek() == Keys::FlowSeqStart)
|
||||||
return ScanAndEnqueue(new FlowSeqStartToken);
|
return ScanAndEnqueue(new FlowSeqStartToken);
|
||||||
|
|
||||||
|
@ -189,7 +199,7 @@ namespace YAML
|
||||||
if(INPUT.peek() == Keys::FlowEntry)
|
if(INPUT.peek() == Keys::FlowEntry)
|
||||||
return ScanAndEnqueue(new FlowEntryToken);
|
return ScanAndEnqueue(new FlowEntryToken);
|
||||||
|
|
||||||
// block/map stuff?
|
// block/map stuff
|
||||||
if(IsBlockEntry())
|
if(IsBlockEntry())
|
||||||
return ScanAndEnqueue(new BlockEntryToken);
|
return ScanAndEnqueue(new BlockEntryToken);
|
||||||
|
|
||||||
|
@ -199,7 +209,10 @@ namespace YAML
|
||||||
if(IsValue())
|
if(IsValue())
|
||||||
return ScanAndEnqueue(new ValueToken);
|
return ScanAndEnqueue(new ValueToken);
|
||||||
|
|
||||||
// TODO: alias/anchor/tag
|
if(INPUT.peek() == Keys::Alias || INPUT.peek() == Keys::Anchor)
|
||||||
|
return ScanAndEnqueue(new AnchorToken);
|
||||||
|
|
||||||
|
// TODO: tag
|
||||||
|
|
||||||
// special scalars
|
// special scalars
|
||||||
if(m_flowLevel == 0 && (INPUT.peek() == Keys::LiteralScalar || INPUT.peek() == Keys::FoldedScalar))
|
if(m_flowLevel == 0 && (INPUT.peek() == Keys::LiteralScalar || INPUT.peek() == Keys::FoldedScalar))
|
||||||
|
|
|
@ -191,6 +191,36 @@ namespace YAML
|
||||||
return pToken;
|
return pToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AnchorToken
|
||||||
|
template <> AnchorToken *Scanner::ScanToken(AnchorToken *pToken)
|
||||||
|
{
|
||||||
|
// insert a potential simple key
|
||||||
|
if(m_simpleKeyAllowed)
|
||||||
|
InsertSimpleKey();
|
||||||
|
m_simpleKeyAllowed = false;
|
||||||
|
|
||||||
|
// eat the indicator
|
||||||
|
char indicator = GetChar();
|
||||||
|
pToken->alias = (indicator == Keys::Alias);
|
||||||
|
|
||||||
|
// now eat the content
|
||||||
|
std::string tag;
|
||||||
|
while(Exp::AlphaNumeric.Matches(INPUT))
|
||||||
|
tag += GetChar();
|
||||||
|
|
||||||
|
// we need to have read SOMETHING!
|
||||||
|
if(tag.empty())
|
||||||
|
throw AnchorNotFound();
|
||||||
|
|
||||||
|
// and needs to end correctly
|
||||||
|
if(INPUT.peek() != EOF && !Exp::AnchorEnd.Matches(INPUT))
|
||||||
|
throw IllegalCharacterInAnchor();
|
||||||
|
|
||||||
|
// and we're done
|
||||||
|
pToken->value = tag;
|
||||||
|
return pToken;
|
||||||
|
}
|
||||||
|
|
||||||
// PlainScalarToken
|
// PlainScalarToken
|
||||||
// . We scan these in passes of two steps each: First, grab all non-whitespace
|
// . We scan these in passes of two steps each: First, grab all non-whitespace
|
||||||
// characters we can, and then grab all whitespace characters we can.
|
// characters we can, and then grab all whitespace characters we can.
|
||||||
|
|
110
test.yaml
110
test.yaml
|
@ -1,97 +1,13 @@
|
||||||
---
|
people:
|
||||||
model:
|
- &jsb
|
||||||
file: data/models/compound.model
|
name: Jesse
|
||||||
textures: data/materials/compound
|
age: 23
|
||||||
rooms:
|
- &dab
|
||||||
- name: "Room #1"
|
name: Daniel
|
||||||
pos: [0, 0, 0]
|
age: 25
|
||||||
size: [1000, 1000, 500]
|
- &ncb
|
||||||
height: 500
|
name: Naftali
|
||||||
stairtype: none
|
age: 21
|
||||||
display: []
|
students:
|
||||||
pathfinding:
|
- *jsb
|
||||||
tilesize: 50
|
- *ncb
|
||||||
size: [24, 24]
|
|
||||||
map: |
|
|
||||||
-----------------------
|
|
||||||
-+++++++++++++++++++++-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+---------------------
|
|
||||||
-+---------------------
|
|
||||||
-+---------------------
|
|
||||||
-+---------------------
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+++++++++++++++++++++-
|
|
||||||
-----------------------
|
|
||||||
- name: Doorway
|
|
||||||
pos: [1000, 400, 0]
|
|
||||||
size: [50, 200, 500]
|
|
||||||
height: 500
|
|
||||||
stairtype: none
|
|
||||||
display: []
|
|
||||||
pathfinding:
|
|
||||||
tilesize: 50
|
|
||||||
size: [5, 9]
|
|
||||||
map: |
|
|
||||||
-----
|
|
||||||
-+++-
|
|
||||||
-----
|
|
||||||
-----
|
|
||||||
-----
|
|
||||||
-----
|
|
||||||
-----
|
|
||||||
-+++-
|
|
||||||
-----
|
|
||||||
- name: "Room #2"
|
|
||||||
pos: [1050, 0, 0]
|
|
||||||
size: [1000, 1000, 500]
|
|
||||||
height: 500
|
|
||||||
stairtype: none
|
|
||||||
display: []
|
|
||||||
pathfinding:
|
|
||||||
tilesize: 50
|
|
||||||
size: [24, 24]
|
|
||||||
map: |
|
|
||||||
-----------------------
|
|
||||||
-+++++++++++++++++++++-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
---------------------+-
|
|
||||||
---------------------+-
|
|
||||||
---------------------+-
|
|
||||||
---------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+-------------------+-
|
|
||||||
-+++++++++++++++++++++-
|
|
||||||
-----------------------
|
|
||||||
exits:
|
|
||||||
- room1: "Room #1"
|
|
||||||
room2: "Room #2"
|
|
||||||
dir: e
|
|
||||||
pos: [400, 600]
|
|
6
token.h
6
token.h
|
@ -31,6 +31,12 @@ namespace YAML
|
||||||
|
|
||||||
struct KeyToken: public Token {};
|
struct KeyToken: public Token {};
|
||||||
struct ValueToken: public Token {};
|
struct ValueToken: public Token {};
|
||||||
|
struct AnchorToken: public Token {
|
||||||
|
bool alias;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
virtual void Write(std::ostream& out) const { out << (alias ? '*' : '&') << value; }
|
||||||
|
};
|
||||||
|
|
||||||
struct ScalarToken: public Token {
|
struct ScalarToken: public Token {
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue