In the example below, RSML is used in the context of a package manager. The user packaging their app adds a .rsea file that the package manager evaluates. Each logic path of the file takes the package manager to a different script, given how different build/installation setup might be given the OS and CPU architecture. This example only exemplifies how RSMl comes into play, it is not a guide on how to create package managers.
usingSystem.IO;usingRSML.Parser;/* * Adapted from rsml-demos * For the full code, see https://github.com/OceanApocalypseStudios/rsml-demos/*/stringPACKAGE_NAME="Example Package";// Reading from the file// (Assume we're passed a FileInfo named rsmlFile)stringdata=File.ReadAllText(rsmlFile.FullName);// Creating the parserRSParserparser=new(data);// Setting up the parser to match official-25parser.DefineOperator(OperatorType.Primary,"->");parser.DefineOperator(OperatorType.Secondary,"||");parser.DefineOperator(OperatorType.Tertiary,"^!");parser.RegisterAction(OperatorType.Secondary,(_,value)=>Console.WriteLine(value));parser.RegisterAction(OperatorType.Tertiary,(_,value)=>thrownewRSMLRuntimeException(value));// Parsingstring?result=parser.EvaluateRSML(true)??thrownewEvaluateException($"No setup scripts found for this machine in {PACKAGE_NAME}.");FileInfofile=new(result);return!file.Exists?thrownewFileNotFoundException("Such script does not exist."):file;
fromrsml_pythonimportRedSeaDocument,RedSeaCLIExecutable# Creating the executablePATH_TO_EXE:str=...# insert path hereRS_EXE:RedSeaCLIExecutable=RedSeaCLIExecutable(PATH_TO_EXE)# Creating the documentdoc:RedSeaDocument=RedSeaDocument()doc.load_from_string(data)# Loading the document into the executableRS_EXE.load_document(doc)# Parsingresult:str=RS_EXE.evaluate_document(expands_any=True)# Checking the resultifresult.startswith(("[WARNING]","[ERROR]")):raiseValueError(f"No setup scripts found for this machine in {PACKAGE_NAME}.")