From 20a7517bf51a5ed1b36d0c134d1bf3f5d01b2e4a Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 17 May 2025 16:34:36 +0200 Subject: add chapter on Markdown and annotation --- def.peg | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 def.peg (limited to 'def.peg') diff --git a/def.peg b/def.peg new file mode 100644 index 0000000..163b5a4 --- /dev/null +++ b/def.peg @@ -0,0 +1,34 @@ +# Subsets of Markdown syntax structure +# expressed in parsing expression grammar (PEG) notation. +# +# Copyright 2025, Jonas Smedegaard +# SPDX-License-Identifier: GPL-3+ + +# Document +Markdown <- MetaBlock* Block* + +# Block elements +Block <- Header / List / LinkDefinition / Paragraph +Header <- '#'+ SPACE* Words? SPACE* NEWLINE +List <- ([-*]+ / [[:digit:]]+ [).]) (SPACE+ (List / Words))? + NEWLINE +LinkDefinition <- '[' !'[]' PlainWords ']:' SPACE Uri NEWLINE + SPACE SPACE '"' !'"' PlainWords '"' NEWLINE +Paragraph <- Words (SPACE? NEWLINE Words / HardBreak Words)* + NEWLINE NEWLINE + +# Inline elements +Words <- StyledWords / LinkedWords / AnnotatedWords / PlainWords +StyledWords <- '*' Words '*' / '**' Words '**' / '_' Words '_' +LinkedWords <- '[' Words ']' '(' Uri ')' + / '[' Words ']' '[' ![\[\]] LinkDefinitionKeyphrase ']' + / '[' LinkDefinitionKeyphrase ']' +AnnotatedWords <- '[' Words ']' '{' ![{}] PlainWords '}' +PlainWords <- PRINTABLES (SPACE PRINTABLES)* +Uri <- '<' ![<>] PRINTABLES? '>' / ![<>] PRINTABLES +HardBreak <- SPACE SPACE NEWLINE + +# Terminals +PRINTABLES <- [[:graph:]]+ +SPACE <- ' ' +NEWLINE <- '\r\n' / '\n' / '\r' -- cgit v1.2.3