aboutsummaryrefslogtreecommitdiff
path: root/def.peg
blob: 4fb3295f938a1bcdf9db95c9e029d5a8f4f3fd9b (plain)
  1. # Subsets of Markdown syntax structure
  2. # expressed in parsing expression grammar (PEG) notation.
  3. #
  4. # Copyright 2025, Jonas Smedegaard <dr@jones.dk>
  5. # SPDX-License-Identifier: GPL-3+
  6. # Document
  7. Markdown <- MetaBlock* Block*
  8. # Block elements
  9. Block <- Header / List / LinkDefinition / Paragraph
  10. Header <- '#'+ SPACE* Words? SPACE* NEWLINE
  11. List <- ([-*]+ / [[:digit:]]+ [).]) (SPACE+ (List / Words))?
  12. NEWLINE
  13. LinkDefinition <- '[' !'[]' PlainWords ']' ':' SPACE Uri NEWLINE
  14. SPACE SPACE '"' !'"' PlainWords '"' NEWLINE
  15. Paragraph <- (Words (SPACE? NEWLINE / HardBreak))+
  16. NEWLINE+
  17. # Inline elements
  18. Words <- StyledWords / LinkedWords / AnnotatedWords / PlainWords
  19. StyledWords <- '*' Words '*' / '**' Words '**' / '_' Words '_'
  20. LinkedWords <- '[' Words ']' '(' Uri ')'
  21. / '[' Words ']' '[' ![\[\]] LinkDefinitionKeyphrase ']'
  22. / '[' LinkDefinitionKeyphrase ']'
  23. AnnotatedWords <- '[' Words ']' '{' ![{}] PlainWords '}'
  24. PlainWords <- PRINTABLES (SPACE PRINTABLES)*
  25. Uri <- '<' ![<>] PRINTABLES? '>' / ![<>] PRINTABLES
  26. HardBreak <- SPACE SPACE+ NEWLINE
  27. # Terminals
  28. PRINTABLES <- [[:graph:]]+
  29. SPACE <- ' '
  30. NEWLINE <- '\r\n' / '\n' / '\r'