Basic version of the parsercheck utility
This commit is contained in:
parent
0ed905bbde
commit
5cb5229e43
3 changed files with 82 additions and 3 deletions
2
demo.srd
2
demo.srd
|
@ -86,7 +86,7 @@
|
|||
(get-input dof-falloff)
|
||||
(get-input dof-max-blur)
|
||||
))
|
||||
(set-uniforms prog 3 ((get-input dof-samples))
|
||||
(set-uniforms prog 3 ((get-input dof-samples)))
|
||||
(set-uniforms prog 4 (vp-width vp-height time))
|
||||
)
|
||||
|
||||
|
|
2
ebcl
2
ebcl
|
@ -1 +1 @@
|
|||
Subproject commit 073fcb3d5e9366de941ebce73a42cbf3c7686b4d
|
||||
Subproject commit 3adfdadd119f2783877865a8365a29d4b567911f
|
|
@ -1,3 +1,82 @@
|
|||
int main( )
|
||||
#include "externals.hh"
|
||||
#include "opast.hh"
|
||||
#include <ebcl/Files.hh>
|
||||
#include <ebcl/SRDText.hh>
|
||||
|
||||
using namespace ebcl;
|
||||
using namespace opast;
|
||||
|
||||
namespace {
|
||||
|
||||
void PrintStreamError(
|
||||
char const* const prefix ,
|
||||
T_String const& name ,
|
||||
X_StreamError const& error )
|
||||
{
|
||||
T_StringBuilder sb;
|
||||
sb << prefix << " '" << name << "': " << error.what( );
|
||||
if ( error.code( ) == E_StreamError::SYSTEM_ERROR ) {
|
||||
sb << " (error code " << error.systemError( ) << ")";
|
||||
}
|
||||
sb << '\n' << '\0';
|
||||
fprintf( stderr , "%s" , sb.data( ) );
|
||||
}
|
||||
|
||||
void WriteSRDError(
|
||||
T_StringBuilder& sb ,
|
||||
T_SRDError const& error )
|
||||
{
|
||||
sb << error.location( ) << " - " << error.error( ) << "\n";
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
int main( int argc , char** argv )
|
||||
{
|
||||
// Open file
|
||||
const T_String inputName( argc >= 2 ? argv[ 1 ] : "demo.srd" );
|
||||
T_File input( inputName , E_FileMode::READ_ONLY );
|
||||
try {
|
||||
input.open( );
|
||||
} catch ( X_StreamError const& e ) {
|
||||
PrintStreamError( "Could not open" , inputName , e );
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Load SRD data
|
||||
T_SRDMemoryTarget srdOut;
|
||||
srdOut.clearComments( true ).clearFlushToken( true );
|
||||
try {
|
||||
T_SRDTextReader srdReader{ srdOut };
|
||||
T_FileInputStream fis{ input };
|
||||
srdReader.read( inputName , fis );
|
||||
} catch ( X_StreamError const& e ) {
|
||||
PrintStreamError( "Could not open" , inputName , e );
|
||||
return 1;
|
||||
} catch ( X_SRDErrors const& e ) {
|
||||
T_StringBuilder sb;
|
||||
const auto nErrors( e.errors.size( ) );
|
||||
for ( auto i = 0u ; i < nErrors ; i ++ ) {
|
||||
WriteSRDError( sb , e.errors[ i ] );
|
||||
}
|
||||
sb << "No parsing happened due to format errors\n" << '\0';
|
||||
fprintf( stderr , "%s" , sb.data( ) );
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Parse the fuck
|
||||
T_Parser parser;
|
||||
if ( parser.parse( srdOut.list( ) ) ) {
|
||||
printf( "Success!\n" );
|
||||
return 0;
|
||||
} else {
|
||||
T_StringBuilder sb;
|
||||
for ( auto const& err : parser.errors( ) ) {
|
||||
WriteSRDError( sb , err );
|
||||
}
|
||||
sb << "Parser failed\n" << '\0';
|
||||
fprintf( stderr , "%s" , sb.data( ) );
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue