doesn't that make you wonder?
Tao Klerks
tao at klerks.biz
Thu Oct 20 17:53:14 EDT 2011
OK, I appreciate the example might be dumbed-down here, but again there is
no reason the two programs couldn't use the exact same function and constant
names, is there? You could easily define a canonical peg (leg) file and have
the constant/function names be part of its "implementation interface".
The only functional difference I see between these two samples is the "!(Sp?
HtmlBlockOpenDiv)" part in MMD that does not feature in Composer. (and I'm
actually curious - what does that difference mean? maybe a subject better
explored offline, when I've done my homework and stand a chance of
recognizing some syntax :))
All that said, I have looked briefly into the PEG frameworks listed at
http://bford.info/packrat/ (looks like the definitive list!), and it looks
like every one has its own syntax, or at least subtleties of implementation.
To implement something in Javascript (and maybe also C#), it looks like
you'd need to start by converting the LEG definition into an
OMeta-compatible format. I guess it will never be trivial.
From: markdown-discuss-bounces at six.pairlist.net
[mailto:markdown-discuss-bounces at six.pairlist.net] On Behalf Of Fletcher T.
Penney
Sent: Thursday, October 20, 2011 5:00 PM
To: Discussion related to Markdown.
Subject: Re: doesn't that make you wonder?
Perhaps an (admittedly trivial) example will help:
peg-mmd:
Block = BlankLine*
( BlockQuote
| Verbatim
| &{ !extension(EXT_COMPATIBILITY) } DefinitionList
| &{ !extension(EXT_COMPATIBILITY) } Glossary
| Note
| Reference
| HorizontalRule
| HeadingSection
| OrderedList
| BulletList
| HtmlBlock
| StyleBlock
| &{ !extension(EXT_COMPATIBILITY) } Table
| &{ !extension(EXT_COMPATIBILITY) } ImageBlock
| !(Sp? HtmlBlockOpenDiv) Para
| Plain )
Composer:
Block = BlankLine*
( BlockQuote
| Verbatim
| &{ EXT(EXT_MMD) } DefinitionList
| &{ EXT(EXT_MMD) } Glossary
| Note
| Reference
| HorizontalRule
| HeadingSection
| OrderedList
| BulletList
| HtmlBlock
| StyleBlock
| &{ EXT(EXT_MMD) } Table
| &{ EXT(EXT_MMD) } FutureTable
| Para
| Plain )
The PEG is basically the same in defining what to match, but the C commands
(inside the {}) are different based on the requirements of the separate
programs.
It sounds like you want a single document that can be pasted into any
program in any language and work. I suspect such a think doesn't exist.
A PEG in this style is close, in that it defines an algorithm for parsing
the input text that can be reused in a variety of contexts, but it will
require customization to suit the particular needs of the program.
F-
On Oct 20, 2011, at 3:16 PM, Tao Klerks wrote:
OK, so just one follow-up, for my understanding if nothing else:
If a PEG is a grammar, and you need to "hook in" to it to get it to do
useful things like converting markdown to html, then why would you need to
change that PEG (definition/grammar) to USE it to do some other thing, like
produce some way to highlight some text in an OSX app? Wouldn't you just
change the "hooks"? Did you really have to change the PEG, or did you just
change the functions/events/[insert C-appropriate or PEG-appropriate
keywords here. "Actions" maybe?] that hook into it? Is the problem that the
two are interspersed in the current implementation/file? Sorry, I've only
very briefly looked at the "markdown_parser.leg" files in peg-markdown and
peg-multimarkdown, haven't yet had the chance to dive in and actually try to
understand them - I was assuming the PEG itself is entirely defined between
those strange looking "%}" and "%%" delimiters in the file.
Sorry I'm harping on about this, but I'm trying to understand whether/how a
completely new program, in a completely different environment, could
correctly parse the input (let's forget about generating the output -
obviously that portion will depend on the language/environment/framework)
WITHOUT writing a new PEG or equivalent and hoping it's defining the same
AST. I'm hoping (wishfully maybe) that it can simply be copy/pasted, and
then another framework build around it for the "Actions".
--
Fletcher T. Penney
fletcher at fletcherpenney.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://six.pairlist.net/pipermail/markdown-discuss/attachments/20111020/de623675/attachment.html>
More information about the Markdown-Discuss
mailing list