Loading...
Searching...
No Matches
by::stelaParser Class Reference

Parser for stela configuration language. More...

#include <stelaParser.hpp>

Inheritance diagram for by::stelaParser:
by::stelaTokenScanable

Public Member Functions

tstr< stelaparse (const std::string &codes)
 Parses the given string of stela code.
 
tstr< stelaparse (const nchar *codes)
 Parses the given C-style string of stela code.
 
tstr< stelaparseFromFile (const std::string &path)
 Parses stela code from the specified file path.
 
tstr< stelaparseFromFile (const nchar *path)
 Parses stela code from the specified C-style file path.
 
stelaTokenDispatchergetDispatcher ()
 
std::vector< ncnt > & getIndents ()
 
nbool isInit () const
 
template<typename T >
void setScan ()
 Sets the scanning mode for the lexer.
 
void rel ()
 
int pushState (int newState)
 Pushes a new Flex scanner state onto the state stack.
 
int popState ()
 Pops a Flex scanner state from the state stack.
 
nint onScan (stelaParser &ps, ZZSTYPE *val, ZZLTYPE *loc, zzscan_t scanner, nbool &isBypass) override
 Handles scanning for the lexer, overriding the base stelaTokenScanable behavior.
 
nint onTokenEndOfFile ()
 Handles the end-of-file token.
 
nint onTokenColon (nint tok)
 Handles the colon token.
 
nint onTokenNewLine (nint tok)
 Handles the newline token.
 
nint onTokenComma (nint tok)
 Handles the comma token.
 
nint onIndent (ncnt col, nint tok)
 Handles an increase in indentation.
 
nint onDedent (ncnt col, nint tok)
 Handles a decrease in indentation.
 
nint onIgnoreIndent (nint tok)
 Handles ignoring indentation (e.g., for inline blocks).
 
nchar onScanUnexpected (const nchar *token)
 Handles an unexpected token encountered during scanning.
 
stelaonDefBlock (stela *stmt)
 
stelaonDefBlock (stela *blk, stela *stmt)
 
stelaonDefBlock ()
 
template<typename T >
stelaonPrimitive (const T &arg)
 Creates a valStela object from a primitive value.
 
verStelaonVer (const std::string &version)
 
stelaonDefProp (const std::string &name, stela &rhs)
 
stelaonDefAssign (const std::string &name, stela *rhs)
 
stelaonDefOrigin (const std::string &name, stela &blk)
 
stelaonDefArray (const stela &elem)
 
stelaonDefArray (stela &as, const stela &elem)
 
stelaonCompilationUnit (stela *blk)
 
void onParseErr (const std::string &msg, const nchar *symbolName)
 Handles a parse error, reporting the message and the symbol where the error occurred.
 
void report (const std::string &msg)
 Reports a message, typically an error or warning, encountered during parsing.
 
nint onScan (stelaParser &ps, ZZSTYPE *val, ZZLTYPE *loc, zzscan_t scanner)
 Default entry point for token scanning.
 
virtual nint onScan (stelaParser &ps, ZZSTYPE *yylval, ZZLTYPE *loc, zzscan_t yyscanner, nbool &isBypass)=0
 Pure virtual method for concrete token scanning implementations.
 
- Public Member Functions inherited from by::stelaTokenScanable
nint onScan (stelaParser &ps, ZZSTYPE *val, ZZLTYPE *loc, zzscan_t scanner)
 Default entry point for token scanning.
 

Detailed Description

Parser for stela configuration language.

Entry point for the Stela parsing component. Specify scripts through parse() or parseFromFile(), and the parsed result is returned in Stela structure.

Similar structure to byeol parser

Since the stela language itself is a specialized language of byeol, the parser is also based on the byeol language parser. Since it's a less complex language than byeol, it's recommended to examine this parser code before looking at the core module.

- bison - stelaParser structure

Uses flex and bison, with flex named lowscanner and bison named lowparser. These low-level scanner and parser exist only within the parser component and are never exposed externally. When stelaParser::parse() executes, it runs lowscanner. lowscanner tokenizes and passes tokens to lowparser. When lowparser matches rules on received tokens, it passes events back to stelaParser. Therefore, stelaParser's functions starting with on are event handling functions that define how to create nodes and build the AST.

Indentation rule

Like the byeol language, stela applies the offside rule, making it very sensitive to indentation. Unlike typical languages, it must count whitespace after newlines. Once indentation is confirmed and determines which scope the code line belongs to, whitespace should be ignored afterward.

Member Function Documentation

◆ onDedent()

nint by::stelaParser::onDedent ( ncnt col,
nint tok )

Handles a decrease in indentation.

Parameters
colThe column count of the new indentation level.
tokThe token ID that triggered the dedentation.
Returns
The token ID for DEDENT.

◆ onIgnoreIndent()

nint by::stelaParser::onIgnoreIndent ( nint tok)

Handles ignoring indentation (e.g., for inline blocks).

Parameters
tokThe token ID.
Returns
The token ID.

◆ onIndent()

nint by::stelaParser::onIndent ( ncnt col,
nint tok )

Handles an increase in indentation.

Parameters
colThe column count of the new indentation level.
tokThe token ID that triggered the indentation.
Returns
The token ID for INDENT.

◆ onParseErr()

void by::stelaParser::onParseErr ( const std::string & msg,
const nchar * symbolName )

Handles a parse error, reporting the message and the symbol where the error occurred.

Parameters
msgThe error message.
symbolNameThe name of the symbol causing the error.

◆ onPrimitive()

template<typename T >
stela * by::stelaParser::onPrimitive ( const T & arg)
inline

Creates a valStela object from a primitive value.

Template Parameters
TThe primitive type of the argument (e.g., int, bool, string).
Parameters
argThe primitive value.
Returns
A pointer to a newly created valStela instance.

◆ onScan() [1/3]

nint by::stelaTokenScanable::onScan ( stelaParser & ps,
ZZSTYPE * val,
ZZLTYPE * loc,
zzscan_t scanner )

Default entry point for token scanning.

This non-virtual method acts as a wrapper that internally dispatches to the pure virtual onScan method, which must be implemented by concrete scanner strategies.

Parameters
psThe stelaParser instance.
valThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
scannerThe Flex scanner instance.
Returns
The token ID.

◆ onScan() [2/3]

nint by::stelaParser::onScan ( stelaParser & ps,
ZZSTYPE * val,
ZZLTYPE * loc,
zzscan_t scanner,
nbool & isBypass )
overridevirtual

Handles scanning for the lexer, overriding the base stelaTokenScanable behavior.

Parameters
psThe stelaParser instance.
valThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
scannerThe Flex scanner instance.
isBypassFlag indicating if indentation bypass is active.
Returns
The token ID.

Implements by::stelaTokenScanable.

◆ onScan() [3/3]

virtual nint by::stelaTokenScanable::onScan ( stelaParser & ps,
ZZSTYPE * yylval,
ZZLTYPE * loc,
zzscan_t yyscanner,
nbool & isBypass )
virtual

Pure virtual method for concrete token scanning implementations.

Parameters
psThe stelaParser instance.
yylvalThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
yyscannerThe Flex scanner instance.
isBypassFlag indicating if indentation bypass is active.
Returns
The token ID.

Implements by::stelaTokenScanable.

◆ onScanUnexpected()

nchar by::stelaParser::onScanUnexpected ( const nchar * token)

Handles an unexpected token encountered during scanning.

Parameters
tokenThe unexpected token string.
Returns
The token ID for an error.

◆ onTokenColon()

nint by::stelaParser::onTokenColon ( nint tok)

Handles the colon token.

Parameters
tokThe token ID of the colon.
Returns
The token ID.

◆ onTokenComma()

nint by::stelaParser::onTokenComma ( nint tok)

Handles the comma token.

Parameters
tokThe token ID of the comma.
Returns
The token ID.

◆ onTokenEndOfFile()

nint by::stelaParser::onTokenEndOfFile ( )

Handles the end-of-file token.

Returns
The token ID for end-of-file.

◆ onTokenNewLine()

nint by::stelaParser::onTokenNewLine ( nint tok)

Handles the newline token.

Parameters
tokThe token ID of the newline.
Returns
The token ID.

◆ parse() [1/2]

tstr< stela > by::stelaParser::parse ( const nchar * codes)

Parses the given C-style string of stela code.

Parameters
codesThe stela code as a C-style string.
Returns
A tstr to the parsed stela AST root object, or null on error.

◆ parse() [2/2]

tstr< stela > by::stelaParser::parse ( const std::string & codes)

Parses the given string of stela code.

Parameters
codesThe stela code as a string.
Returns
A tstr to the parsed stela AST root object, or null on error.

◆ parseFromFile() [1/2]

tstr< stela > by::stelaParser::parseFromFile ( const nchar * path)

Parses stela code from the specified C-style file path.

Parameters
pathThe path to the file containing stela code.
Returns
A tstr to the parsed stela AST root object, or null on error.

◆ parseFromFile() [2/2]

tstr< stela > by::stelaParser::parseFromFile ( const std::string & path)

Parses stela code from the specified file path.

Parameters
pathThe path to the file containing stela code.
Returns
A tstr to the parsed stela AST root object, or null on error.

◆ popState()

int by::stelaParser::popState ( )

Pops a Flex scanner state from the state stack.

Returns
The previous state.

◆ pushState()

int by::stelaParser::pushState ( int newState)

Pushes a new Flex scanner state onto the state stack.

Parameters
newStateThe new state to push.
Returns
The new state.

◆ report()

void by::stelaParser::report ( const std::string & msg)

Reports a message, typically an error or warning, encountered during parsing.

Parameters
msgThe message to report.

◆ setScan()

template<typename T >
void by::stelaParser::setScan ( )
inline

Sets the scanning mode for the lexer.

Template Parameters
TThe type of the scanner strategy (e.g., normalScan, indentScan).

The documentation for this class was generated from the following file: