tag:blogger.com,1999:blog-2744072865491516720.post7032554156942798185..comments2023-05-03T06:35:33.259-04:00Comments on Higher Logics: Sasa v0.9.3 Released!Sandro Magihttp://www.blogger.com/profile/05446177882449578817noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-2744072865491516720.post-36390717827643898732011-03-26T10:48:26.938-04:002011-03-26T10:48:26.938-04:00Thanks for the references Peter, I just couldn'...Thanks for the references Peter, I just couldn't seem to find any discussion of \G. Why Match would take an index but seemingly ignore the parameter entirely unless you specify a cryptic regex option is beyond me.<br /><br />I've committed the addition to Sasa.Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-72821158875936386862011-03-19T11:31:25.177-04:002011-03-19T11:31:25.177-04:00About the \G in RegEx strings, see e.g. http://sta...About the \G in RegEx strings, see e.g. http://stackoverflow.com/questions/2658180/how-to-regex-ismatch-at-a-specified-offset-in-net<br /><br />In short, it ensures the scanner will only match at the 'start' position given.<br /><br />Given the current Grammer.RegEx method, a test would be something like:<br /><br />Scanner s = RegEx("abc");<br />Assert(s("123abc", 2) == 2); // no match<br />Assert(s("123abc", 3) == 6); // match<br /><br />I think the first assertion would fail as the code is right now. I suppose alternatively it could be left to the caller to add the @"\G" themselves, but that seems like an avoidable source of bugs.Peterhttps://www.blogger.com/profile/06491330474563287546noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-18462478337100975702011-03-07T02:38:40.976-05:002011-03-07T02:38:40.976-05:00I added a few more convenience declarations to han...I added a few more convenience declarations to handle lists of values, and I committed a trivial list grammar to the test suite. It's basically just integer values and lists of integers.<br /><br />I used a temporary hack to check token membership, but the essence of list parsing is there. I don't specify a Led anywhere, just a Nud on the list symbol, and no dependency on previous tokens. I basically just took the implementation of the Group declaration, and instead of just returning a single value between the open and close delimiters, I process a list of values.<br /><br />It's not purely functional like your version, but the Pratt parsing algorithm is inherently imperative, so no great loss there IMO. I think a purely functional version is possible, it's just too late to think about it now. :-)<br /><br />Re: regular expression and \G, I don't use regexes much, and I couldn't find much documentation on \G. Can you provide a simple test case that I can add to the test suite?Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-88239700088926352872011-03-07T00:10:59.992-05:002011-03-07T00:10:59.992-05:00Hi Sandro, thanks for your response.
The language...Hi Sandro, thanks for your response.<br /><br />The language I was parsing is GML, from the ICFP 2000 ray tracer <a href="http://www.cs.cornell.edu/icfp/task.htm" rel="nofollow">task</a>. I believe that falls into the category of "dynamic, functional programming language", which according to Doug Crockford's article should be easy with a Pratt parser.<br /><br />It's really just lists of tokens (including nested lists for functions, arrays). I ended up adding a Led to every symbol:<br /><br /> protected Symbol ListSymbol(string id)<br /> {<br /> var lex = Symbol(id, 50);<br /> lex.Led =<br /> (parser, left) =><br /> list(left, parser.CurrentToken.Nud(parser));<br /> return lex;<br /> }<br /><br />"list" is essentially 'cons' here. Notice though that I need to parse the CurrentToken, and because I need the match string, essentially, I have to call Token.Nud.<br /><br />(By the way, the parser worked fine with those minor changes, and I went on to get a working ray tracer, so thanks!)<br /><br />I expect I'm missing something obvious, as I'm new to Pratt parsers. Possibly, there could just be an alternate Parse method for returning a list of tokens (where there's a sort of default Led of list append).<br /><br />I haven't needed this, but don't some languages allow you to apply a function f in infix position by writing 'f or `f or something? e.g. "1 'plus 2" Perhaps that would be an interesting case to prototype?<br /><br />Incidentally, I think the \G I was prepending to the regex expression is important, otherwise the regex may match past the start location. It appears to be missing from the SVN version.Peterhttps://www.blogger.com/profile/06491330474563287546noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-85925484047222144812011-03-06T11:57:04.780-05:002011-03-06T11:57:04.780-05:00I've fixed the line count bug, and also found ...I've fixed the line count bug, and also found another bug with the Grammar.Match declaration, so thanks Peter!<br /><br />I've added the Regex scanner as well, with an optional argument for RegexOptions.<br /><br />I haven't done anything regarding the previous token, which Peter named "CurrentToken". I know which token this refers to, but I'd like to better understand the specific circumstances where it's needed before making this change. <br /><br />Assuming it's needed, I think the best solution would be to extend Token with a property designating the previous Token, so you can look back an arbitrary number of tokens.Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-57978030861005179612011-03-02T14:27:00.426-05:002011-03-02T14:27:00.426-05:00Hey Peter,
Re: line counts, I believe you're ...Hey Peter,<br /><br />Re: line counts, I believe you're correct. I'll implement a fix tonight or tomorrow.<br /><br />Re: CurrentToken, can you provide a simple example? Your mention of fixed operators suggests you might be extending the symbol table dynamically with user-defined operators. I haven't applied PrattParser in this domain yet, so it might indeed be missing something important.<br /><br />Re: ScanRegex, that's eminently doable. I generally try to avoid using control strings, so I'd prefer to actually add combinators for the regex matching you've found useful, but that's certainly a useful interim solution. Thanks!Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-6709908884452150242011-03-02T00:35:31.624-05:002011-03-02T00:35:31.624-05:00I found a small bug in PrattParser.cs (Sasa 0.9.3)...I found a small bug in PrattParser.cs (Sasa 0.9.3); the line counts are not updated for skipped tokens (see lines 567-573).<br /><br />For my purposes I also had to add a "CurrentToken" property to PrattParser ('var t' from the main loop), else I couldn't see a way to access the Nud for a token during evaluation of its Led ('Token' has already advanced). I hope that explanation makes sense. It appears to not be an issue in the examples I've seen due to the operators tending to be fixed strings. Perhaps I have missed something.<br /><br />Finally, can I propose the following addition, which I found made my life alot easier when producing scanners for my parser:<br /><br /> protected static Scanner ScanRegex(string regex)<br /> {<br /> Regex r = new Regex(@"\G" + regex);<br /> return (input, start) =><br /> {<br /> Match m = r.Match(input, start);<br /> return m.Success ? start + m.Length : start;<br /> };<br /> }Peterhttps://www.blogger.com/profile/06491330474563287546noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-87762581461935285132011-02-01T19:17:25.591-05:002011-02-01T19:17:25.591-05:00I see CCI-Metadata as fitting into the PHX (Phoeni...I see CCI-Metadata as fitting into the PHX (Phoenix) compiler stack...John Zabroskihttps://www.blogger.com/profile/17294832205855394228noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-46071850631365121312011-02-01T18:36:11.983-05:002011-02-01T18:36:11.983-05:00Re: CCI-Metadata, thanks for the ref, it's new...Re: CCI-Metadata, thanks for the ref, it's new to me. I'm just using Mono.Cecil 2.0 for rewriting, which sounds similar though less ambitious.<br /><br />I was excited about Nemerle for awhile, but it's really difficult to gauge its status, and the devs aren't very interested in developing a community.<br /><br />Re: pattern matching, I wasn't looking at anything fancy, just to inline the compiler-generated delegates for matching on Either types. It certainly could get more interesting considering <a href="http://higherlogics.blogspot.com/2008/10/vtable-dispatching-vs-runtime-tests-and.html" rel="nofollow">runtime tests and casts are more efficient than vtable dispatch</a>, but that's further down the road.<br /><br />Anyhow, let me know the tutorials go! Feel free to submit bugs, suggestions or feature requests.Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-67971723272706905082011-02-01T17:56:07.206-05:002011-02-01T17:56:07.206-05:00Give me some time and space to think about the pat...Give me some time and space to think about the pattern matching tricks.<br /><br />I'll just focus on writing tutorials for the existing stuff, since it will also push me to read more of the code.<br /><br />With regards to IL Rewriting, I consider that to be a very big topic. Have you seen the CCI-Metadata project on Codeplex? It is written by the same dude @ MSFT who wrote ILMerge. He pretty much just wanted a less crappy ILMerge. He should've used F# for CCI-Metadata though. I imagine the code being simpler and executing faster.<br /><br />Also, as my friend jokes, "Nemerle, C# 5.0, Today!"John Zabroskihttps://www.blogger.com/profile/17294832205855394228noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-33071824917324017932011-01-28T14:21:25.781-05:002011-01-28T14:21:25.781-05:00Re: unconstrained-melody, yes, some of the feature...Re: unconstrained-melody, yes, some of the features I implemented were inspired by Skeet's blog posts. I just took another quick look at the source there, and there is some odd code there for the enums. He builds some dictionaries for descriptions, and returns IList instead of IEnumerable, so it's definitely not as efficient or minimal as the interface Sasa provides.<br /><br />As for what Sasa is missing, I think just tutorials and tests, mainly for the concurrent abstractions really. I briefly looked into using MS's <a href="http://research.microsoft.com/en-us/projects/chess/" rel="nofollow">CHESS</a> concurrency checker to more rigourously verify the futures and event extensions, but haven't had time to really dig into it. That's definitely an interesting project though if you're looking for something cool to do.<br /><br />Each assembly has a TODO.txt file detailing some of the plans I have, or incomplete/unsatisfactory abstractions, with a rough timeline I'm trying to stick to. You might be interested in the IL rewriting extensions I plan to add, such as pattern matching inlining, and an analysis to ensure a struct's default constructor is never called (mainly to make NonNull more useful). But anything you'd like to do is welcome!Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-46999487412210768252011-01-28T13:21:20.248-05:002011-01-28T13:21:20.248-05:00Actually, maybe I could start with a tutorial on t...Actually, maybe I could start with a tutorial on the Enum stuff in Sasa. I did some research a few months ago on all the available tools for manipulating Enum's in .NET when I wanted to add an EnumFlagsCSharpRepresentationVisualizer for Visual Studio 2008, similar to the same feature available in VS 2005+ for C++. I kind of went overboard with the research since all I needed to do was a coercive cast, but I just got really curious with the design options.<br /><br />Have you seen Jon Skeet's Enum library? http://code.google.com/p/unconstrained-melody/John Zabroskihttps://www.blogger.com/profile/17294832205855394228noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-9776006634485827832011-01-28T13:11:36.606-05:002011-01-28T13:11:36.606-05:00Maybe I'll contribute some documentation to Sa...Maybe I'll contribute some documentation to Sasa, then.<br /><br />I've got a couple of projects I am working on now as-is: (1) SQLPSX PowerShell project's monitoring API and dashboardd (2) an ORM for Haskell (3) Porting Google Refine to .NET [non-trivial] (4) Porting Gource from C++ and SDL to F# with the help of C# SDL .NET library.<br /><br />I just finished another port recently from a WPF app to Silveright (with improved abstractions and code re-use). I don't know why, but huge ports have been a fun hobby for me lately.<br /><br />If you have anything you want help with, just make a list.<br /><br />Cheers,<br />Z-BoJohn Zabroskihttps://www.blogger.com/profile/17294832205855394228noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-22165616719839378912011-01-27T20:44:28.672-05:002011-01-27T20:44:28.672-05:00Thanks for the kind words! I'll consider that ...Thanks for the kind words! I'll consider that when Sasa gets a little closer to 1.0. Some of these features don't enjoy the degree of test coverage I'd like since they were just fun hacks at the time.<br /><br />I'm not even sure what abstractions people find interesting. The ones I described in this post are the most innovative or unusual for .NET libraries that I've encountered, but I haven't received much feedback beyond the MIME library.<br /><br />I have demo projects in mind for parsing (a small programming language), and serialization will be a good demonstration of dynamics, but I don't have a good demo in mind for the event functions. A simple concurrent program would be nice, so if you have any thoughts please let me know!Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-61171723388989735972011-01-27T20:03:58.130-05:002011-01-27T20:03:58.130-05:00Sasa is shaping up to be pretty amazing. You shou...Sasa is shaping up to be pretty amazing. You should consider writing an OOPSLA practitioner's report next year about it. I think it would be the first time in history that I've read a practitioner's report and didn't fall asleep.John Zabroskihttps://www.blogger.com/profile/17294832205855394228noreply@blogger.com