Skip to content

Commit

Permalink
renamed .gjs to .gls.js
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Jan 4, 2024
1 parent e5e86fa commit 6728edd
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ Config::Config( const int argc, const char* argv[] ) {
}
);
parser.AddRule(
"gse-prompt-gjs", "Open interactive GJS prompt", AH( this ) {
m_debug_flags |= DF_GSE_ONLY | DF_GSE_PROMPT_GJS;
"gse-prompt-js", "Open interactive JS prompt", AH( this ) {
m_debug_flags |= DF_GSE_ONLY | DF_GSE_PROMPT_JS;
}
);
parser.AddRule(
Expand Down
2 changes: 1 addition & 1 deletion src/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CLASS( Config, base::Module )
DF_QUIET = 1 << 12,
DF_GSE_ONLY = 1 << 13,
DF_GSE_TESTS = 1 << 14,
DF_GSE_PROMPT_GJS = 1 << 15,
DF_GSE_PROMPT_JS = 1 << 15,
};
#endif

Expand Down
11 changes: 6 additions & 5 deletions src/gse/GSE.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "GSE.h"

#include "parser/GJS.h"
#include "parser/JS.h"
#include "runner/Interpreter.h"
#include "util/FS.h"

Expand All @@ -24,11 +24,12 @@ GSE::~GSE() {

parser::Parser* GSE::GetParser( const std::string& filename, const std::string& source, const size_t initial_line_num ) const {
parser::Parser* parser = nullptr;
const auto extension = util::FS::GetExtension( filename );
if ( extension == ".gjs" ) {
NEW( parser, parser::GJS, filename, source, initial_line_num );
const auto extensions = util::FS::GetExtensions( filename );
ASSERT( extensions.size() == 2 && extensions[ 0 ] == ".gls", "unsupported file name ( " + filename + "), expected: *.gls.*" );
if ( extensions[ 1 ] == ".js" ) {
NEW( parser, parser::JS, filename, source, initial_line_num );
}
ASSERT( parser, "could not find parser for '" + extension + "' extension" );
ASSERT( parser, "could not find parser for '.gls" + extensions[ 1 ] + "' extension" );
return parser;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gse/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SET( SRC ${SRC}

${PWD}/Parser.cpp
${PWD}/GJS.cpp
${PWD}/JS.cpp

PARENT_SCOPE )
36 changes: 18 additions & 18 deletions src/gse/parser/GJS.cpp → src/gse/parser/JS.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "GJS.h"
#include "JS.h"

#include <stack>
#include <functional>
Expand All @@ -24,12 +24,12 @@ namespace parser {

using namespace program;

GJS::GJS( const std::string& filename, const std::string& source, const size_t initial_line_num )
JS::JS( const std::string& filename, const std::string& source, const size_t initial_line_num )
: Parser( filename, source, initial_line_num ) {

}

void GJS::GetElements( source_elements_t& elements ) {
void JS::GetElements( source_elements_t& elements ) {
char c;
si_t::pos_t begin;
si_t si;
Expand Down Expand Up @@ -127,20 +127,20 @@ void GJS::GetElements( source_elements_t& elements ) {
#define EL( _label )
#endif

const program::Program* GJS::GetProgram( const source_elements_t& elements ) {
const program::Program* JS::GetProgram( const source_elements_t& elements ) {
NEWV( program, program::Program, GetScope( elements.begin(), elements.end() ) );
return program;
}

const si_t GJS::GetSI( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const si_t JS::GetSI( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
return {
( *begin )->m_si.file,
( *begin )->m_si.from,
( ( *( end - 1 ) )->m_si.to )
};
}

const program::Scope* GJS::GetScope( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Scope* JS::GetScope( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetScope" )
std::vector< const program::Control* > body = {};
auto it = begin;
Expand Down Expand Up @@ -188,7 +188,7 @@ const program::Scope* GJS::GetScope( const source_elements_t::const_iterator& be
return new program::Scope( GetSI( begin, end ), body );
}

const program::Control* GJS::GetControl( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Control* JS::GetControl( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetControl" );
ASSERT( begin != end, "no elements inside" );
if ( ( *begin )->m_type == SourceElement::ET_CONDITIONAL ) {
Expand All @@ -199,7 +199,7 @@ const program::Control* GJS::GetControl( const source_elements_t::const_iterator
}
}

const program::Conditional* GJS::GetConditional( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Conditional* JS::GetConditional( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetConditional" );
ASSERT( ( *begin )->m_type == SourceElement::ET_CONDITIONAL, "conditional expected here" );
Conditional* conditional = (Conditional*)( *begin );
Expand Down Expand Up @@ -266,12 +266,12 @@ const program::Conditional* GJS::GetConditional( const source_elements_t::const_
}
}

const program::Statement* GJS::GetStatement( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Statement* JS::GetStatement( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetStatement" );
return new program::Statement( GetSI( begin, end ), GetExpression( begin, end, true ) );
}

const program::Operand* GJS::GetExpressionOrOperand( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end, bool is_scope_expected ) {
const program::Operand* JS::GetExpressionOrOperand( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end, bool is_scope_expected ) {
ELS( "GetExpression" )
// resolve elements, unpack scopes
typedef std::vector< const Element* > elements_t;
Expand Down Expand Up @@ -650,14 +650,14 @@ const program::Operand* GJS::GetExpressionOrOperand( const source_elements_t::co
return get_operand( elements.begin(), elements.end() );
}

const program::Expression* GJS::GetExpression( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end, const bool is_scope_expected ) {
const program::Expression* JS::GetExpression( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end, const bool is_scope_expected ) {
const auto* operand = GetExpressionOrOperand( begin, end, is_scope_expected );
return operand->type == program::Operand::OT_EXPRESSION
? (Expression*)operand
: new Expression( operand->m_si, operand );
}

const program::Operand* GJS::GetOperand( const Identifier* element, program::Variable::variable_hints_t* next_var_hints ) {
const program::Operand* JS::GetOperand( const Identifier* element, program::Variable::variable_hints_t* next_var_hints ) {
EL( "GetOperand" )
switch ( element->m_identifier_type ) {
case IDENTIFIER_VARIABLE: {
Expand Down Expand Up @@ -693,14 +693,14 @@ const program::Operand* GJS::GetOperand( const Identifier* element, program::Var
}
}

const program::Operator* GJS::GetOperator( const Operator* element ) {
const program::Operator* JS::GetOperator( const Operator* element ) {
EL( "GetOperator" )
const auto it = OPERATOR_NAMES.find( element->m_op );
ASSERT( it != OPERATOR_NAMES.end(), "operator name not found: " + element->m_op );
return new program::Operator( element->m_si, it->second );
}

const program::Array* GJS::GetArray( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Array* JS::GetArray( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetArray" );
std::vector< const Expression* > elements = {};
source_elements_t::const_iterator it = begin, it_end;
Expand All @@ -726,7 +726,7 @@ const program::Array* GJS::GetArray( const source_elements_t::const_iterator& be
return new program::Array( GetSI( begin - 1, end + 1 ), elements );
}

const program::Object* GJS::GetObject( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const program::Object* JS::GetObject( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ELS( "GetObject" );
std::unordered_map< std::string, const Expression* > properties = {};
Identifier* identifier;
Expand Down Expand Up @@ -762,7 +762,7 @@ const program::Object* GJS::GetObject( const source_elements_t::const_iterator&
return new program::Object( GetSI( begin - 1, end + 1 ), properties );
}

const GJS::source_elements_t::const_iterator GJS::GetBracketsEnd( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
const JS::source_elements_t::const_iterator JS::GetBracketsEnd( const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) {
ASSERT( ( *begin )->m_type == SourceElement::ET_BLOCK, "expected opening bracket" );
std::stack< uint8_t > brackets = {};
source_elements_t::const_iterator it = begin;
Expand Down Expand Up @@ -797,11 +797,11 @@ const GJS::source_elements_t::const_iterator GJS::GetBracketsEnd( const source_e

#ifdef DEBUG

void GJS::LogElement( const std::string& prefix, const SourceElement* element ) const {
void JS::LogElement( const std::string& prefix, const SourceElement* element ) const {
Log( prefix + element->ToString() );
}

void GJS::LogElements( const std::string& label, const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) const {
void JS::LogElements( const std::string& label, const source_elements_t::const_iterator& begin, const source_elements_t::const_iterator& end ) const {
Log( label + "(" );
for ( auto it = begin ; it != end ; it++ ) {
LogElement( " ", *it );
Expand Down
4 changes: 2 additions & 2 deletions src/gse/parser/GJS.h → src/gse/parser/JS.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
namespace gse {
namespace parser {

CLASS( GJS, Parser )
CLASS( JS, Parser )

GJS( const std::string& filename, const std::string& source, const size_t initial_line_num );
JS( const std::string& filename, const std::string& source, const size_t initial_line_num );

protected:
void GetElements( source_elements_t& elements ) override;
Expand Down
6 changes: 3 additions & 3 deletions src/gse/tests/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gse/program/While.h"
#include "gse/program/Try.h"
#include "gse/program/Catch.h"
#include "gse/parser/GJS.h"
#include "gse/parser/JS.h"

namespace gse {
namespace tests {
Expand Down Expand Up @@ -288,9 +288,9 @@ void AddParserTests( task::gsetests::GSETests* task ) {
};

task->AddTest(
"test if GJS parser produces valid output",
"test if JS parser produces valid output",
GT( validate_program ) {
parser::GJS parser( GetTestFilename(), GetTestSource(), 1 );
parser::JS parser( GetTestFilename(), GetTestSource(), 1 );
const auto* program = parser.Parse();
const auto result = validate_program( program );
if ( program ) {
Expand Down
4 changes: 2 additions & 2 deletions src/gse/tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void AddTests( task::gsetests::GSETests* task ) {
}

const std::string& GetTestFilename() {
const static std::string filename = "test.gjs";
const static std::string filename = "<TEST>.gls.js";
return filename;
}

Expand Down Expand Up @@ -1898,7 +1898,7 @@ const std::string& GetExpectedResult() {
"BEFORE EXCEPTION\n"
"failfunc\n"
"CAUGHT TestError : something happened\n"
"array{string{\tat test.gjs:116: throw TestError('something happened');},string{\tat test.gjs:118: failfunc();}}\n"
"array{string{\tat <TEST>.gls.js:116: throw TestError('something happened');},string{\tat <TEST>.gls.js:118: failfunc();}}\n"
"bye!\n";
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ int main( const int argc, const char* argv[] ) {
NEWV( task, task::gsetests::GSETests );
scheduler.AddTask( task );
}
else if ( config.HasDebugFlag( config::Config::DF_GSE_PROMPT_GJS ) ) {
NEWV( task, task::gseprompt::GSEPrompt, "gjs" );
else if ( config.HasDebugFlag( config::Config::DF_GSE_PROMPT_JS ) ) {
NEWV( task, task::gseprompt::GSEPrompt, "js" );
scheduler.AddTask( task );
}

Expand Down
2 changes: 1 addition & 1 deletion src/task/gseprompt/GSEPrompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void GSEPrompt::ProcessInput() {
}

auto* parser = m_gse.GetParser(
"input." + m_syntax, source, m_is_tty
"<STDIN>.gls." + m_syntax, source, m_is_tty
? m_lines_count
: 1
);
Expand Down
17 changes: 15 additions & 2 deletions src/util/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ using namespace std;
#define PATH_SEPARATOR "/"
#endif

#define EXTENSION_SEPARATOR '.'

#ifdef DEBUG
#define Log( _text ) std::cout << "<Util::FS> " << (_text) << std::endl
#else
Expand Down Expand Up @@ -111,7 +113,7 @@ const std::string FS::GetFilteredPath( const std::string& path ) {
if ( path == "." ) {
return "";
}
while ( pos + 1 < path.size() && path[ pos ] == '.' && path[ pos + 1 ] == '/' ) {
while ( pos + 1 < path.size() && path[ pos ] == EXTENSION_SEPARATOR && path[ pos + 1 ] == '/' ) {
pos += 2;
}
#endif
Expand All @@ -127,7 +129,7 @@ const std::string FS::GetAbsolutePath( const std::string& path ) {
}

const std::string FS::GetExtension( const std::string& path ) {
const auto pos = path.rfind( '.' );
const auto pos = path.rfind( EXTENSION_SEPARATOR );
if ( pos == std::string::npos ) {
return "";
}
Expand All @@ -136,6 +138,17 @@ const std::string FS::GetExtension( const std::string& path ) {
}
}

const std::vector< std::string > FS::GetExtensions( const std::string& path ) {
std::vector< std::string > result = {};
size_t pos, last_pos = path.size();
while ( ( pos = path.rfind( EXTENSION_SEPARATOR, last_pos - 1 ) ) != std::string::npos ) {
result.push_back( path.substr( pos, last_pos - pos ) );
last_pos = pos;
}
std::reverse( result.begin(), result.end() );
return result;
}

const bool FS::Exists( const string& path ) {
return std::filesystem::exists( path );
}
Expand Down
1 change: 1 addition & 0 deletions src/util/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CLASS( FS, Util )
static const std::string GetFilteredPath( const std::string& path );
static const std::string GetAbsolutePath( const std::string& path );
static const std::string GetExtension( const std::string& path );
static const std::vector< std::string > GetExtensions( const std::string& path );

static const bool Exists( const std::string& path );
static const bool IsFile( const std::string& path );
Expand Down

0 comments on commit 6728edd

Please sign in to comment.