Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
98ff7943
Unverified
Commit
98ff7943
authored
Aug 02, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backup
parent
24fa80ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
93 deletions
+79
-93
include/cif++/v2/file.hpp
+1
-1
include/cif++/v2/parser.hpp
+77
-92
include/cif++/v2/row.hpp
+1
-0
No files found.
include/cif++/v2/file.hpp
View file @
98ff7943
...
...
@@ -139,7 +139,7 @@ class file_t
// setValidator(nullptr);
parser_type
p
(
is
,
*
this
);
p
.
parse
F
ile
();
p
.
parse
_f
ile
();
// if (saved != nullptr)
// {
...
...
include/cif++/v2/parser.hpp
View file @
98ff7943
...
...
@@ -48,16 +48,16 @@ class parse_error : public std::runtime_error
class
sac_parser
{
public
:
using
DatablockI
ndex
=
std
::
map
<
std
::
string
,
std
::
size_t
>
;
using
datablock_i
ndex
=
std
::
map
<
std
::
string
,
std
::
size_t
>
;
sac_parser
(
std
::
istream
&
is
)
:
m
Data
(
is
)
sac_parser
(
std
::
istream
&
is
,
bool
init
=
true
)
:
m
_source
(
is
)
{
m_validate
=
true
;
m_line_nr
=
1
;
m_bol
=
true
;
//
if (init)
if
(
init
)
m_lookahead
=
get_next_token
();
}
...
...
@@ -157,6 +157,7 @@ class sac_parser
case
CIFToken
:
:
STOP
:
return
"STOP"
;
case
CIFToken
:
:
Tag
:
return
"Tag"
;
case
CIFToken
:
:
Value
:
return
"Value"
;
default:
return
"Invalid token parameter"
;
}
}
...
...
@@ -182,41 +183,42 @@ class sac_parser
case
CIFValue
:
:
TextField
:
return
"TextField"
;
case
CIFValue
:
:
Inapplicable
:
return
"Inapplicable"
;
case
CIFValue
:
:
Unknown
:
return
"Unknown"
;
default:
return
"Invalid type parameter"
;
}
}
// get
NextC
har takes a char from the buffer, or if it is empty
// get
_next_c
har takes a char from the buffer, or if it is empty
// from the istream. This function also does carriage/linefeed
// translation.
int
get
NextC
har
()
int
get
_next_c
har
()
{
int
result
;
if
(
m
B
uffer
.
empty
())
result
=
m
Data
.
get
();
if
(
m
_b
uffer
.
empty
())
result
=
m
_source
.
get
();
else
{
result
=
m
B
uffer
.
top
();
m
B
uffer
.
pop
();
result
=
m
_b
uffer
.
top
();
m
_b
uffer
.
pop
();
}
// very simple CR/LF translation into LF
if
(
result
==
'\r'
)
{
int
lookahead
=
m
Data
.
get
();
int
lookahead
=
m
_source
.
get
();
if
(
lookahead
!=
'\n'
)
m
B
uffer
.
push
(
lookahead
);
m
_b
uffer
.
push
(
lookahead
);
result
=
'\n'
;
}
m
TokenV
alue
+=
static_cast
<
char
>
(
result
);
m
_token_v
alue
+=
static_cast
<
char
>
(
result
);
if
(
result
==
'\n'
)
++
m_line_nr
;
if
(
VERBOSE
>=
6
)
{
std
::
cerr
<<
"get
NextC
har => "
;
std
::
cerr
<<
"get
_next_c
har => "
;
if
(
iscntrl
(
result
)
or
not
isprint
(
result
))
std
::
cerr
<<
int
(
result
)
<<
std
::
endl
;
else
...
...
@@ -228,21 +230,21 @@ class sac_parser
void
retract
()
{
assert
(
not
m
TokenV
alue
.
empty
());
assert
(
not
m
_token_v
alue
.
empty
());
char
ch
=
m
TokenV
alue
.
back
();
char
ch
=
m
_token_v
alue
.
back
();
if
(
ch
==
'\n'
)
--
m_line_nr
;
m
B
uffer
.
push
(
ch
);
m
TokenV
alue
.
pop_back
();
m
_b
uffer
.
push
(
ch
);
m
_token_v
alue
.
pop_back
();
}
int
restart
(
int
start
)
{
int
result
=
0
;
while
(
not
m
TokenV
alue
.
empty
())
while
(
not
m
_token_v
alue
.
empty
())
retract
();
switch
(
start
)
...
...
@@ -277,12 +279,12 @@ class sac_parser
int
state
=
State
::
Start
,
start
=
State
::
Start
;
m_bol
=
false
;
m
TokenV
alue
.
clear
();
m
_token_v
alue
.
clear
();
mTokenType
=
CIFValue
::
Unknown
;
while
(
result
==
CIFToken
::
Unknown
)
{
auto
ch
=
get
NextC
har
();
auto
ch
=
get
_next_c
har
();
switch
(
state
)
{
...
...
@@ -318,7 +320,7 @@ class sac_parser
{
state
=
State
::
Start
;
retract
();
m
TokenV
alue
.
clear
();
m
_token_v
alue
.
clear
();
}
else
m_bol
=
(
ch
==
'\n'
);
...
...
@@ -329,7 +331,7 @@ class sac_parser
{
state
=
State
::
Start
;
m_bol
=
true
;
m
TokenV
alue
.
clear
();
m
_token_v
alue
.
clear
();
}
else
if
(
ch
==
kEOF
)
result
=
CIFToken
::
Eof
;
...
...
@@ -351,8 +353,8 @@ class sac_parser
state
=
State
::
TextField
;
else
if
(
ch
==
';'
)
{
assert
(
m
TokenV
alue
.
length
()
>=
2
);
m
TokenValue
=
mTokenValue
.
substr
(
1
,
mTokenV
alue
.
length
()
-
3
);
assert
(
m
_token_v
alue
.
length
()
>=
2
);
m
_token_value
=
m_token_value
.
substr
(
1
,
m_token_v
alue
.
length
()
-
3
);
mTokenType
=
CIFValue
::
TextField
;
result
=
CIFToken
::
Value
;
}
...
...
@@ -378,10 +380,10 @@ class sac_parser
result
=
CIFToken
::
Value
;
mTokenType
=
CIFValue
::
String
;
if
(
m
TokenV
alue
.
length
()
<
2
)
if
(
m
_token_v
alue
.
length
()
<
2
)
error
(
"Invalid quoted string token"
);
m
TokenValue
=
mTokenValue
.
substr
(
1
,
mTokenV
alue
.
length
()
-
2
);
m
_token_value
=
m_token_value
.
substr
(
1
,
m_token_v
alue
.
length
()
-
2
);
}
else
if
(
ch
==
quoteChar
)
;
...
...
@@ -493,7 +495,7 @@ class sac_parser
case
State
:
:
Value
:
if
(
ch
==
'_'
)
{
std
::
string
s
=
toLowerCopy
(
m
TokenV
alue
);
std
::
string
s
=
toLowerCopy
(
m
_token_v
alue
);
if
(
s
==
"global_"
)
result
=
CIFToken
::
GLOBAL
;
...
...
@@ -518,12 +520,12 @@ class sac_parser
retract
();
result
=
CIFToken
::
Value
;
if
(
m
TokenV
alue
==
"."
)
if
(
m
_token_v
alue
==
"."
)
mTokenType
=
CIFValue
::
Inapplicable
;
else
if
(
m
TokenV
alue
==
"?"
)
else
if
(
m
_token_v
alue
==
"?"
)
{
mTokenType
=
CIFValue
::
Unknown
;
m
TokenV
alue
.
clear
();
m
_token_v
alue
.
clear
();
}
}
break
;
...
...
@@ -539,7 +541,7 @@ class sac_parser
else
result
=
CIFToken
::
SAVE
;
m
TokenValue
.
erase
(
mTokenValue
.
begin
(),
mTokenV
alue
.
begin
()
+
5
);
m
_token_value
.
erase
(
m_token_value
.
begin
(),
m_token_v
alue
.
begin
()
+
5
);
}
break
;
...
...
@@ -556,7 +558,7 @@ class sac_parser
if
(
mTokenType
!=
CIFValue
::
Unknown
)
std
::
cerr
<<
' '
<<
get_value_name
(
mTokenType
);
if
(
result
!=
CIFToken
::
Eof
)
std
::
cerr
<<
" "
<<
std
::
quoted
(
m
TokenV
alue
);
std
::
cerr
<<
" "
<<
std
::
quoted
(
m
_token_v
alue
);
std
::
cerr
<<
std
::
endl
;
}
...
...
@@ -572,10 +574,10 @@ class sac_parser
}
public
:
bool
parse
SingleD
atablock
(
const
std
::
string
&
datablock
)
bool
parse
_single_d
atablock
(
const
std
::
string
&
datablock
)
{
// first locate the start, as fast as we can
auto
&
sb
=
*
m
Data
.
rdbuf
();
auto
&
sb
=
*
m
_source
.
rdbuf
();
enum
{
...
...
@@ -653,20 +655,20 @@ class sac_parser
if
(
found
)
{
produce
D
atablock
(
datablock
);
produce
_d
atablock
(
datablock
);
m_lookahead
=
get_next_token
();
parse
DataB
lock
();
parse
_datab
lock
();
}
return
found
;
}
DatablockIndex
indexD
atablocks
()
datablock_index
index_d
atablocks
()
{
DatablockI
ndex
index
;
datablock_i
ndex
index
;
// first locate the start, as fast as we can
auto
&
sb
=
*
m
Data
.
rdbuf
();
auto
&
sb
=
*
m
_source
.
rdbuf
();
enum
{
...
...
@@ -748,7 +750,7 @@ class sac_parser
else
if
(
isspace
(
ch
))
{
if
(
not
datablock
.
empty
())
index
[
datablock
]
=
m
Data
.
tellg
();
index
[
datablock
]
=
m
_source
.
tellg
();
state
=
start
;
}
...
...
@@ -763,18 +765,18 @@ class sac_parser
return
index
;
}
bool
parse
SingleDatablock
(
const
std
::
string
&
datablock
,
const
DatablockI
ndex
&
index
)
bool
parse
_single_datablock
(
const
std
::
string
&
datablock
,
const
datablock_i
ndex
&
index
)
{
bool
result
=
false
;
auto
i
=
index
.
find
(
datablock
);
if
(
i
!=
index
.
end
())
{
m
Data
.
seekg
(
i
->
second
);
m
_source
.
seekg
(
i
->
second
);
produce
D
atablock
(
datablock
);
produce
_d
atablock
(
datablock
);
m_lookahead
=
get_next_token
();
parse
DataB
lock
();
parse
_datab
lock
();
result
=
true
;
}
...
...
@@ -782,21 +784,21 @@ class sac_parser
return
result
;
}
void
parse
F
ile
()
void
parse
_f
ile
()
{
while
(
m_lookahead
!=
CIFToken
::
Eof
)
{
switch
(
m_lookahead
)
{
case
CIFToken
:
:
GLOBAL
:
parse
G
lobal
();
parse
_g
lobal
();
break
;
case
CIFToken
:
:
DATA
:
produce
Datablock
(
mTokenV
alue
);
produce
_datablock
(
m_token_v
alue
);
match
(
CIFToken
::
DATA
);
parse
DataB
lock
();
parse
_datab
lock
();
break
;
default
:
...
...
@@ -807,7 +809,7 @@ class sac_parser
}
protected
:
void
parse
G
lobal
()
void
parse
_g
lobal
()
{
match
(
CIFToken
::
GLOBAL
);
while
(
m_lookahead
==
CIFToken
::
Tag
)
...
...
@@ -817,7 +819,7 @@ class sac_parser
}
}
void
parse
DataB
lock
()
void
parse
_datab
lock
()
{
std
::
string
cat
;
...
...
@@ -836,11 +838,11 @@ class sac_parser
while
(
m_lookahead
==
CIFToken
::
Tag
)
{
std
::
string
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
m
TokenV
alue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
m
_token_v
alue
);
if
(
cat
.
empty
())
{
produce
C
ategory
(
catName
);
produce
_c
ategory
(
catName
);
cat
=
catName
;
}
else
if
(
not
iequals
(
cat
,
catName
))
...
...
@@ -853,11 +855,11 @@ class sac_parser
while
(
m_lookahead
==
CIFToken
::
Value
)
{
produce
R
ow
();
produce
_r
ow
();
for
(
auto
tag
:
tags
)
{
produce
Item
(
cat
,
tag
,
mTokenV
alue
);
produce
_item
(
cat
,
tag
,
m_token_v
alue
);
match
(
CIFToken
::
Value
);
}
}
...
...
@@ -869,25 +871,25 @@ class sac_parser
case
CIFToken
:
:
Tag
:
{
std
::
string
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
m
TokenV
alue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
m
_token_v
alue
);
if
(
not
iequals
(
cat
,
catName
))
{
produce
C
ategory
(
catName
);
produce
_c
ategory
(
catName
);
cat
=
catName
;
produce
R
ow
();
produce
_r
ow
();
}
match
(
CIFToken
::
Tag
);
produce
Item
(
cat
,
itemName
,
mTokenV
alue
);
produce
_item
(
cat
,
itemName
,
m_token_v
alue
);
match
(
CIFToken
::
Value
);
break
;
}
case
CIFToken
:
:
SAVE
:
parse
SaveF
rame
();
parse
_save_f
rame
();
break
;
default
:
...
...
@@ -897,7 +899,7 @@ class sac_parser
}
}
virtual
void
parse
SaveF
rame
()
virtual
void
parse
_save_f
rame
()
{
error
(
"A regular CIF file should not contain a save frame"
);
}
...
...
@@ -914,10 +916,10 @@ class sac_parser
// production methods, these are pure virtual here
virtual
void
produce
D
atablock
(
const
std
::
string
&
name
)
=
0
;
virtual
void
produce
C
ategory
(
const
std
::
string
&
name
)
=
0
;
virtual
void
produce
R
ow
()
=
0
;
virtual
void
produce
I
tem
(
const
std
::
string
&
category
,
const
std
::
string
&
item
,
const
std
::
string
&
value
)
=
0
;
virtual
void
produce
_d
atablock
(
const
std
::
string
&
name
)
=
0
;
virtual
void
produce
_c
ategory
(
const
std
::
string
&
name
)
=
0
;
virtual
void
produce
_r
ow
()
=
0
;
virtual
void
produce
_i
tem
(
const
std
::
string
&
category
,
const
std
::
string
&
item
,
const
std
::
string
&
value
)
=
0
;
protected
:
enum
State
...
...
@@ -939,16 +941,16 @@ class sac_parser
SAVE
};
std
::
istream
&
m
Data
;
std
::
istream
&
m
_source
;
// Parser state
bool
m_validate
;
uint32_t
m_line_nr
;
bool
m_bol
;
CIFToken
m_lookahead
;
std
::
string
m
TokenV
alue
;
std
::
string
m
_token_v
alue
;
CIFValue
mTokenType
;
std
::
stack
<
int
>
m
B
uffer
;
std
::
stack
<
int
>
m
_b
uffer
;
};
// --------------------------------------------------------------------
...
...
@@ -971,12 +973,12 @@ class parser_t : public sac_parser
{
}
void
produce
D
atablock
(
const
std
::
string
&
name
)
override
void
produce
_d
atablock
(
const
std
::
string
&
name
)
override
{
std
::
tie
(
m_datablock
,
std
::
ignore
)
=
m_file
.
emplace
(
name
);
}
void
produce
C
ategory
(
const
std
::
string
&
name
)
override
void
produce
_c
ategory
(
const
std
::
string
&
name
)
override
{
if
(
VERBOSE
>=
4
)
std
::
cerr
<<
"producing category "
<<
name
<<
std
::
endl
;
...
...
@@ -984,7 +986,7 @@ class parser_t : public sac_parser
std
::
tie
(
m_category
,
std
::
ignore
)
=
m_datablock
->
emplace
(
name
);
}
void
produce
R
ow
()
override
void
produce
_r
ow
()
override
{
if
(
VERBOSE
>=
4
)
std
::
cerr
<<
"producing row for category "
<<
m_category
->
name
()
<<
std
::
endl
;
...
...
@@ -994,7 +996,7 @@ class parser_t : public sac_parser
// m_row.lineNr(m_line_nr);
}
void
produce
I
tem
(
const
std
::
string
&
category
,
const
std
::
string
&
item
,
const
std
::
string
&
value
)
override
void
produce
_i
tem
(
const
std
::
string
&
category
,
const
std
::
string
&
item
,
const
std
::
string
&
value
)
override
{
if
(
VERBOSE
>=
4
)
std
::
cerr
<<
"producing _"
<<
category
<<
'.'
<<
item
<<
" -> "
<<
value
<<
std
::
endl
;
...
...
@@ -1002,7 +1004,7 @@ class parser_t : public sac_parser
if
(
not
iequals
(
category
,
m_category
->
name
()))
error
(
"inconsistent categories in loop_"
);
m_row
[
item
]
=
m
TokenV
alue
;
m_row
[
item
]
=
m
_token_v
alue
;
}
protected
:
...
...
@@ -1012,24 +1014,7 @@ class parser_t : public sac_parser
row_handle_type
m_row
;
};
// class Parser : public SacParser
// {
// public:
// Parser(std::istream &is, File &f, bool init = true);
// virtual void produceDatablock(const std::string &name);
// virtual void produceCategory(const std::string &name);
// virtual void produceRow();
// virtual void produceItem(const std::string &category, const std::string &item, const std::string &value);
// protected:
// File &mFile;
// Datablock *mDataBlock;
// Datablock::iterator m_category;
// Row mRow;
// };
// // --------------------------------------------------------------------
// --------------------------------------------------------------------
// class DictParser : public Parser
// {
...
...
@@ -1040,7 +1025,7 @@ class parser_t : public sac_parser
// void loadDictionary();
// private:
// virtual void parse
SaveF
rame();
// virtual void parse
_save_f
rame();
// bool collectItemTypes();
// void linkItems();
...
...
include/cif++/v2/row.hpp
View file @
98ff7943
...
...
@@ -27,6 +27,7 @@
#pragma once
#include <cif++/v2/item.hpp>
#include <cif++/v2/condition.hpp>
namespace
cif
::
v2
{
...
...
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