MCPcopy Create free account
hub / github.com/TankOs/SFGUI / ParseFile

Function ParseFile

src/SFGUI/Parsers/ThemeParser/Parse.cpp:82–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82std::vector<Rule> ParseFile( std::string filename ) {
83 _grammar.ClearResults();
84 //ELL_ENABLE_DUMP( grammar );
85
86 auto result = false;
87
88 std::vector<Rule> rules;
89
90 std::ifstream file( filename.c_str(), std::ifstream::in );
91 file.unsetf( std::ios::skipws );
92
93 if( !file.good() ) {
94#if defined( SFGUI_DEBUG )
95 std::cerr << "Error opening file: " << filename << "\n";
96#endif
97 file.close();
98 return std::vector<Rule>();
99 }
100
101 auto str = std::string( std::istreambuf_iterator<char>( file ), std::istreambuf_iterator<char>() );
102
103 try {
104 _grammar.parse( str.c_str() );
105 rules = _grammar.GetTheme();
106 result = true;
107 }
108#if defined( SFGUI_DEBUG )
109 catch( const std::runtime_error& e ) {
110 result = false;
111
112 std::cerr << "Error parsing file \"" << filename << "\" at line " << _grammar.line_number <<":\n"
113 << GetLine( str, static_cast<std::size_t>( _grammar.line_number ) ) << "\n"
114 << std::string( ColumnPosition( str, static_cast<std::size_t>( _grammar.position - str.c_str() ) ), ' ' ) << "^\n"
115 << "Expected " << strstr( e.what(), "expecting " ) + 10 << "\n";
116 }
117#else
118 catch( const std::runtime_error& /*e*/ ) {
119 result = false;
120 }
121#endif
122
123 if( result && ( _grammar.get() == '\0' ) ) {
124 file.close();
125 return rules;
126 }
127
128 file.close();
129
130 return std::vector<Rule>();
131}
132
133}
134}

Callers

nothing calls this directly

Calls 3

ClearResultsMethod · 0.80
getMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected