Skip to content

Commit

Permalink
fix(ASTOkenRibbon): logging
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Jan 15, 2025
1 parent 21e0dcd commit bbd7080
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 deletions rake/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def new_target_from_base(name, type)
]

target.linker_flags |= [
"-s EMBIND_STD_STRING_IS_UTF8=0",
"-s ALLOW_MEMORY_GROWTH",
"-s MIN_WEBGL_VERSION=2",
"-s MAX_WEBGL_VERSION=2",
Expand Down
56 changes: 35 additions & 21 deletions src/ndbl/core/ASTTokenRibbon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ ASTToken & ASTTokenRibbon::push(ASTToken &_token)

std::string ASTTokenRibbon::to_string()const
{
const char* TO_VISIT = ".";
const char* IN_TRANSACTION = "v";
const char* CURRENT = "c";

tools::string out;
out.append(RESET);

Expand All @@ -35,26 +31,44 @@ std::string ASTTokenRibbon::to_string()const

for (const ASTToken& token : m_tokens)
{
bool inside_transaction = !m_transaction.empty()
&& token.m_index >= m_transaction.top()
&& token.m_index <= m_cursor;

bool is_current = token.m_index == m_cursor;
const char* state = is_current ? CURRENT
: inside_transaction ? IN_TRANSACTION
: TO_VISIT;
tools::string512 line;
line.append_fmt("%s%5llu) %s \"%s\"" RESET "\n",
inside_transaction ? BOLDBLACK : "",
token.m_index,
state,
token.word_to_string().c_str());
out.append( line.c_str() );

if ( token.m_index == 0 )
{
line.append("B"); // begin
}
else if ( token.m_index == m_tokens.back().m_index )
{
line.append("E"); // end
}
else
{
line.append("|"); // default
}

if ( !m_transaction.empty()
&& token.m_index >= m_transaction.top()
&& token.m_index <= m_cursor )
{
line.append("T"); // transaction
}
else
{
line.append("."); // no transaction
}

const std::string word = token.word_to_string();
line.append_fmt("%5zu) \"%s\"", token.m_index, word.c_str() );

if ( token.m_index == m_cursor )
{
line.append(" [c]"); // current
}

out.append(line.c_str());
out.append("\n");
}

bool is_current = m_tokens.size() == m_cursor;
out.append_fmt(" END) %s " RESET "\n", is_current ? CURRENT : " ");

return out.c_str();
}

Expand Down

0 comments on commit bbd7080

Please sign in to comment.