arc_parser 0.1.0

Arc Readable Configuration Parser via Pest
Documentation
program = _{SOI ~ (dict_literal|list_literal|statement*) ~ EOI}
statement = _{
    SEPARATOR
  | empty_line{1,}
  | dict_literal
  | dict_scope
  | dict_pair
  | list_scope
}
empty_line = _{WHITESPACE* ~ NEWLINE}
RestOfLine =  {(!NEWLINE ~ ANY)*}
/*====================================================================================================================*/
dict_scope = {dict_head ~ (SEPARATOR? ~ dict_pair)*}
dict_empty = {"{" ~ "}"}
dict_head  = {"{" ~ NameSpace ~ "}"}
dict_pair  = {NameSpace ~ Set ~ Value}
/*====================================================================================================================*/
list_scope = {list_head ~ (SEPARATOR? ~ list_pair)*}
list_empty = {"[" ~ "]"}
list_head  = {"[" ~ NameSpace ~ "]"}
list_pair  = {
    Insert ~ dict_pair+
  | Append ~ Value
}
/*====================================================================================================================*/
dict_literal = {
    dict_empty
  | "{" ~ (SEPARATOR? ~dict_pair)+ ~ SEPARATOR? ~ "}"
}
list_literal = {
    list_empty
  | "[" ~ (SEPARATOR? ~ Value)+ ~ SEPARATOR? ~ "]"
}
/*====================================================================================================================*/
Value = {Byte|Number|Boolean|Null|Unit|String|dict_literal|list_literal}
//!#D19A66: Null|Unit
Null = @{"null"}
Unit = !{"(" ~ ")"}
/*====================================================================================================================*/
///#D19A66
Boolean = !{True|False}
True    = @{"true"}
False   = @{"false"}
/*====================================================================================================================*/
///#D19A66
Byte     = ${Byte_BIN|Byte_OCT|Byte_HEX}
Byte_BIN = ${Zero ~ ("b"|"B") ~ (Underline? ~ ASCII_BIN_DIGIT)+}
Byte_OCT = ${Zero ~ ("o"|"O") ~ (Underline? ~ ASCII_OCT_DIGIT)+}
Byte_HEX = ${Zero ~ ("x"|"X") ~ (Underline? ~ ASCII_HEX_DIGIT)+}
/*====================================================================================================================*/
///#D19A66
Number       = ${Complex|DecimalBad|SignedNumber}
SignedNumber = ${Sign? ~ (Decimal|Integer)}
Decimal      = ${Integer ~ Dot ~ ASCII_DIGIT+}
DecimalBad   = ${Integer ~ Dot|Dot ~ ASCII_DIGIT+}
Integer      = @{Zero|ASCII_NONZERO_DIGIT ~ (Underline? ~ ASCII_DIGIT)*}
Complex      =  {SignedNumber ~ SYMBOL}

Zero = _{"0"}
/*====================================================================================================================*/
//!#3C963C: String
//!#98C379: StringText|StringLiteralText
String            = ${SYMBOL? ~ (StringLines|StringNormal|StringLiteral|StringEmpty)}
StringLines       =  {(NEWLINE? ~ WHITESPACE* ~ Accent ~ RestOfLine?)+}
StringLiteral     =  {StringStart ~ StringLiteralText ~ StringEnd}
StringNormal      =  {Quotation ~ StringText ~ Quotation}
StringEmpty       =  {Quotation{2}|Apostrophe{2}}
StringLiteralText =  {(!(Apostrophe ~ PEEK) ~ ANY)*}
StringText        =  {(Escape ~ (Escape|Quotation)|!Quotation ~ ANY)*}
StringStart       = @{Apostrophe{1} ~ PUSH(Apostrophe*)}
StringEnd         = @{POP ~ Apostrophe{1}}


Accent     = @{"`"}
Apostrophe = @{"'"}
Quotation  = @{"\""}
Escape     = @{"\\"}
/*====================================================================================================================*/
///#61AFEF
NameSpace = @{Dots? ~ Key ~ (Dot ~ Key)*}
Key       = {String|SYMBOL|Integer}
Dot       = @{"."}
Dots      = @{Dot+}
SYMBOL    = @{XID_CONTINUE+}
/*====================================================================================================================*/
// NEWLINE = @{"\r" ~ "\n"|"\r"|"\n"}

///Gray
COMMENT          =  {MultiLineComment|LineComment}
WHITESPACE       = _{NEWLINE|SPACE_SEPARATOR|"\t"}
LineComment      = ${"%" ~ (!NEWLINE ~ ANY)*}
MultiLineComment = ${"%%%" ~ (MultiLineComment | !"%%%" ~ ANY)* ~ "%%%"}



At         = @{"@"}
Sharp      = @{"#"}
Underline  = @{"_"}
Asterisk   = @{"*"}
SEPARATOR  = @{","|";"}

Set      = @{"="|":"}
Vertical = @{"|"}
Sign     = @{"+"|"-"}

Insert = @{"*"}
Append = @{">"}