diff options
| author | Jonas Smedegaard <dr@jones.dk> | 2025-05-18 11:08:01 +0200 |
|---|---|---|
| committer | Jonas Smedegaard <dr@jones.dk> | 2025-05-18 14:04:21 +0200 |
| commit | ba1aaf9246f7371bc4c4f8e6636baf44ddf28444 (patch) | |
| tree | a8eb32ce0d7ad526e9fea948d5a71d345c6c7327 | |
| parent | 72827171201ee9c022a6a8c30107e55a16c3826c (diff) | |
define _
| -rw-r--r-- | _def_dia.qmd | 2 | ||||
| -rw-r--r-- | def.peg | 16 | ||||
| -rwxr-xr-x | def_Header.py | 2 | ||||
| -rwxr-xr-x | def_LinkDefinition.py | 28 | ||||
| -rwxr-xr-x | def_LinkLabel.py | 4 | ||||
| -rwxr-xr-x | def_List.py | 2 | ||||
| -rwxr-xr-x | def_Paragraph.py | 21 | ||||
| -rwxr-xr-x | def_PlainWords.py | 2 | ||||
| -rwxr-xr-x | def__.py | 25 |
9 files changed, 57 insertions, 45 deletions
diff --git a/_def_dia.qmd b/_def_dia.qmd index 9255e47..d800c02 100644 --- a/_def_dia.qmd +++ b/_def_dia.qmd @@ -30,6 +30,8 @@ involving the negative predicate from PEG notation.  + +   @@ -9,13 +9,10 @@ Markdown <- MetaBlock* Block* # Block elements Block <- Header / List / LinkDefinition / Paragraph -Header <- '#'+ SPACE* Words? SPACE* NEWLINE -List <- ([-*]+ / [[:digit:]]+ [).]) (SPACE+ (List / Words))? - NEWLINE -LinkDefinition <- LinkLabel ':' SPACE Uri NEWLINE - SPACE SPACE '"' !'"' PlainWords '"' NEWLINE -Paragraph <- (Words (SPACE? NEWLINE / HardBreak))+ - NEWLINE+ +Header <- '#'+ SPACE* !NEWLINE Words? SPACE* NEWLINE +List <- ([-*]+ / [[:digit:]]+ [).]) (_ (List / Words))? NEWLINE +LinkDefinition <- LinkLabel ':' _? Uri (_ '"' !'"' PlainWords '"')? NEWLINE +Paragraph <- Words (HardBreak Words)* NEWLINE+ # Inline elements Words <- StyledWords / LinkedWords / AnnotatedWords / PlainWords @@ -24,10 +21,11 @@ LinkedWords <- '[' Words ']' '(' Uri ')' / '[' Words ']' LinkLabel / LinkLabel AnnotatedWords <- '[' Words ']' '{' ![{}] PlainWords '}' -LinkLabel <- '[' SPACE? ![\[\]] PlainWords SPACE? ']' -PlainWords <- PRINTABLES (SPACE PRINTABLES)* +LinkLabel <- '[' _? ![\[\]] PlainWords _? ']' +PlainWords <- PRINTABLES (_ PRINTABLES)* Uri <- '<' ![<>] PRINTABLES? '>' / ![<>] PRINTABLES HardBreak <- SPACE SPACE+ NEWLINE +_ <- SPACE+ / SPACE? NEWLINE SPACE? SPACE? SPACE? # Terminals PRINTABLES <- [[:graph:]]+ diff --git a/def_Header.py b/def_Header.py index 2559443..3d5ca66 100755 --- a/def_Header.py +++ b/def_Header.py @@ -10,7 +10,7 @@ Diagram( Start("complex"), OneOrMore('#'), ZeroOrMore(NonTerminal("SPACE")), - Optional(NonTerminal("Words")), + Optional(NonTerminal("!NEWLINE Words")), NonTerminal("NEWLINE"), End("complex") ).writeStandalone( diff --git a/def_LinkDefinition.py b/def_LinkDefinition.py index b8dd227..67b5797 100755 --- a/def_LinkDefinition.py +++ b/def_LinkDefinition.py @@ -8,23 +8,17 @@ from railroad import * Diagram( Start("complex"), - Stack( - Sequence( - NonTerminal("LinkLabel"), - ":", - NonTerminal("SPACE"), - NonTerminal("Uri"), - NonTerminal("NEWLINE") - ), - Sequence( - NonTerminal("SPACE"), - NonTerminal("SPACE"), - '"', - NonTerminal("!'\"' PlainWords"), - '"', - NonTerminal("NEWLINE") - ) - ), + NonTerminal("LinkLabel"), + ":", + Optional(NonTerminal("_")), + NonTerminal("Uri"), + Optional(Sequence( + NonTerminal("_"), + '"', + NonTerminal("!'\"' PlainWords"), + '"' + )), + NonTerminal("NEWLINE"), End("complex") ).writeStandalone( open(splitext(basename(__file__))[0] + ".svg", "w").write) diff --git a/def_LinkLabel.py b/def_LinkLabel.py index 8749ab8..4001f7a 100755 --- a/def_LinkLabel.py +++ b/def_LinkLabel.py @@ -9,9 +9,9 @@ from railroad import * Diagram( Start("complex"), "[", - Optional(NonTerminal("SPACE")), + Optional(NonTerminal("_")), NonTerminal("![\\[\\]] PlainWords"), - Optional(NonTerminal("SPACE")), + Optional(NonTerminal("_")), "]", End("complex") ).writeStandalone( diff --git a/def_List.py b/def_List.py index f5e8058..43503e7 100755 --- a/def_List.py +++ b/def_List.py @@ -16,7 +16,7 @@ Diagram( ) ), Optional( - OneOrMore(NonTerminal("SPACE")), + NonTerminal("_"), Choice(0, NonTerminal("List"), NonTerminal("Words") diff --git a/def_Paragraph.py b/def_Paragraph.py index 55ec343..90a7816 100755 --- a/def_Paragraph.py +++ b/def_Paragraph.py @@ -8,20 +8,13 @@ from railroad import * Diagram( Start("complex"), - Stack( - OneOrMore(Sequence( - NonTerminal("Words"), - Choice(0, - Sequence( - Optional(NonTerminal("SPACE")), - NonTerminal("NEWLINE"), - ), - NonTerminal("HardBreak"), - )) - ), - OneOrMore( - NonTerminal("NEWLINE") - ) + NonTerminal("Words"), + ZeroOrMore( + NonTerminal("HardBreak"), + NonTerminal("Words") + ), + OneOrMore( + NonTerminal("NEWLINE") ), End("complex") ).writeStandalone( diff --git a/def_PlainWords.py b/def_PlainWords.py index 42764bc..098c3d6 100755 --- a/def_PlainWords.py +++ b/def_PlainWords.py @@ -10,7 +10,7 @@ Diagram( Start("complex"), NonTerminal("PRINTABLES"), ZeroOrMore( - NonTerminal("SPACE"), + NonTerminal("_"), NonTerminal("PRINTABLES") ), End("complex") diff --git a/def__.py b/def__.py new file mode 100755 index 0000000..806b970 --- /dev/null +++ b/def__.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +# Copyright 2025, Jonas Smedegaard <dr@jones.dk> +# SPDX-License-Identifier: GPL-3+ + +from os.path import basename, splitext +from railroad import * + +Diagram( + Start("complex"), + Choice(0, + Sequence( + OneOrMore(NonTerminal("SPACE")), + ), + Sequence( + Optional(NonTerminal("SPACE")), + NonTerminal("NEWLINE"), + Optional(NonTerminal("SPACE")), + Optional(NonTerminal("SPACE")), + Optional(NonTerminal("SPACE")) + ) + ), + End("complex") +).writeStandalone( + open(splitext(basename(__file__))[0] + ".svg", "w").write) |
