aboutsummaryrefslogtreecommitdiff
path: root/syntax
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-05-24 14:29:20 +0200
committerJonas Smedegaard <dr@jones.dk>2025-05-24 14:29:20 +0200
commit9d6da046d07b39bf14ca6c97b7781d1da38c6b49 (patch)
treed8f9b8afe7588d5eb5fdd54177573b54516aa5e5 /syntax
parent7f610808af0a83264d9e2dd52620b01bea4d0091 (diff)
fix add def.peg, accidentally dropped in git commit 7e56c94
Diffstat (limited to 'syntax')
-rw-r--r--syntax/def.peg56
1 files changed, 56 insertions, 0 deletions
diff --git a/syntax/def.peg b/syntax/def.peg
new file mode 100644
index 0000000..e40610f
--- /dev/null
+++ b/syntax/def.peg
@@ -0,0 +1,56 @@
+# Subsets of Markdown syntax structure
+# expressed in parsing expression grammar (PEG) notation.
+#
+# Copyright 2025, Jonas Smedegaard <dr@jones.dk>
+# SPDX-License-Identifier: GPL-3+
+
+# Document
+Markdown <- ('---' NEWLINE MetaBlock* '---' NEWLINE)? Block*
+
+# Block elements
+Block <- Header
+ / List
+ / LinkDefinition
+ / Paragraph
+Header <- '#'+ SPACE* !NEWLINE Words? SPACE* NEWLINE
+List <- ([-*]+ / [[:digit:]]+ [).]) (_ (List / Words))? NEWLINE
+LinkDefinition <- LinkLabel ':' _? Uri (_ LinkTitle)? NEWLINE
+Paragraph <- Words (HardBreak Words)* NEWLINE+
+
+# Inline elements
+Words <- StyledWords
+ / LinkedWords
+ / AnnotatedWords
+ / PlainWords
+StyledWords <- '**' Words '**'
+ / '*' Words '*'
+ / '_' Words '_'
+LinkedWords <- '[' Words ']' '(' ((Uri _)? LinkTitle / Uri) ')'
+ / '[' Words ']' LinkLabel
+ / LinkLabel
+AnnotatedWords <- '[' Words ']' '{' ![{}] PlainWords '}'
+LinkLabel <- '[' _? ![\[\]] PlainWords _? ']'
+LinkTitle <- '"' _? !'"' _? PlainWords _? '"'
+ / "'" _? !"'" PlainWords _? "'"
+ / "(" _? ![()] PlainWords _? ")"
+PlainWords <- PRINTABLES (_ PRINTABLES)*
+Uri <- '<' ![<>] PRINTABLES? '>'
+ / ![<>] PRINTABLES
+HardBreak <- SPACE SPACE+ NEWLINE
+_ <- SPACE+
+ / SPACE? NEWLINE SPACE? SPACE? SPACE?
+
+# Terminals
+PRINTABLES <- [[:graph:]]+
+SPACE <- ' '
+NEWLINE <- '\r\n'
+ / '\n'
+ / '\r'
+
+# Semantic Markdown
+AnnotatedWordsX <- '[' Words ']'
+ ('{' (SemWords / ![{}] PlainWords) '}')
+SemWords <- SEMPREFIX '<' ![<>] PRINTABLES '>'
+ / SEMPREFIX Curie
+Curie <- NAME? ':' NAME?
+SEMPREFIX <- [.#]