 Some of you that came down to delirium on Friday might be expecting me to do a talk on origami. This is a King Cobra model. Yes, it is one sheet of paper. One very long sheet of paper, albeit. But we're not talking about that. I have something of a deep, dark secret. I'm actually something of an awful person. By awful, I don't mean necessarily bad, although we can argue about that. I mean insensitive and adult fan of Lego, A-F-O-L. In this case, this is obviously not my work, thankfully, unfortunately. This is a model that I found at random. One problem that I have living as I do as an expat overseas is most of my collection of bricks is in the U.S. as I cannot have them shipped over here. So instead of something on this scale, I'm kind of forced to work on a much smaller scale. I believe I'm allowed to call that a laser sword. Thank you, Lucasfilm. So a much smaller part count, much smaller. Now, when you are stuck far home and need more cess work, go to bricklink, you need a little bit of creativity. You can't quite build on this scale. Yes, that is a real life adult there. This is a model of St. Pancras Station in London, if you've been there. And yes, the train's going in and out due work. They, in fact, go all the way around these seven and back to the bridge that you see in back. This, I think, was taken at Lego World in London in 2015. I was lucky enough to be there. So a lot of pieces, a lot of piece count. And unfortunately, most people don't have that, don't have that many pieces. But luckily for us, we have substitutes. We have ML CAD, Lego CAD, Lego CAD design. This is, admittedly, yes, an old application. I would prefer to use a term of venerable. The important thing that we need to worry about here are the three panes that are above. The one marked 14 over there is a way to choose the piece. Frame 13 there talks about the type of piece, and one point has a part ID. And down here in pane 12, you have the x, y, and z coordinates of pieces that you position. A ML CAD text file, much reduced looks something like this. You have columns for x, y, z, a part name, and a color with a string, in this case, because some colors have, there is the light gray, there is the dark gray, there is the old blue, there is the hardest blue, and several. So you have a combination of several different types of identifiers. So, and we'll start with that easy in Pearl 5. How many of you here are working with or have played so far with Pearl 6? Okay, about half. Excellent, excellent. So you've probably seen some, so everyone here probably knows how radio expressions used to work. I shouldn't use that phrase. I will use the phrase, how they work right now in Pearl 5. I work at Pearl 5 right now. I am very much, oh, about 25, 20 or so years of my career to Pearl 5. So I love it. I still use the language on a daily basis. But I'm using Pearl 6 now as more of, right now, a hobby. And eventually, we will get people to the point where we have job descriptions for Pearl 6. But that's the future. So everyone immediately knows what this expression is. Just write out the back. Almost. Most of you probably do, most of you can probably read this very easily. For a new person coming in or anyone looking at Pearl 5 code, they're going to look at this and immediately say, what the blank? What is that? It's just a bunch of slashes and stars and plus signs. Nothing there to actually tell what it is. And even if you know what it is, looking along there, you're not going to get an idea of what the file content you're processing actually looks like. You're not going to get an idea of an x, y, or z quarter. You're not going to get an idea of this being an identifier or a string. You're not going to get that. Even if you take the time to separate out a little bit. And even then, if you don't look carefully, you're not going to see the fact that you have a slash d slash s slash d. And then along the way trips you up with a slash w. So it's a little bit hard to read. It's a little bit hard to understand. Even if you take the time with the x mile fire to space down a little bit. So you see that you have three strings decibels, a string of identifier characters, and a string of, and a quote string down there. If you space it out, you see a little bit more. You don't have visual separation between the, between slash d and the slash w down there. A little bit more work, but you still really don't know what you're looking at. Unless you have a side-by-side copy of your data file to compare that to. So you see that, yes, x, y, and z match this, this, and this. You can do that as well. That's perfectly fine. You can match things that way. Add comments in. That's what the slash action is for. There's no expression a little bit more. Show more of what's going on. But you're still not one-to-one. You're still not the ideal self-documenting code. Some of you might by now be thinking of what was introduced in, I think, 516, the name match, like so. I don't, how many of you here have used the name match so far? Okay, not many. Okay. About four or five in the audience have actually used that or know what that is. This is a name catcher where you take a, where you take the string, say the slash d there and assign a name to it. I'm deliberately using generic names here for a reason. We'll get to that later on. But this is how it can look in 518. More documentive. If you're replacing number with, say, X, you'll get, you can get X, Y, Z for your corners on that. And have a better idea of what you're looking at. I had, I have forgotten actually about this for roughly a few years until they reminded me of that at the Pearl Conference in 20, in Amsterdam this year. I had forgotten completely about name captures in Pearl 5. They're not that well used feature. But in Pearl 6, what we do is we've taken that syntax and simplify it just a little bit. So, the one things that you probably also want to know as well is how to actually capture content. How do you read that? In this case, I'm assuming that we're using the cap E flag that you have, say, for that feature. And you use the slash, use dollar plus. Obvious, completely blindly intuitive to the two people that have used the at plus variable in Pearl. And the at minus, that tells you the range of matches. It is intuitive once you know what those, once you know that it relates to the at plus variable. Completely intuitive. Pearl 6, we're doing away with a lot of that. But we're leaving behind kind of a ghost, if you will, of the name capture. First thing we'll do is we'll use the module that I created. And we'll get rid of the description of the slash D. Now, what this gives us as well as just the backslash, as just a spring of digits, it gives us anything that Pearl 6 thinks is a number in there. So, if someone came along and used a half brick jumper in your design to go from 1 to 1.5, now you're covered. If you have something like a Star Destroyer that you need to use exponential numbers for, then by all means we've got that covered. We've got negative signs, we've got complex numbers covered. If you want to, if you have, say, a four-dimensional or TARDIS, or a real-life TARDIS and go back in time, we can use complex numbers to represent points if you really want to go that far. I'm also deliberately using the quote notation number here to avoid complicating things for those people coming in from moral profile mindset. The next thing we'll do to slim this down is get rid of those pesky parentheses. In Pearl 6, these captures are automatically named for us. You don't need fancy notation. So, they're named like that. The last thing that we're going to want to do here is just one small change. You'll notice on the last slide, I'm going to use saying slash, carrot, blah, blah, blah, slash, slash, carrot, blah, blah, blah, slash, and then plus to match. That's a little bit, a little bit off-putting. It doesn't quite match with what you actually see there in the Pearl code. There's no real mnemonic there. You would have to know, again, about the special variable plus to know that it is a capture variable. So, what we do in Pearl 6 is you have slash, slash, we use dollar slash. Much simpler. So, the next thing that we have in that spring, we have, aside from the idea of fire, we had a spring there in quotes. Now, the expression I show you there isn't quite, wouldn't quite work in Pearl 6, but in this case, the Regec, the Parmy-Rammer common model gives you a string to work with. So, we take the spring, we capture the, we capture the string, and you'll notice here that it comes back with the entire string along with the outside quotation marks. This isn't a problem in most languages. In JSON or C or C++ or Java, they don't really care about whether a spring is in double or single quotes or using cube, cube quotation marks. In Pearl, we care a little bit more about that. So, looking at this, you might be thinking, great, I've got the spring here as a blob, so now I've got to go back and figure out any what kind of string I'm starting with. Is it a QQ? Is double quote? Is single quote? And then match, strip off that in, strip off the back end matching, and then do some more work. Well, luckily for us, Pearl 6 supports not only regular captures, name captures, but nested name captures, like so. So, we have your spring and we decide to match the content directly. And the grammar common module, when it's finally released, we'll have an alias for that, so you'll have to type both layers in to match that. It'll just be like string-content in the final option as well. But you still get at the first and final quotation marks if you need that form. Parsing, say, another language that uses QQ or whatever, like maybe Pearl, one of those. So, Rails expressions are both... Rails expressions are... You can have name matches. You can still use the old parentheses. You can still use $1, $2, $3, and several like you did before. Although, like we simplified the plus to slash, we simplified and got rid of $0, so now your matches all start at $0. Instead of having to remember that, oh, yeah, because it is a match, you'll use $1 to use $1, $2, $3, $4 for parentheses. Now you use $0, $1, $2, $3, like every good programmer should start at $0. You might wonder how we would... If you have a lot of these values, say we have our x, y, and z numbers, you'll wonder how we separate those. You add an alias, like so. With color equal, you give that a function. You give that a name. And you're referenced by the original name of string or by the color. And you still pull in the content variable because it's still alias in that fashion. Simple. So Rails expressions are... You can capture them, you can nest them, and of course, like we said before, you have your name variables for name, x, name, y, et cetera, and still print these out. This would almost work in... This would almost work out in curl 5 as well. Just change the plus signs there and put back all the doys. And there's also a notation to do, at least to just use the x or y for the name capture. And also, you'll notice as well, the original string we have, backslash d, with no minus sign, now that we're using an actual number, we can go and use any type of number that we want. So when we find out later on that the file format's changed, or we find out that, oh, yeah, I forgot to add scientific notation to that, you're covered. With one module and one term, you're covered for all of that. Like the negative 3, 4 in this case. Now, we can get a little bit more complex, a little bit more depth. This is a Lego ball contraption made by a fellow by the name of Aki Yuki. His entire goal is to move balls from the left-hand side, obviously, through these rolling things, up to the top level of the black structure and then back down. It's part of a long chain of things, and the world record was set recently in 2018 for roughly, I think it was almost half a football field of these machines, considerably passing balls from one to another. Terrific clicking noise. A lot of fun to go watch. If you need noise, distraction, I highly recommend the link form of a Lego GBC great ball contraption video online if you need distraction. Now, we're talking back about MLCAD and how to work with Lego. This is kind of warm my speed. The thing is that, again, as a programmer, what I would want to do is instead of sitting in hand and by hand making one of these structures copy, turn, paste, copy, turn, paste, like so, all the time, what I want to do is do that, obviously, in purl. So, we have here alternating red and yellow stages as we go along this structure. Each one twists it just a little bit, move it up, twist, move up, that is ideally suited to automation. So, what do we want to do? Let's, instead of worrying about all of the looping constructs, let's just look at something simple like this. You have a MLCAD file now that this time has a variable in it and you do math. We have the layer, which will be the stack as you go up. So, each time you go up one, put on your red, go up one, put on your yellow and then repeat it. That way, we'll worry about rotation layer model, don't worry. Well, we'll get to that stage. But, again, we have a simple file but we have these terms here now for two times layer, two times layer plus one. How will we go ahead and throw that into our Perl 6 parser? Well, again, this is pretty easy to do. You have a number. You need to use double quotes, you need to use some sort of quotes around the star there because Perl 6 simplifies all of those rules about backslashes and gets rid of all that noise. All you need to know is if it's outside of the, if it's not a letter then it needs to be backslashed. I'm sorry, not a letter or a midi character. It needs to be backslashed. So, that way the slash, so the plus over here doesn't fall on that rule because that's a midi character. So, you can do things in this fashion and match that way. So you have number, star, ident. But then you have to do a whole bunch of number, star, ident, number plus, ident, number minus ident. A set of them. You have to go through do all those choices and maybe get something wrong and then forget that you forgot to add in number plus number, number minus number because someone may try to play around that format that way. So, what you would, so what we would do here is because we're good programmers and what to refactor, we would take our number plus number, number times number, and group it into a row expression. Like so. So this is how we create our own tags. You don't have to rely just on my model to get the number or get a spring. You can create your own. Like so. And it's just that easy. You say my regex and then regex name. Fault and use it just like you would use anything else. The expert here. And later on you say expert number because we can nest expressions. That includes expressions that you create. Those all get nested. So you say darl slash brace expert expert number. So the expert, so the number inside the expression and the identifier inside expression is done that way. But what we want to do there again is go one level further and why don't we just sort of hide that away? So we'll just change a little bit that. This time now we're using my module and this time what you do on your side is you create the value term over here which is a generic either a number or an identifier. Say a C identifier or a pearl identifier. By default it will be pearl. But for demonstration sake we'll say C. You take your expression you take the expression tag and drop it right into your expression. Slash, carrot and then expression and parse. Go on with life. And this will handle number plus number, number minus number, number times number. But also because pearl expression pearl expressions are recursive it can handle number times number plus number, number times parent to number plus number close parent and so on down nesting. This if you have tried if you've worked with any natural language parsing or parsing of say C this is where people tend to get tripped up when they start writing expressions. They will go through and write a expression that except the match what they need and then someone comes along and writes you know 2 plus a or a plus 2 turns around the order and your parser breaks. With this you don't need to worry you drop in the expression replacement. And you have the entire match tree available it will handle all standard C type expressions all standard pearl type expressions if you choose. And you get back the original text along with the full nesting as well. I separate inside there I use terms to separate things so I won't go too deep into the layers but unless you handle constructs like these yes pie over layer pie over one pie over two it's not quite the right calculation but the real calculation will not fit on screen. I thought about for about 15 minutes and I can't get it to quite fit on screen so we'll have to make do with this. But it will do the it will do the calculation for you. Sight unseen you don't need to worry about anything it drops in. It's a straightforward replacement and you don't need to go in and try to figure out how to do parentheses. You don't need to worry about how to do star, how to do times. You don't need to worry about okay is slash parts before star is star parts before white ship. You don't need to worry about any of that. The grammar model takes care of that for you. The last thing before we get into before we move into the bonus round here is we're going is formed by expressions. Because we've already talked about how they are as powerful at least as Perl 5. How they can be nested. How they are recursive, usually recursive. Expression matches on itself in fact and that you will find hard you'll find hard to that hard to do with languages such as bison or flex or yak. Those while they work out you take a while to figure out how that works. But again with a grammar model those problems are all gone. There's one more work here. The 7 point here some languages like a trailing like to have sorry like to require a trailing zero like trailing number like 1.2 trailing they're like that for the point numbers some will take 0.35 some don't like 7.1 or just bear 7. like Perl does. Perl 6 does. So one of the things that you'll want to do with your real expression is you can make two or three expressions and put them into your grammar and you'll have you may have problems down the road trying to figure out just what goes where you need spaces. So one thing that you do with your real expressions is remember that in Perl 6 real expressions are also functions that you pass in arguments to so if you want to so if you want to disallow the so if you want to disallow the barrage so if you want to make 7 point illegal because you only want 7.1 7.2 you take your expression your real expression and pass in this value one second alright luckily we've got just enough time to go into our bonus round party on ok so the last thing that I promised in the talk luckily we can cover a little bit of this and for this if there are questions if there are questions coming up I'll take them as they come because we need to go a little bit slower on this step so everyone can keep everyone can keep up the first thing that we want to do is get rid of a little bit more in our expression because we have all this white space here we have the slash s plus and then if you want to use if you want to make the optional slash s star we want to make that optional in pearl 6 we just want to make it go away instead of using the reg x we use the rule designation and then every term that you have say the x equal number y equal number string gets optional white space automatically you can write of course if you want but this just makes things a lot simpler a lot shorter you'll have to worry did I remember to put white space between the x and y did I remember between the plus and the star where do we go with the braces do we want a new line after that the rule will take care of all that for you so that trims down your code means you have less work less mental work process less work for you to do in the code and in this case like the reg x it's just another construct that you drop into your own code you'll drop in a parser for a line and by the way when I say parser I just to clarify this I truly mean an actual parser because these are both reg and they're also the same language that purl 6 uses to parse itself so when you have an expression that you manage you can actually parse a purl 6 expression one of the famous things that we use that we like to say about purl 5 is only purl 5 can parse purl 5 the nice thing about purl 6 is it's parsed in purl 6 it's not quite the same thing because you can take the purl 6 reg extension and re-informat that in C re-informat that in javascript which is already done take that reg extension and move it anywhere else and put your compiler on to any platform you want llvm, clang, jvm anything that anything that you take is for a expression engine from purl anything that you can do that with so purl 6 can move to any platform that we want now we have these we have our line here we're going to go just a little bit further here and take this line in our expressions and package them up into into any little package that we can move around to the mlcad grammar so we take that mlcad parser which truly is a parser much like the last talk and move that around and this time we have one more term a grammar here for those of you from the purl 5 community is basically a package with moose and special sauce so there are proper attributes it does compositions and more importantly just like moose it does rolls which is what grammar common is it's a roll that you drop into anything so you can take that and use it for whatever you like you can add that into your own parsers you can go in and just copy out bits of code if you like you can go in and add that to your own parser subclass that into whatever you like so that's what a grammar is it's just a fancy name for a class that has only rules and reg actions there's one on type but we won't get into that right now the important rule that you need to know for a grammar is the rule named top tlp all caps that's how purl 6 knows where to start parsing so when we take our string 10 space 20 space and then 2 times layer plus 1 when we take that that's where purl knows where to apply the parse it knows to start looking for the expression and label it x label y and so on we change of course the slashes are now the parse expression and of course we can go in and take a look at anything any of the objects I'm not going to show you the parse tree for this because it is a bit ugly but again the mong holes we have been using slashes all along and now we still use the slash for after the parse or copy or capture the value into a variable I don't have quite enough room on screen to fit then and again and again we have 2 again we have a complex expression and label numbers and all of that fun stuff so I'm a little bit have time here and I do apologize because we are down to the last slide for this so if you have questions now is the time so for the last thing one of the things that I promised in the talk and we are delivering is a is a actual interpreter because one of the things that we give you I give you alongside of the actual parser is you get a just a time interpreter for your language so when you have your expression as long as long as it only uses pure math this will handle pure math just fine if you try to add a string to a number you will get an odd result just like you would in say C so this becomes effectively a dropping this becomes a dropping interpreter so if you want to do if you want to take your program write out a file and do just a time interpretation maybe just fill in a few things this is a simple way to do that it I design things to be as simple as possible for this so you take you will take the model that you have here and drop it in and run you can use the basic you can use basic stuff like numbers, identifiers the numbers all come from the identifier terms all again come from either pearl or they are configurable for C or C++ values as well so I by no means fixate on pearl for this because the world is more complex the springs that we have here springs like these will take you can use that for say parsing JSON you can use that for parsing YAML you can use that for just raw identifier content and so on the expressions that you get over here for such things as two times later there is also a prefix and postfix so if you so if forth so forth if you speak then we got you covered on that so you can do new postfix expressions infix and prefix as well those are all covered and I am running a bit down here so if there are no questions out here as to where why would you want to use this why would anyone want to use this the first thing that comes to mind is doing say syntax highlighting for languages write your own highlighter write your own reformat utility one of the things that you can use this in in combination with is another of my modules Perl assist antler which takes a grammar for a language a grammar for language and like say C and turns it into Perl so you have a Perl compiler and you can use my tools to fill in the file bits that you want so