From: Fredrik Karlsson on 9 Jul 2010 03:55 Hi! Sorry for reviving this thread, but I have a question concerning my grammar where my Tcl skill level is not enough, so I hope you can help me. I now have this (part of a) PEG: .... labelsequence <- label (OROPERATOR label)*; label <- (STRINGMARK label STRINGMARK) / (<alnum>)+ / (STRINGMARK WHITESPACE STRINGMARK); void: OROPERATOR <- '|' ; void: WHITESPACE <- (" " / "\t" / "\r" / "\n" )* ; void: STRINGMARK <- "'"; .... What I really want is to be able to have (almost) the entire ASCII alphabet as a label, just as long as it is enclosed in matching "'"- chars. So, '"}\r`|r\{' should be a valid entry, and be extracted as ONE normal string when put into the AST, but (of course) '"}\r`|r\{'|b should still be two entries in the labelsequence. Is this possible to do? /Fredrik
From: Fredrik Karlsson on 9 Jul 2010 05:43 Sorry, I think not that I should have been more clear in what I need. I did not give enough information above as to what I actually want. What I need is a part of grammar that would allow "label" to be anything that is a) all numbers and letters (already done in the PEG above) b) '-character followed by ANYTHING up until another '-character followed by either whitespace or a '|'-character. So, ''''{`1'''}'''{''s''a|''|a should be a valid sequence of two labels. Any ideas of what the PEG should be? And, how do I get this to work with the parser generator in a safe Tcl way? Please, I would appreciate all the help I could get on this. /Fredrik
From: Andreas Kupries on 9 Jul 2010 09:19
Fredrik Karlsson <dargosch(a)gmail.com> writes: > Sorry, I think not that I should have been more clear in what I need. > I did not give enough information above as to what I actually want. > > What I need is a part of grammar that would allow "label" to be > anything that is > > a) all numbers and letters (already done in the PEG above) > b) '-character followed by ANYTHING up until another '-character > followed by either whitespace or a '|'-character. > So, ''''{`1'''}'''{''s''a|''|a should be a valid sequence of two > labels. http://docs.activestate.com/activetcl/8.5/tcllib/pt/pt_peg_import_peg.html#section3 Please look at the definition of 'Literal'. This isa, I believe what you are looking for, or very nearly so. A string which starts with a apostroph, followed by anything which is not an (unquoted) apostroph, closed by an apostroph. > Any ideas of what the PEG should be? And, how do I get this to work > with the parser generator in a safe Tcl way? > > Please, I would appreciate all the help I could get on this. > > /Fredrik > -- So long, Andreas Kupries <akupries(a)shaw.ca> <http://www.purl.org/NET/akupries/> Developer @ <http://www.activestate.com/> ------------------------------------------------------------------------------- |