Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
754c38e8
Commit
754c38e8
authored
Feb 27, 2015
by
Aaron Burghardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved buffer management into the lexer class and implemented YYFILL so that…
Moved buffer management into the lexer class and implemented YYFILL so that streams are read incrementally.
parent
5526de13
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
17 deletions
+51
-17
json.hpp.re2c
src/json.hpp.re2c
+51
-17
No files found.
src/json.hpp.re2c
View file @
754c38e8
...
...
@@ -3046,11 +3046,20 @@ class basic_json
using lexer_char_t = unsigned char;
/// constructor with a given buffer
inline lexer(const string_t& s) noexcept
: m_content(reinterpret_cast<const lexer_char_t*>(s.c_str()))
{
inline lexer(const string_t& s) noexcept
: m_buffer(s), m_stream(nullptr)
{
m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
m_start = m_cursor = m_content;
m_limit = m_content + s.size();
}
inline lexer(std::istream* s) noexcept
: m_stream(s)
{
getline(*m_stream, m_buffer);
m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
m_start = m_cursor = m_content;
m_limit = m_content +
s
.size();
m_limit = m_content +
m_buffer
.size();
}
/// default constructor
...
...
@@ -3182,6 +3191,8 @@ class basic_json
// remember the begin of the token
m_start = m_cursor;
#define YYFILL(n) { size_t offset_marker = m_marker - m_start; yyfill(n); m_marker = m_start + offset_marker; }
/*!re2c
re2c:define:YYCTYPE = lexer_char_t;
re2c:define:YYCURSOR = m_cursor;
...
...
@@ -3190,7 +3201,6 @@ class basic_json
re2c:indent:string = " ";
re2c:indent:top = 1;
re2c:labelprefix = "basic_json_parser_";
re2c:yyfill:enable = 0;
// whitespace
ws = [ \t\n\r]+;
...
...
@@ -3240,8 +3250,28 @@ class basic_json
// anything else is an error
. { return token_type::parse_error; }
*/
}
void yyfill(int n) noexcept
{
if (not m_stream or not *m_stream) return;
ssize_t offset_start = m_start - m_content;
ssize_t offset_cursor = m_cursor - m_start;
ssize_t offset_limit = m_limit - m_start;
m_buffer.erase(0, offset_start);
std::string line;
std::getline(*m_stream, line);
m_buffer += line;
m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str()); //reinterpret_cast<lexer_char_t*>(endptr)
m_start = m_content + offset_start;
m_cursor = m_start + offset_cursor;
m_limit = m_start + offset_limit;
}
/// return string representation of last read token
inline string_t get_token() const noexcept
{
...
...
@@ -3404,14 +3434,20 @@ class basic_json
}
private:
/// optional input stream
std::istream* m_stream;
/// the buffer
string_t m_buffer;
/// the buffer pointer
const lexer_char_t* m_content = nullptr;
/// pointer to he beginning of the current symbol
/// pointer to
t
he beginning of the current symbol
const lexer_char_t* m_start = nullptr;
/// pointer to the current symbol
const lexer_char_t* m_cursor = nullptr;
/// pointer to the end of the buffer
const lexer_char_t* m_limit = nullptr;
/// YYSTATE
int m_state;
};
/*!
...
...
@@ -3421,24 +3457,24 @@ class basic_json
{
public:
/// constructor for strings
inline parser(const string_t& s) : m_buffer(s), m_lexer(m_buffer
)
inline parser(const string_t& s) : m_lexer(s
)
{
// read first token
get_token();
}
/// a parser reading from an input stream
inline parser(std::istream&
_is)
inline parser(std::istream& _is) : m_lexer(&
_is)
{
while (_is)
{
string_t input_line;
std::getline(_is, input_line);
m_buffer += input_line;
}
//
while (_is)
//
{
//
string_t input_line;
//
std::getline(_is, input_line);
//
m_buffer += input_line;
//
}
// initializer lexer
m_lexer = lexer(m_buffer
);
// m_lexer = std::move(lexer(_is)
);
// read first token
get_token();
...
...
@@ -3625,8 +3661,6 @@ class basic_json
}
private:
/// the buffer
string_t m_buffer;
/// the type of the last read token
typename lexer::token_type last_token = lexer::token_type::uninitialized;
/// the lexer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment