context-notation 0.1.4

Featherweight semantic notation for text
Documentation
/*
    Public slashlink:
    @public/foo/bar

    Private slashlink:
    /foo/bar
*/

Context = { SOI ~ (Block*) ~ EOI }

Slug      = @{ (LETTER | NUMBER | SlugSpecialCharacter)+ }
Petname   = @{ (!"/" ~ Bridge | LETTER | NUMBER)+ }
Protocol  = @{ "http" ~ "s"? ~ "://" }
HyperLink = @{ Protocol ~ (!(Whitespace | ("." ~ Whitespace)) ~ ANY)+ }

BridgeCharacter       = _{ "-" | "_" | "." }
Bridge                = _{ BridgeCharacter ~ !(" " | BridgeCharacter | LeadingInlineBoundary | Terminator | EOI) }
SlugSpecialCharacter  = _{ Bridge | "/" ~ !"/" }
Whitespace            = _{ (SEPARATOR+ | Terminator) }
Indentation           = _{ SPACE_SEPARATOR ~ SPACE_SEPARATOR }
Terminator            = _{ NEWLINE | IgnoredUnicode }
IgnoredUnicode        = _{ '\u{1FF80}'..'\u{10FFFF}' }
Contiguous            = _{ !NEWLINE ~ ANY }
MentionBoundary       = _{ "@" }
SlashLinkBoundary     = _{ "/" ~ !"/" }
HashTagBoundary       = _{ "#" }
InlineCodeBoundary    = _{ !"\\" ~ "`" }
WikiLinkOpenBoundary  = _{ "[[" ~ !"[" }
WikiLinkCloseBoundary = _{ "]]" }
ListItemBoundary      = _{ "- " }
QuoteBoundary         = _{ "> " }
CodeBoundary          = _{ "```" }
LeadingInlineBoundary = _{ MentionBoundary | SlashLinkBoundary | HashTagBoundary | InlineCodeBoundary }
TextCharacter         = _{ !Whitespace ~ Contiguous ~ LeadingInlineBoundary | !NonTextSpan ~ Contiguous }
Span                  = _{ NonTextSpan | Text }
NonTextSpan           = _{ HyperLink | InlineCode | HashTag | SlashLink | WikiLink | Mention }
BlockContent          = _{ Span+ }
Block                 = _{ List | Quote | Code | Paragraph | Empty }

Mention         = { MentionBoundary ~ Petname }
SlashLink       = { Mention? ~ SlashLinkBoundary ~ Slug }
HashTag         = { HashTagBoundary ~ Slug }
Text            = { TextCharacter+ }
Empty           = { NEWLINE }
InlineCode      = {
    InlineCodeBoundary ~ InlineCodeValue ~ InlineCodeBoundary
}
InlineCodeValue = { (!InlineCodeBoundary ~ Contiguous)+ }

WikiLink        = { WikiLinkOpenBoundary ~ WikiLinkValue ~ WikiLinkCloseBoundary }
WikiLinkValue   = { (!WikiLinkOpenBoundary ~ !WikiLinkCloseBoundary ~ Contiguous)+ }
Paragraph       = { BlockContent ~ NEWLINE? }
Code            = {
    CodeBoundary ~ Slug? ~ NEWLINE ~ CodeValue? ~ CodeBoundary ~ NEWLINE?
}
CodeValue       = { (!CodeBoundary ~ ANY)* ~ NEWLINE? }
List            = {
    ListIndentation ~ ListItem ~ (NEWLINE? ~ PEEK_ALL ~ ListItem)* ~ NEWLINE?
}
NestedList      = {
    ListIndentation ~ ListItem ~ (NEWLINE? ~ PEEK_ALL ~ ListItem)*
}
ListIndentation = { PUSH(Indentation*) }
ListItem        = {
    ListItemBoundary ~ ListItemContent ~ (NEWLINE ~ (&(PEEK_ALL ~ Indentation+) ~ NestedList ~ DROP))*
}
ListItemContent = { BlockContent }
Quote           = { QuoteLine ~ (NEWLINE ~ QuoteLine)* ~ NEWLINE? }
QuoteLine       = { QuoteBoundary ~ BlockContent }