ostrat.pParse

This is the RSON package. Readable Succinct Object Notation. It could be just as accurately be described as Readable Succinct Data Notation, but that wouldn't scan as well and indicate it as a better replacement for JSON. RSON uses the standard semicolon separated statements combined with multilevel bracket hierarchy syntax familiar from C, C++, Java and JavaScript. Its main innovations over JSON and XML are allowing statements to be partitioned into comma delineated clauses, the empty statement, the empty clause and type inference. It uses a context free operator precedence hierarchy, with the exception of allowing the 4 ( - + ~ !) operator to be used as prefix operators. Beyond this it generally follows Scala syntax where this doesn't conflict with the preceding rules. Unlike Scala statements must finish with a semicolon unless it is the last statement of a file or a bracket block. Allowing statements to end with a newline introduces horrendous ambiguities unless one is willing to go completely down the significant whitespace route and I'm not sure if that could work even work for such a general purpose basic syntax.

The above allows it to combine a high level of human readability, succinctness, non-programmer / non-expert write-ability, programmer flexibility and composability and fast-parsing. The initial motivating use case was strategy games, which require huge amounts of modable date files. XML and JSON, the current defaults are simply not fit for purpose. RSON aims to break down the walls between game player, game modder, professional game artist, professional game scripter, professional imperative programming wizards in languages such as C / C++ and Rust and professional functional programming wizards in languages such as Scala, Haskell and Idris.

Type members

Classlikes

case class AsignExpr(left: AssignMemExpr, asToken: AsignToken, right: AssignMemExpr) extends CompoundExpr
case class AsignToken(startPosn: TextPosn) extends BlockMemToken with StatementMem

A + or - infix Operator token

A + or - infix Operator token

trait AssignMem extends StatementMem

An Assignment member can appear in the expressions either side of an asignment operator.

An Assignment member can appear in the expressions either side of an asignment operator.

trait AssignMemExpr extends Expr with AssignMem

An expression that is a member of the right oe left side of an assignment expression.

An expression that is a member of the right oe left side of an assignment expression.

trait BlockMem extends TextSpan

This trait includes all the tokens except braces plus the Bracket syntactic blocks. The Block in the name block member is either the top level statements in the file or the statements with in a bracket block. Conceptually the source file is considered a special case of bracket block where the beginning of substitutes for the opening bracket and the end of file substitutes for the closing bracket. BlockMember has only two sub traits StatementMember and SemiToken. So a sequence of TokenOrBlocks is simply a series of tokens which has been parsed into Blocks.

This trait includes all the tokens except braces plus the Bracket syntactic blocks. The Block in the name block member is either the top level statements in the file or the statements with in a bracket block. Conceptually the source file is considered a special case of bracket block where the beginning of substitutes for the opening bracket and the end of file substitutes for the closing bracket. BlockMember has only two sub traits StatementMember and SemiToken. So a sequence of TokenOrBlocks is simply a series of tokens which has been parsed into Blocks.

trait BlockMemToken extends BlockMem with Token

Token that is member of a block. Includes all tokens except the brace tokens.

Token that is member of a block. Includes all tokens except the brace tokens.

trait BlockRaw
sealed trait Braces
sealed trait BracketCloseToken extends BracketToken

A closing bracket Token, The ']', ']' or ')' characters are BracketCloseTokens.

A closing bracket Token, The ']', ']' or ')' characters are BracketCloseTokens.

sealed trait BracketOpen extends BracketToken

An opening Brace, '{', '[' or '('.

An opening Brace, '{', '[' or '('.

sealed trait BracketToken extends Token
case class BracketedRaws(statements: Arr[TextSpan], braces: Braces, startBracket: TextPosn, endBracket: TextPosn)
case class BracketedStatements(statements: Statements, braces: Braces, startBracket: TextPosn, endBracket: TextPosn) extends BlockStatements
case class CharToken(startPosn: TextPosn, char: Char) extends ClauseMemExprToken
case class Clause(expr: ClauseMemExpr, optComma: OptRef[CommaToken]) extends TextSpan

Statements in RCON can be unclaused or multi comma separated. The empty Clause just contains a comma. The comma at the end of the last Clause of a Statement is optional.

Statements in RCON can be unclaused or multi comma separated. The empty Clause just contains a comma. The comma at the end of the last Clause of a Statement is optional.

trait ClauseMem extends AssignMem

I think its helpful to have an expression member trait for syntax that is not expressions. So I don't think it would be helpful if say an opening brace was an expression. All Expressions are Expression members.

I think its helpful to have an expression member trait for syntax that is not expressions. So I don't think it would be helpful if say an opening brace was an expression. All Expressions are Expression members.

An expression that can be a member of a Clause.

An expression that can be a member of a Clause.

A Token that is an Expression. Most tokens are expressions, but some are not such as braces, commas and semicolons.

A Token that is an Expression. Most tokens are expressions, but some are not such as braces, commas and semicolons.

A Token that can be a member of a Clause.

A Token that can be a member of a Clause.

Intended as a common trait for Clauses and Unclaused Statements.

Intended as a common trait for Clauses and Unclaused Statements.

case class ClausesExpr(clauses: Arr[Clause]) extends ExprSeqNonEmpty
case class CommaToken(startPosn: TextPosn) extends EmptyExprToken with AssignMem

A compound expression. The traits sole purpose is to give an Expr, the start and end text positions from its first and last components.

A compound expression. The traits sole purpose is to give an Expr, the start and end text positions from its first and last components.

A compound expression. The traits sole purpose is to give an Expr, the start and end text positions from its first and last components.

A compound expression. The traits sole purpose is to give an Expr, the start and end text positions from its first and last components.

object CurlyBlock
case object CurlyBraces extends Braces
case class CurlyCloseToken(startPosn: TextPosn) extends BracketCloseToken
case class CurlyOpenToken(startPosn: TextPosn) extends BracketOpen
final case class DeciFracNegToken(startPosn: TextPosn, dgs1: String, dgs2: String, trail: String) extends DeciFracToken

Negative Decimal fractional fixed point number token.

Negative Decimal fractional fixed point number token.

final case class DeciFracPosToken(startPosn: TextPosn, dgs1: String, dgs2: String, trail: String) extends DeciFracToken with ValidPosFracToken with DigitSeqsCode

Positive Decimal fractional fixed point token.

Positive Decimal fractional fixed point token.

Decimal fractional fixed point token.

Decimal fractional fixed point token.

Sequence of point separated number sequences. Includes fixed point decimal numbers, IPv4 notation nad version nunbers.

Sequence of point separated number sequences. Includes fixed point decimal numbers, IPv4 notation nad version nunbers.

case class Dot2Token(startPosn: TextPosn) extends ClauseMemToken

The double Dot or Stop Token.

The double Dot or Stop Token.

case class Dot3Token(startPosn: TextPosn) extends ClauseMemToken

The triple Dot or Stop Token.

The triple Dot or Stop Token.

case class DotToken(startPosn: TextPosn) extends ClauseMemToken

The Dot or Stop Token.

The Dot or Stop Token.

Empty Clause class, represented by just a comma.

Empty Clause class, represented by just a comma.

Companion:
object

Factory object for the empty clause. Not sure if it is necessary

Factory object for the empty clause. Not sure if it is necessary

Companion:
class

The Semicolon of the Empty statement is the expression of this special case of the unclaused statement

The Semicolon of the Empty statement is the expression of this special case of the unclaused statement

Companion:
object
Companion:
class
trait Expr extends BlockMem with StatementMem

The fundamental expression trait. As it currently stands properly formed Statements either is empty or contains an expression or a sequence of clauses that contain each contain an expression.

The fundamental expression trait. As it currently stands properly formed Statements either is empty or contains an expression or a sequence of clauses that contain each contain an expression.

trait Expr0 extends Expr1
trait Expr1 extends ClauseMemExpr
trait ExprSeq extends ClauseMemExpr

An ExprSeq can be a sequence of Statements or a Sequence of Clauses.

An ExprSeq can be a sequence of Statements or a Sequence of Clauses.

An ExprSeq can be a sequence of Statements or a Sequence of Clauses.

An ExprSeq can be a sequence of Statements or a Sequence of Clauses.

case class FileStatements(statements: Arr[Statement]) extends BlockStatements
final case class FloatPtNegToken(startPosn: TextPosn, dgs1: String, dgs2: String, expPos: Boolean, expStr: String, trail: String) extends FloatPtToken

Negative Floating point fractional number token.

Negative Floating point fractional number token.

final case class FloatPtPosToken(startPosn: TextPosn, dgs1: String, dgs2: String, expPos: Boolean, expStr: String, trail: String) extends FloatPtToken

Positive Floaiting point fractional number token.

Positive Floaiting point fractional number token.

case class HashAlphaToken(startPosn: TextPosn, srcStr: String) extends ClauseMemExprToken

The purpose of this token is for use at the beginning of a file, to make the the rest of the Statements, sub-statements. As if they were the statements inside parenthesis.

The purpose of this token is for use at the beginning of a file, to make the the rest of the Statements, sub-statements. As if they were the statements inside parenthesis.

case class IdentLowerBase32OnlyToken(startPosn: TextPosn, srcStr: String) extends IdentLowerToken with ValidRawBase32IntToken

An identifier beginning with a lowercase that is not a valid raw Base32 or hexadecimal token.

An identifier beginning with a lowercase that is not a valid raw Base32 or hexadecimal token.

case class IdentLowerHexaToken(startPosn: TextPosn, srcStr: String) extends IdentLowerToken

An identifier beginning with a lowercase that is a valid raw hexadecimal and raw Base32 token.

An identifier beginning with a lowercase that is a valid raw hexadecimal and raw Base32 token.

case class IdentLowerOnlyToken(startPosn: TextPosn, srcStr: String) extends IdentLowerToken

An identifier beginning with a lowercase that is not a valid raw Base32 or hexadecimal token.

An identifier beginning with a lowercase that is not a valid raw Base32 or hexadecimal token.

A valid identifier beginning with a lowercase letter or an underscore character.

A valid identifier beginning with a lowercase letter or an underscore character.

Companion:
object

Extractor function object for IdentLowerToken type.

Extractor function object for IdentLowerToken type.

Companion:
class
case class IdentUnderToken(startPosn: TextPosn, srcStr: String) extends IdentifierToken

An identifier token beginning with an underscore character.

An identifier token beginning with an underscore character.

case class IdentUpperBase32OnlyToken(startPosn: TextPosn, srcStr: String) extends IdentUpperBase32Token

An alphanumeric token beginning with an alphabetic character that most commonly represents a name of something, but is also a valid raw Base32 Token.

An alphanumeric token beginning with an alphabetic character that most commonly represents a name of something, but is also a valid raw Base32 Token.

case class IdentUpperHexaToken(startPosn: TextPosn, srcStr: String) extends IdentUpperBase32Token with ValidRawHexaNatToken

An identifier beigning with an upper case letter that is also a valid raw hexadecimal token.

An identifier beigning with an upper case letter that is also a valid raw hexadecimal token.

case class IdentUpperOnlyToken(startPosn: TextPosn, srcStr: String) extends IdentUpperToken

An identifier beginning with a upper case that is not a valid raw Base32 or hexadecimal token.

An identifier beginning with a upper case that is not a valid raw Base32 or hexadecimal token.

An alphanumeric identifier token beginning with an upper case alphabetic character.

An alphanumeric identifier token beginning with an upper case alphabetic character.

Companion:
object

Extractor function object for IdentUpperToken type.

Extractor function object for IdentUpperToken type.

Companion:
class

An alphanumeric token beginning with an alphabetic character that normally represents a name of something, that identifies something.

An alphanumeric token beginning with an alphabetic character that normally represents a name of something, that identifies something.

Common trait for RawIntDeciToken, NatOxToken and NatOyToken has the getIntStd method. This is the trait you would use in general purpose programming language, where raw hexadecimal and raw Bse32 numbers are disallowed.

Common trait for RawIntDeciToken, NatOxToken and NatOyToken has the getIntStd method. This is the trait you would use in general purpose programming language, where raw hexadecimal and raw Bse32 numbers are disallowed.

Companion:
object

Companion object for the IntStdToken trait, only contains an unapply method.

Companion object for the IntStdToken trait, only contains an unapply method.

Companion:
class
case class Nat0xToken(startPosn: TextPosn, digitsStr: String) extends NatStdToken with ValidHexaIntToken

A hexadecimal token with a leading "0x", that can be used for standard 32 bit Ints, 64 bit Longs, as well as less used integer formats such as BigInteger and Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

A hexadecimal token with a leading "0x", that can be used for standard 32 bit Ints, 64 bit Longs, as well as less used integer formats such as BigInteger and Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

Companion:
object
object Nat0xToken

Function for parsing explicit Hexadecimal Token, one that begins with the characters '0x'.

Function for parsing explicit Hexadecimal Token, one that begins with the characters '0x'.

Companion:
class
case class Nat0yToken(startPosn: TextPosn, digitsStr: String) extends IntStdToken with ValidBase32IntToken

A hexadecimal token with a leading "0y", that can be used for standard 32 bit Ints, 64 bit Longs, as well as less used integer formats such as BigInteger and Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

A hexadecimal token with a leading "0y", that can be used for standard 32 bit Ints, 64 bit Longs, as well as less used integer formats such as BigInteger and Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

Companion:
object
object Nat0yToken

Function for parsing explicit Hexadecimal Token, one that begins with the charchters '0y'.

Function for parsing explicit Hexadecimal Token, one that begins with the charchters '0y'.

Companion:
class
case class NatDeciToken(startPosn: TextPosn, srcStr: String) extends ValidRawHexaNatToken with RawIntDeciToken with NatStdToken with DigitSeqsCode

A 64 bit natural number token in standard decimal format, but which can be inferred to be a raw Hexadecimal. It can be used for standard 32 bit Ints and 64 bit Longs, as well as less used integer formats such as Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

A 64 bit natural number token in standard decimal format, but which can be inferred to be a raw Hexadecimal. It can be used for standard 32 bit Ints and 64 bit Longs, as well as less used integer formats such as Byte. This is in accord with the principle that RSON at the Token and AST (Abstract Syntax Tree) levels stores data not code, although of course at the higher semantic levels it can be used very well for programming languages.

Common trait for RawIntDeciToken, NatOxToken and NatOyToken has the getIntStd method. This is the trait you would use in general purpose programming language, where raw hexadecimal and raw Bse32 numbers are disallowed.

Common trait for RawIntDeciToken, NatOxToken and NatOyToken has the getIntStd method. This is the trait you would use in general purpose programming language, where raw hexadecimal and raw Bse32 numbers are disallowed.

Companion:
object

Companion object for the NatStdToken trait, only contains an unapply method.

Companion object for the NatStdToken trait, only contains an unapply method.

Companion:
class
case class NegDeciToken(startPosn: TextPosn, digitsStr: String) extends RawIntDeciToken with ValidRawHexaNegToken

Negative natural number token. There must be no space between the '-' character and the digits.

Negative natural number token. There must be no space between the '-' character and the digits.

case class NonEmptyStatement(expr: Expr, optSemi: OptRef[SemicolonToken]) extends Statement with TextSpanCompound

An un-claused Statement that is not the empty statement.

An un-claused Statement that is not the empty statement.

case class OperatorToken(startPosn: TextPosn, srcStr: String) extends AssignMemExprToken

An Operator token.

An Operator token.

case class ParenthCloseToken(startPosn: TextPosn) extends BracketCloseToken
case class ParenthOpenToken(startPosn: TextPosn) extends BracketOpen
case object Parenthesis extends Braces
case class RawBase32NatToken(startPosn: TextPosn, srcStr: String) extends ValidRawBase32NatToken

A raw natural Base32 integer token starting with a digit that is not a valid hexadecimal and hence is not a decimal number either.

A raw natural Base32 integer token starting with a digit that is not a valid hexadecimal and hence is not a decimal number either.

case class RawBase32NegToken(startPosn: TextPosn, srcStr: String) extends ValidRawBase32IntToken

A raw natural Base32 integer token starting with a digit that is not a valid hexadecimal and hence is not a decimal number either.

A raw natural Base32 integer token starting with a digit that is not a valid hexadecimal and hence is not a decimal number either.

case class RawHexaNatToken(startPosn: TextPosn, srcStr: String) extends ValidRawHexaNatToken

Raw hexadecimal natural number token, starting with a digit that includes one or more 'A' .. 'F' digits.

Raw hexadecimal natural number token, starting with a digit that includes one or more 'A' .. 'F' digits.

case class RawHexaNegToken(startPosn: TextPosn, srcStr: String) extends ValidRawHexaNegToken

Raw hexadecimal natural number token, starting with a digit that includes one or more 'A' .. 'F' digits.

Raw hexadecimal natural number token, starting with a digit that includes one or more 'A' .. 'F' digits.

A raw integer token could be negative.

A raw integer token could be negative.

case class SemicolonToken(startPosn: TextPosn) extends EmptyExprToken
case object SquareBraces extends Braces
case class SquareCloseToken(startPosn: TextPosn) extends BracketCloseToken
case class SquareOpenToken(startPosn: TextPosn) extends BracketOpen
sealed trait Statement extends TextSpan

The top level compositional unit of Syntax in CRON: Compact Readable Object Notation. A statement can be claused consisting of comma separated clauses containing a single expression. An empty statement is a special case of the UnClausedStatement where the semicolon character is the expression.

The top level compositional unit of Syntax in CRON: Compact Readable Object Notation. A statement can be claused consisting of comma separated clauses containing a single expression. An empty statement is a special case of the UnClausedStatement where the semicolon character is the expression.

Companion:
object
object Statement

Companion object for the Statement trait, contains implicit extension class for List[Statement].

Companion object for the Statement trait, contains implicit extension class for List[Statement].

Companion:
class
trait StatementMem extends BlockMem

A statement member is a Token except the semi colon, which is the statement delimiter and the braces, plus it includes blocks, As blocks contain a sequence of Statements but can themselves be part of a statement.

A statement member is a Token except the semi colon, which is the statement delimiter and the braces, plus it includes blocks, As blocks contain a sequence of Statements but can themselves be part of a statement.

case class StringStatements(statements: Arr[Statement]) extends BlockStatements
case class StringToken(startPosn: TextPosn, stringStr: String) extends ClauseMemExprToken
trait Syntax
case class SyntaxPrefs(maxLineLength: Int, multiStatement: Boolean)
trait Token extends TextSpan
Companion:
object
object Token

Companion object for Token trait contains ShowDec implicit instance.

Companion object for Token trait contains ShowDec implicit instance.

Companion:
class
case class UnderscoreToken(startPosn: TextPosn) extends EmptyExprToken with StatementMem

Common trait for all tokens that can be valid hexadecimal natural numbers as well as valid base32 numbers.

Common trait for all tokens that can be valid hexadecimal natural numbers as well as valid base32 numbers.

A valid fractional number token. Could be an integer or a fractional number.

A valid fractional number token. Could be an integer or a fractional number.

Companion:
object
Companion:
class

Common trait for all tokens that can be valid hexadecimal natural numbers as well as valid base32 numbers.

Common trait for all tokens that can be valid hexadecimal natural numbers as well as valid base32 numbers.

The base trait for all integer tokens. A Natural (non negative) number Token. It contains a single property, the digitStr. The digitStr depending on the class may be interpreted in 1 to 3 ways, as a normal decimal number, a hexadecimal number, or a trigdual (base 32) number.

The base trait for all integer tokens. A Natural (non negative) number Token. It contains a single property, the digitStr. The digitStr depending on the class may be interpreted in 1 to 3 ways, as a normal decimal number, a hexadecimal number, or a trigdual (base 32) number.

A valid non negative fractional number token

A valid non negative fractional number token

Companion:
object
Companion:
class

Token for base 32 natural number. All DecimalTokens are also legal base32 tokens, as well as all raw hexadecimal tokens. Base32 , '0' .. '9', followed by 'A' .. 'W' with letter 'O' unused. Some Alpha numeric terms are valid TrigDualInts.

Token for base 32 natural number. All DecimalTokens are also legal base32 tokens, as well as all raw hexadecimal tokens. Base32 , '0' .. '9', followed by 'A' .. 'W' with letter 'O' unused. Some Alpha numeric terms are valid TrigDualInts.

Companion:
object

Valid Raw natural number compatible with hexadecimal format. This trait exists for its natAsRawHexa method and the associated unapply method.in the companion object.

Valid Raw natural number compatible with hexadecimal format. This trait exists for its natAsRawHexa method and the associated unapply method.in the companion object.

Companion:
object
Companion:
class

Valid raw negative hexadecimal Int Token.

Valid raw negative hexadecimal Int Token.

Companion:
object
Companion:
class

Valid raw negative hexadecimal Int Token.

Valid raw negative hexadecimal Int Token.

Function object for parseing blockMems to an Expr.

Function object for parseing blockMems to an Expr.

Function object to sort tokens in to brace hierarchy.

Function object to sort tokens in to brace hierarchy.

object getClauses
object getExpr

Function object that seeks to get a valid expression from a Mono Statement or clause.

Function object that seeks to get a valid expression from a Mono Statement or clause.

Function object for parsing clause members into ClauseMemExpr.

Function object for parsing clause members into ClauseMemExpr.

Function object to parse identifier token. If successful it passes back, the remaining chars pointer, the test position and the token.

Function object to parse identifier token. If successful it passes back, the remaining chars pointer, the test position and the token.

Function object to parse operator token.

Function object to parse operator token.

Function object for parsing a raw number, could be a normal decimal, hexadecimal or trigdual number. Not all natural numbers are parsed with this function object. Raw hex and trigdual numbers can be encoded as alpha numeric identity tokens.

Function object for parsing a raw number, could be a normal decimal, hexadecimal or trigdual number. Not all natural numbers are parsed with this function object. Raw hex and trigdual numbers can be encoded as alpha numeric identity tokens.

Function object that parses String (with RSON syntax) searching for the String terminator. Returns error if end of file found first.

Function object that parses String (with RSON syntax) searching for the String terminator. Returns error if end of file found first.

object prefixPlus

Function object. Not entirely sure what this does.

Function object. Not entirely sure what this does.

Function object for creating an EMon of Refs of Token from a source. This internally uses a mutable ArrayBuffer, but the mutability is fully encapsulated.

Function object for creating an EMon of Refs of Token from a source. This internally uses a mutable ArrayBuffer, but the mutability is fully encapsulated.

Parses String (with RSON syntax) searching for the String terminator. Returns error if end of file found first. Function object to parse a raw Statement of statement members, where sub blocks have already been parsed into Statement Blocks.

Parses String (with RSON syntax) searching for the String terminator. Returns error if end of file found first. Function object to parse a raw Statement of statement members, where sub blocks have already been parsed into Statement Blocks.

Types

type Tokens = Arr[Token]

Value members

Concrete methods

Tries to parse a sequence of block members BlockMems to a squence of Statements.

Tries to parse a sequence of block members BlockMems to a squence of Statements.

def isOperator(char: Char): Boolean
def srcToEStatements(input: Array[Char], inputSourceName: String): EArr[Statement]

Returns an EMon of a sequence of Statements from a file. This uses the fromString method. Non fatal exceptions or if the file doesn't exist will be returned as errors.

Returns an EMon of a sequence of Statements from a file. This uses the fromString method. Non fatal exceptions or if the file doesn't exist will be returned as errors.

def stringToStatements(input: String): EArr[Statement]

Returns an EMon of a sequence of Statements from a String.

Returns an EMon of a sequence of Statements from a String.

def stringToTokens(srcStr: String): EArr[Token]

Max numbers for long and hexidecimal formats needs to be implemented

Max numbers for long and hexidecimal formats needs to be implemented

def tokensToExpr(tokens: Arr[Token]): EMon[Expr]

Tries to parse a sequence of tokens to an expression Expr.

Tries to parse a sequence of tokens to an expression Expr.

Tries to parse a sequence of Tokens to Statements.

Tries to parse a sequence of Tokens to Statements.