Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
bc95e9bc
Commit
bc95e9bc
authored
11 years ago
by
Martin Žák
Browse files
Options
Downloads
Patches
Plain Diff
Acat - option for parsing automaton into some known type, exception when file is not found
parent
a778d565
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
acat/src/acat.cpp
+48
-16
48 additions, 16 deletions
acat/src/acat.cpp
alib/src/sax/SaxInterface.cpp
+8
-2
8 additions, 2 deletions
alib/src/sax/SaxInterface.cpp
with
56 additions
and
18 deletions
acat/src/acat.cpp
+
48
−
16
View file @
bc95e9bc
...
...
@@ -30,35 +30,67 @@ using namespace alib;
using
namespace
sax
;
using
namespace
grammar
;
void
getAutomaton
(
list
<
Token
>&
tokens
,
bool
complexTypes
)
{
UnknownAutomaton
automaton
=
AutomatonParser
::
parse
(
tokens
);
if
(
complexTypes
)
{
Automaton
*
concreateAutomaton
=
AutomatonFactory
::
buildAutomaton
(
automaton
);
concreateAutomaton
->
toXML
(
cout
);
}
else
{
automaton
.
toXML
(
cout
);
}
}
void
getGrammar
(
list
<
Token
>&
tokens
)
{
UnknownGrammar
grammar
=
GrammarParser
::
parse
(
tokens
);
grammar
.
toXML
(
cout
);
}
void
getRegExp
(
list
<
Token
>&
tokens
)
{
RegExp
regexp
=
RegExpParser
::
parse
(
tokens
);
regexp
.
toXML
(
cout
);
}
int
main
(
int
argc
,
char
**
argv
)
{
list
<
Token
>
tokens
;
int
fileParameterIndex
=
-
1
;
bool
complexTypes
=
false
;
try
{
if
(
argc
>
1
)
{
if
(
string
(
"-h"
).
compare
(
argv
[
1
])
==
0
)
{
cout
<<
"Automaton parsing.
\n
Usage: catPDA [automaton.xml]
\n
"
;
return
-
1
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
string
(
"-h"
).
compare
(
argv
[
i
])
==
0
)
{
cout
<<
"Automaton parsing.
\n
Usage: catPDA [automaton.xml]
\n
"
;
return
-
1
;
}
else
if
(
string
(
"-c"
).
compare
(
argv
[
i
])
==
0
)
{
complexTypes
=
true
;
}
else
{
if
(
fileParameterIndex
==
-
1
)
{
fileParameterIndex
=
i
;
}
else
{
throw
AlibException
(
"Only one file can be passed as parameter - "
+
string
(
argv
[
i
])
+
" "
+
string
(
argv
[
fileParameterIndex
]));
}
}
}
}
list
<
Token
>
tokens
;
SaxInterface
::
parseFile
(
argv
[
1
],
tokens
);
if
(
fileParameterIndex
!=
-
1
)
{
SaxInterface
::
parseFile
(
argv
[
fileParameterIndex
],
tokens
);
}
else
{
string
input
(
istreambuf_iterator
<
char
>
(
cin
),
(
istreambuf_iterator
<
char
>
()));
string
input
(
istreambuf_iterator
<
char
>
(
cin
),
(
istreambuf_iterator
<
char
>
()));
SaxInterface
::
parseMemory
(
input
,
tokens
);
}
if
(
tokens
.
front
().
getData
()
==
"automaton"
)
{
UnknownAutomaton
automaton
=
AutomatonParser
::
parse
(
tokens
);
automaton
.
toXML
(
cout
);
getAutomaton
(
tokens
,
complexTypes
);
}
else
if
(
tokens
.
front
().
getData
()
==
"grammar"
)
{
UnknownGrammar
grammar
=
GrammarParser
::
parse
(
tokens
);
grammar
.
toXML
(
cout
);
getGrammar
(
tokens
);
}
else
if
(
tokens
.
front
().
getData
()
==
"regexp"
)
{
RegExp
regexp
=
RegExpParser
::
parse
(
tokens
);
regexp
.
toXML
(
cout
);
getRegExp
(
tokens
);
}
else
{
throw
AlibException
(
"Expected root tag automaton or grammar. Read: "
+
tokens
.
front
().
getData
());
throw
AlibException
(
"Expected root tag automaton, grammar or regexp. Read: "
+
tokens
.
front
().
getData
());
}
}
catch
(
AlibException
&
e
)
{
...
...
This diff is collapsed.
Click to expand it.
alib/src/sax/SaxInterface.cpp
+
8
−
2
View file @
bc95e9bc
...
...
@@ -9,8 +9,10 @@
#include
<string>
#include
<cstring>
#include
"../AlibException.h"
namespace
sax
{
void
SaxInterface
::
initSAXHandler
(
xmlSAXHandler
&
handler
)
{
memset
(
&
handler
,
0
,
sizeof
(
handler
));
handler
.
initialized
=
XML_SAX2_MAGIC
;
...
...
@@ -34,9 +36,13 @@ void SaxInterface::parseFile(std::string filename, std::list<Token>& out) {
xmlSAXHandler
handler
;
initSAXHandler
(
handler
);
xmlSAXUserParseFile
(
&
handler
,
(
void
*
)
&
out
,
filename
.
c_str
());
int
result
=
xmlSAXUserParseFile
(
&
handler
,
(
void
*
)
&
out
,
filename
.
c_str
());
xmlCleanupParser
();
if
(
result
!=
0
)
{
throw
alib
::
AlibException
(
"Cannot parse the XML file "
+
filename
);
}
}
void
SaxInterface
::
characters
(
void
*
user_data
,
const
xmlChar
*
ch
,
int
len
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment