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

Serializes a stela tree back to stela source text. More...

#include <stelaWriter.hpp>

Inheritance diagram for by::stelaWriter:
by::stelaVisitor by::typeProvidable by::clonable

Public Member Functions

std::string write (stela &root)
 Serializes root and its subtree to a string.
 
nbool writeFile (stela &root, const std::string &path)
 Serializes root and writes the result to path (LF, UTF-8, non-atomic).
 
nbool writeFile (stela &root, const nchar *path) BY_SIDE_FUNC(path
 
nbool writeFile (root, std::string(path))
 
- Public Member Functions inherited from by::stelaVisitor
void work (stela &root)
 
virtual void onLeave (const stelaVisitInfo &i, valStela &it)
 
virtual void visit (const stelaVisitInfo &i, stela &it)
 
virtual nbool onVisit (const stelaVisitInfo &i, stela &it)
 
virtual void onLeave (const stelaVisitInfo &i, stela &it)
 
virtual void onTraverse (const stelaVisitInfo &i, stela &it)
 
- Public Member Functions inherited from by::typeProvidable
nbool operator== (const me &rhs) const
 
nbool operator!= (const me &rhs) const
 
virtual const typegetType () const =0
 
nbool isSub (const type &it) const
 
nbool isSub (const type *it) const BY_SIDE_FUNC(isSub)
 
nbool isSub (const me &it) const
 
nbool isSub (const me *it) const BY_SIDE_FUNC(isSub)
 
nbool isSuper (const type &it) const
 
nbool isSuper (const type *it) const BY_SIDE_FUNC(isSuper)
 
nbool isSuper (const me &it) const
 
nbool isSuper (const me *it) const BY_SIDE_FUNC(isSuper)
 
template<typename T >
nint isSub () const
 
template<typename T >
nint isSuper () const
 
template<typename T >
Tcast ()
 
template<typename T >
const Tcast () const BY_CONST_FUNC(cast< T >()) virtual void *cast(const type &to)
 Safe cast to target type using type hierarchy information.
 
const voidcast (const type &to) const BY_CONST_FUNC(cast(to)) void *cast(const type *it) BY_SIDE_FUNC(cast)
 
- Public Member Functions inherited from by::clonable
virtual meclone () const =0
 
virtual mecloneDeep () const
 
virtual void onCloneDeep (const me &from)
 

Public Attributes

nbool false
 

Protected Member Functions

nbool onVisit (const stelaVisitInfo &i, rootStela &it) override
 
nbool onVisit (const stelaVisitInfo &i, defStela &it) override
 
nbool onVisit (const stelaVisitInfo &i, valStela &it) override
 
nbool onVisit (const stelaVisitInfo &i, strStela &it) override
 
nbool onVisit (const stelaVisitInfo &i, arrStela &it) override
 
void onLeave (const stelaVisitInfo &i, arrStela &it) override
 

Detailed Description

Serializes a stela tree back to stela source text.

Implemented as a stelaVisitor. writes a canonical form.

What IS preserved: values, structure, child order, comments, and the spelling of number literals (0xFF stays 0xFF). Round-trip parse -> edit -> write -> parse gives the same value tree, and write -> parse -> write produces the same string (canonical fixed point).

What is NOT preserved:

  • original indentation width and any hand alignment: indentation is generated from depth, so a node inserted into a hand-written block still lands right
  • blank lines
  • where a comment closing a block sits: it becomes the prefix of the node after the block

Root handling

The writer serializes a compilation unit, so it accepts only a rootStela: handing write() or writeFile() any other node is rejected (empty string / false). The rootStela itself is never emitted as def <name> — only its children are — matching the shape of stela source, where the top level is implicit.

Usage

std::string src = stelaWriter().write(*root);
stelaWriter().writeFile(*root, "out.by");
Serializes a stela tree back to stela source text.
Definition stelaWriter.hpp:35
std::string write(stela &root)
Serializes root and its subtree to a string.
nbool writeFile(stela &root, const std::string &path)
Serializes root and writes the result to path (LF, UTF-8, non-atomic).
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34

Member Function Documentation

◆ onVisit()

nbool by::stelaWriter::onVisit ( const stelaVisitInfo & i,
valStela & it )
overrideprotectedvirtual

Reimplemented from by::stelaVisitor.

◆ writeFile()

nbool by::stelaWriter::writeFile ( stela & root,
const std::string & path )

Serializes root and writes the result to path (LF, UTF-8, non-atomic).

Returns
true on success. false if the file could not be opened for writing.

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