welcome back everybody to are
I'm lecture on parsing and lead
make it does on our first more net I am
grade and now we can move on
and lead look add
a an another operator
on partners that really
an make it into a moan at
and that is namely sequencing of bars
so what we want to do as we wanted a good barger
and not gonna you know try the other one that the first one failed
but we want to go to sequentially composed and so we don't do gonna run
one barger
and then run its terminated we want to run the next bars & Poor Dad we're going
to use this so called to duty and action to do 10 Dec
that's one of the advantages of having a moan at because now you can ride
code that looks I'm and out that makes this
sequential composition clear so here's what we all do it
ride so we want to ride the following are the day
drive to bars a nighttime
Golden Axe bars another item
I don't care and about that also I don't give a name
that bars a third IBM goal that why
and then return the pair of X common why
okay sorry to hear that were sequencing
these three barges I P M
a ever just returning the first and the Los
and now
if you look at a this code here
remember that we talked about to lay out a row so
all day right banks here must be lined up
really nice you can also good curly braces
and Jamie goes in there that actually well I usually do
and when I used to do notation because then it looks even more like Embarq it
got
I
and as we already showed
if you don't food is gone left arrow a and their
then the partners gold but they have resulted
discarded alright
so I'm the other thing is dead
when we're composing partner mokhiber barges in a row
what we want your help is dead you know when
any attempt failed the whole thing will fail and then we get always gonna
dry read the the triple plus do
you know you have another partial so I V Bar a.m.
every am bar here P
and that what are our example here
and would get it would take this guy and murdered
bars three characters and readers the first
and that their readers yet but if we tried to
applied at through a drink that only has two characters
then they won't work so it will fail
it will fail you see it here
failing eat their I'm failing
like departure okay so
when a barter any bars images aggression combos fails you want the whole
think bit okay and the other than
is dead the the real
advantage of having a Mon add as know that it makes you look smart
it is not that you're a cool kid it's not that you can ride
to millions blow up almost on explaining Mon at
their real advantage Mon at is that you can do
used to do notation a ride and
so that all there is to it
not a big deal a ride to allege
I'm grabbing your
riding show more partition here in this cage
assuming that we have this barger
that can do a.m. sequential composition
we're going to and ride
the following function that pink granite get
from care
after tubal and breeders a bar here
for character you hear that that don't be
or looking for a character that satisfies be
weep arsenide done it will trigger next
FBI hold every immediately returned act every dog chased the input
it be aback
does not halt then we have to
fail alright so this is
quite a bit we tried to bar any I don't
Demi Jack whether to grant a good haul if it holds
we use the bars are not always 6eh and
ever the Brotherhood does not hold for years the bar here that always felt
good notion does came in quite handy I'm
alright ledge years this
at bars are now to ride some interesting
at think so say that we want to parse it did
well what they can do it again today used it
Sat red is dead so not this thing will try to parse a character
check weather today did in that case it will imagery 16
that they did image know that they did it will fail
immediately I'm if you want to parse
specific character I'm here
got back and we can use sectioning
to grid the predicate
X it grows a quote so this is a function
expected character and checks rendered equal to act
and then we applied at set alright
sure you see a quite nice use of sectioning
in case you wondered why honored it is weird sectioning and have to go
up here you have an example up this
now some people won't say
%uh but you know they're X here and their action there
I can ride this point for each stock so maybe you should ride
you can ride this thing here
and point freestyle and again as I warned you
when used Ford Freestyle read from serb opposition and so on
you got your code might become quite unreadable
very quickly but in this case I think it's a nice challenge
to right this wrong. 13 and will nuke
quite nice okay but you get the next one here
it into a bar that drives to parse me
year or more times and you see the adopted like a regular expression or
repetition and I want to find you know
here are more digit maury by Buddha Bar
identify rwanda barcy and a letter
followed by a year or more identifiers or digits
so yeah digit often happens
when you're trying to parse think so here we see many
thank you barbara Bay and readers a bar sure
messed up and guess wat
this is defined recursively so many of me
first drive-through barcy at least won't be
and if that fails and returns and
the MPS are and you know will be slightly nicer to use the
parser dead always fail there now how do we write many want well
and really find that in terms of many sure we have here
mutual recursion definition so if I want to parse
be one or more times I tried to barge be wrong
I get the value P then I tried to
bar here or more times be
I got the value that can be dnt elective II
it by return them to let dad and
I have to apologize it is really regarding the empty let that up failing
because
if I'm bars be here are more time second bars and longtime
or hear adults and this year a dime I have to return the
let so I'm Atlas
something there so I we parted there
so we get here are more gone and never return
be concatenated with me
so this is the wrong time and Disney many good
is a so this is like this SUT gol mutual recursion
and very subtle I can even Eric made a mistake there
so you better pay attention okay
a las 10 here and her going to use a function
define a function that tries to parse a string
so far we have seen many examples very trying to parse
a character but I want a bar a strain
so if I want to am it might
and remember strings are just list of characters
so if i start red the MP lead
well I just returned the ampule at the empty string
and I'd try to parse is a character actor contacted
well I tried to barge a character actor I Rieger you need ride to bars
string that represents the rest of this thing and then
II return
the result well I found the neck
I returned that and I return that so I just
return district addicted checks rather dish during
is the prefix of my input good
so now we can define a parser that consumes alleged
a wall or mortgages from a string so this is starting to become more like a
no parking
an actual language so what we do we do is we want to bar the list
so we have to parse it and open brace and a close bread
right not interested in those values are you don't see
left arrow there memory trying to bargain digit
and then we're trying to parse many
character
coma digit okay because we will devilish
of wall or more digits so there's Wong digit
and and them or digit here
and then we just don't got in a dead they did but the other digits are you
see
how we got you know take old niece
elementary barger and combine them together
to ride a.m. already
pretty complicated bars like this every
a apply departure here on the list
on the lead God strain
but we want to barge that ring as a letter and
we'll see let me get the and
then just wanted 34 and and if we're trying to
parted on something that hasn't you know at mother brother last
we will get an error okay
now courted head as you read that bitch is heard
super simple barger and if you want a ride
a real cars are if you want to you know our
use a bar here in real God you definitely want to do something smart to
render errors and Justin are returning the MTS
agree you want to go to No if the position
in the AM blessed right things go wrong are you a good ride to
correct errors or whatever but again we're trying to
go over here very very basics of parsing
and there's plenty of parking libraries perhaps call
and for other languages that are based on this day my dear
that at all these more sophisticated features
thank you very much and CEO
an ex parte