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
16b7deaf
Unverified
Commit
16b7deaf
authored
Jun 02, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better is_unquoted_string test
parent
ce14593f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
20 deletions
+125
-20
include/cif++/parser.hpp
+1
-20
src/parser.cpp
+124
-0
No files found.
include/cif++/parser.hpp
View file @
16b7deaf
...
...
@@ -92,26 +92,7 @@ class sac_parser
(
ch
>=
0x20
and
ch
<=
0x7f
and
(
kCharTraitsTable
[
ch
-
0x20
]
&
kAnyPrintMask
)
!=
0
);
}
static
bool
is_unquoted_string
(
std
::
string_view
text
)
{
bool
result
=
text
.
empty
()
or
is_ordinary
(
text
.
front
());
if
(
result
)
{
for
(
auto
ch
:
text
)
{
if
(
is_non_blank
(
ch
))
continue
;
result
=
false
;
break
;
}
}
static
const
std
::
regex
kReservedRx
(
R"(loop_|stop_|global_|data_\S+|save_\S+)"
,
std
::
regex_constants
::
icase
);
// but be careful it does not contain e.g. stop_
return
result
and
not
std
::
regex_match
(
text
.
begin
(),
text
.
end
(),
kReservedRx
);
}
static
bool
is_unquoted_string
(
std
::
string_view
text
);
protected
:
static
constexpr
uint8_t
kCharTraitsTable
[
128
]
=
{
...
...
src/parser.cpp
View file @
16b7deaf
...
...
@@ -54,6 +54,130 @@ sac_parser::sac_parser(std::istream &is, bool init)
m_lookahead
=
get_next_token
();
}
bool
sac_parser
::
is_unquoted_string
(
std
::
string_view
text
)
{
bool
result
=
text
.
empty
()
or
is_ordinary
(
text
.
front
());
int
state
=
1
;
for
(
char
ch
:
text
)
{
if
(
not
is_non_blank
(
ch
))
{
result
=
false
;
break
;
}
switch
(
state
)
{
case
0
:
break
;
case
1
:
switch
(
ch
&
~
0x20
)
{
case
'D'
:
// data_
state
=
10
;
break
;
case
'G'
:
state
=
20
;
// global_
break
;
case
'L'
:
state
=
30
;
// loop_
break
;
case
'S'
:
state
=
40
;
// stop_ | save_
break
;
default
:
state
=
0
;
break
;
}
break
;
case
10
:
state
=
((
ch
&
~
0x20
)
==
'A'
)
?
state
+
1
:
0
;
break
;
case
11
:
state
=
((
ch
&
~
0x20
)
==
'T'
)
?
state
+
1
:
0
;
break
;
case
12
:
state
=
((
ch
&
~
0x20
)
==
'A'
)
?
100
:
0
;
break
;
case
20
:
state
=
((
ch
&
~
0x20
)
==
'L'
)
?
state
+
1
:
0
;
break
;
case
21
:
state
=
((
ch
&
~
0x20
)
==
'O'
)
?
state
+
1
:
0
;
break
;
case
22
:
state
=
((
ch
&
~
0x20
)
==
'B'
)
?
state
+
1
:
0
;
break
;
case
23
:
state
=
((
ch
&
~
0x20
)
==
'A'
)
?
state
+
1
:
0
;
break
;
case
24
:
state
=
((
ch
&
~
0x20
)
==
'L'
)
?
200
:
0
;
break
;
case
30
:
state
=
((
ch
&
~
0x20
)
==
'O'
)
?
state
+
1
:
0
;
break
;
case
31
:
state
=
((
ch
&
~
0x20
)
==
'O'
)
?
state
+
1
:
0
;
break
;
case
32
:
state
=
((
ch
&
~
0x20
)
==
'P'
)
?
200
:
0
;
break
;
case
40
:
if
((
ch
&
~
0x20
)
==
'A'
)
state
=
41
;
else
if
((
ch
&
~
0x20
)
==
'T'
)
state
=
51
;
else
state
=
0
;
break
;
case
41
:
state
=
((
ch
&
~
0x20
)
==
'V'
)
?
state
+
1
:
0
;
break
;
case
42
:
state
=
((
ch
&
~
0x20
)
==
'E'
)
?
100
:
0
;
break
;
case
51
:
state
=
((
ch
&
~
0x20
)
==
'O'
)
?
state
+
1
:
0
;
break
;
case
52
:
state
=
((
ch
&
~
0x20
)
==
'P'
)
?
200
:
0
;
break
;
case
100
:
state
=
((
ch
&
~
0x20
)
==
'_'
)
?
101
:
0
;
break
;
case
101
:
result
=
false
;
state
=
0
;
break
;
case
200
:
if
((
ch
&
~
0x20
)
==
'_'
)
{
result
=
false
;
state
=
201
;
}
else
state
=
0
;
break
;
case
201
:
result
=
true
;
break
;
}
}
return
result
;
// bool result = text.empty() or is_ordinary(text.front());
// int state = 0;
// if (result)
// {
// for (auto ch : text)
// {
// switch (state)
// {
// case 0:
// switch
// }
// if (is_non_blank(ch))
// continue;
// result = false;
// break;
// }
// }
// // static const std::regex kReservedRx(R"(loop_|stop_|global_|data_\S+|save_\S+)", std::regex_constants::icase);
// // but be careful it does not contain e.g. stop_
// return result and not std::regex_match(text.begin(), text.end(), kReservedRx);
}
// get_next_char takes a char from the buffer, or if it is empty
// from the istream. This function also does carriage/linefeed
// translation.
...
...
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