Skip to content

Commit

Permalink
Tweak parse tree to treat uninit and bools as literals
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Jan 30, 2024
1 parent f8f2510 commit e1852e3
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 436 deletions.
819 changes: 404 additions & 415 deletions lib/Parser/EscriptGrammar/EscriptParser.cpp

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions lib/Parser/EscriptGrammar/EscriptParser.g4
Expand Up @@ -284,9 +284,6 @@ primary
| parExpression
| functionCall
| scopedFunctionCall
| UNINIT
| BOOL_TRUE
| BOOL_FALSE
| IDENTIFIER
| functionReference
| explicitArrayInitializer
Expand Down Expand Up @@ -387,7 +384,9 @@ arrayInitializer
literal
: integerLiteral
| floatLiteral
| boolLiteral
| STRING_LITERAL
| UNINIT
;

interpolatedString
Expand Down
5 changes: 2 additions & 3 deletions lib/Parser/EscriptGrammar/EscriptParser.h
Expand Up @@ -1188,9 +1188,6 @@ class EscriptParser : public antlr4::Parser {
ParExpressionContext *parExpression();
FunctionCallContext *functionCall();
ScopedFunctionCallContext *scopedFunctionCall();
antlr4::tree::TerminalNode *UNINIT();
antlr4::tree::TerminalNode *BOOL_TRUE();
antlr4::tree::TerminalNode *BOOL_FALSE();
antlr4::tree::TerminalNode *IDENTIFIER();
FunctionReferenceContext *functionReference();
ExplicitArrayInitializerContext *explicitArrayInitializer();
Expand Down Expand Up @@ -1547,7 +1544,9 @@ class EscriptParser : public antlr4::Parser {
virtual size_t getRuleIndex() const override;
IntegerLiteralContext *integerLiteral();
FloatLiteralContext *floatLiteral();
BoolLiteralContext *boolLiteral();
antlr4::tree::TerminalNode *STRING_LITERAL();
antlr4::tree::TerminalNode *UNINIT();

virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/ast/UninitializedValue.cpp
Expand Up @@ -6,7 +6,7 @@
namespace Pol::Bscript::Compiler
{
UninitializedValue::UninitializedValue( const SourceLocation& source_location )
: Expression( source_location )
: Value( source_location )
{
}

Expand Down
4 changes: 2 additions & 2 deletions pol-core/bscript/compiler/ast/UninitializedValue.h
@@ -1,11 +1,11 @@
#ifndef POLSERVER_UNINITIALIZEDVALUE_H
#define POLSERVER_UNINITIALIZEDVALUE_H

#include "bscript/compiler/ast/Expression.h"
#include "bscript/compiler/ast/Value.h"

namespace Pol::Bscript::Compiler
{
class UninitializedValue : public Expression
class UninitializedValue : public Value
{
public:
explicit UninitializedValue( const SourceLocation& );
Expand Down
12 changes: 0 additions & 12 deletions pol-core/bscript/compiler/astbuilder/ExpressionBuilder.cpp
Expand Up @@ -564,18 +564,6 @@ std::unique_ptr<Expression> ExpressionBuilder::primary( EscriptParser::PrimaryCo
{
return interpolate_string( inter_string );
}
else if ( ctx->UNINIT() )
{
return std::make_unique<UninitializedValue>( location_for( *ctx ) );
}
else if ( ctx->BOOL_TRUE() )
{
return std::make_unique<BooleanValue>( location_for( *ctx ), true );
}
else if ( ctx->BOOL_FALSE() )
{
return std::make_unique<BooleanValue>( location_for( *ctx ), false );
}

location_for( *ctx ).internal_error( "unhandled primary expression" );
}
Expand Down
9 changes: 9 additions & 0 deletions pol-core/bscript/compiler/astbuilder/ValueBuilder.cpp
Expand Up @@ -8,6 +8,7 @@
#include "bscript/compiler/ast/FunctionReference.h"
#include "bscript/compiler/ast/IntegerValue.h"
#include "bscript/compiler/ast/StringValue.h"
#include "bscript/compiler/ast/UninitializedValue.h"
#include "bscript/compiler/astbuilder/BuilderWorkspace.h"
#include "bscript/compiler/file/SourceLocation.h"
#include "bscript/compiler/model/FunctionLink.h"
Expand Down Expand Up @@ -185,6 +186,14 @@ std::unique_ptr<Value> ValueBuilder::value( EscriptParser::LiteralContext* ctx )
{
return float_value( float_literal );
}
else if ( auto bool_literal = ctx->boolLiteral() )
{
return bool_value( bool_literal );
}
else if ( ctx->UNINIT() )
{
return std::make_unique<UninitializedValue>( location_for( *ctx ) );
}
else
{
location_for( *ctx ).internal_error( "unhandled literal" );
Expand Down

0 comments on commit e1852e3

Please sign in to comment.