lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 22/07/16 08:13 PM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
http://stackoverflow.com/q/38514522/3691554

I'm trying to parse a subset of markdown into a tree with LPeg. The idea
is simple but I'm not sure what I'm doing. The whole spec for the thing
I'm doing is here[1] and yes, that's a master branch github link, there
are still some things I need to work out.
   I'm not exactly sure how you want the resulting table to look like, but
going from this minimal example [1]:

	#Tag
	##Attribute
	###Value
	Content
Invalid. Instead:

#Tag
##Attribute
###Value
> Content

should produce:

{ -- document root
  { -- root tag
    [tagname_idx] = "Tag",
    ["Attribute"] = "Value",
    "Content"
  }
}

an initial stab at the problem (untested):

[code]

   I opted to store the "tag" as the [0]th element because that's what LuaXML
does when parsing XML documents.  This should get you going though (other
things left as an exercise---what if there's a missing tag?  Adding in
escape sequences.  That odd 'raw' mode I didn't understand.  Parsing nested
data)
A missing tag should be an error. A missing attribute value should be an error. Raw mode means "disable the parser and treat everything as data" like XML's <![CDATA[ ]]>. Note that missing tags can only happen when you go in a `> ` block.

   -spc
[1] And I'm wondering why you even want this, when you could just use
	Lua directly, or JSON, or YAML, or *any number of existing
	half-documented markup languages masquerading as a "standard"* but
	I'll take you at face value and not ask WTF?


I can use this for config files, because it's a clean config file format unlike XML, and I can also use this to generate XML documents (e.g. XHTML webpages) because I designed it that way.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.