background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Creating a new programming language with Rust Part 48: The last feature"

input logo icon
Cover of audio
Please wait. We're preparing links for easy ad-free video watching and downloading.
console placeholder icon
Video tags
|

Video tags

creating
new
programming
language
rust
part
48:
last
feature
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:00
I hope you're ready for this video
00:00:02
because we're gonna do something
00:00:05
never before seen
00:00:08
probably not really but
00:00:11
so
00:00:13
our interpreter is almost done I mean it
00:00:17
is a fully working programming language
00:00:18
now with
00:00:20
with a first class functions
00:00:24
classes inheritance and things like that
00:00:30
we have one custom feature already which
00:00:33
is
00:00:34
the pipe operator let's actually
00:00:38
have a look at that
00:00:41
so it's in the parser there should be
00:00:45
here we go
00:00:47
so
00:00:49
we have this idea for pipe operator
00:00:53
which looks like this and what it does
00:00:56
is it takes
00:00:59
this thing on the right hand side and
00:01:00
applies it to a
00:01:03
the reason I like that is because let's
00:01:05
look in here
00:01:08
um it's a couple of examples
00:01:11
let's say I have a pipeline a processing
00:01:13
pipeline and what I can do is
00:01:16
I can say take some input data then
00:01:19
apply this function then run another
00:01:21
function
00:01:23
so that's very nice for these kind of
00:01:25
Pipelines
00:01:27
and workflows
00:01:29
a and I had this idea that maybe this
00:01:33
language could be a language for
00:01:37
writing
00:01:39
automation scripts on the command line
00:01:43
so basically like an advanced form of
00:01:46
batch scripting that also has classes
00:01:48
and so on and the way I wanted to to
00:01:51
achieve that is
00:01:56
um
00:01:58
with a syntax
00:02:01
that looks like this
00:02:04
so let's say you define
00:02:07
something
00:02:13
I'm not sure if I want it let's let's
00:02:15
remove that so
00:02:17
you have a variable name an identifier
00:02:19
rather and then you have this
00:02:21
Arrow call it gets or whatever so
00:02:24
command gets
00:02:26
and then you write a
00:02:30
a command line
00:02:32
thing so let's say
00:02:33
[Music]
00:02:35
um Echo
00:02:38
on the command line
00:02:41
so actually what happens if I run this I
00:02:43
go on the command line
00:02:48
we'll just say Okay so that works as I
00:02:50
thought
00:02:54
then this should produce a function down
00:02:57
to the name command so then if I do this
00:03:01
actually let's write a semicolon then if
00:03:04
I write command like that if I call it
00:03:07
it should just say
00:03:12
actually what I would like is for the
00:03:14
verse
00:03:16
for
00:03:17
this
00:03:19
the output of the command to be captured
00:03:21
in a variable so I actually want to say
00:03:23
something like
00:03:25
the result is this and then we can print
00:03:27
it so
00:03:32
and then we get something like that
00:03:34
so how do we achieve that
00:03:37
so if we actually
00:03:41
the first thing I want to do what I need
00:03:43
to do is to go in here into the tokens
00:03:49
the token types rather
00:03:52
and we're going to add a new
00:03:54
character that we will call
00:03:57
gets
00:03:59
gets
00:04:00
and that's going to be this one
00:04:03
then up here in the scanner
00:04:10
if we find this character then we need
00:04:13
to check
00:04:17
something like else if
00:04:20
the next one is minus sign then we
00:04:25
should
00:04:26
return cats
00:04:30
otherwise
00:04:34
we just assume it's
00:04:40
it's less let me look at this one
00:04:45
okay so if it matches correctly
00:04:48
it also advances
00:04:51
so we could
00:04:55
we could write a quick test
00:04:57
it just looks like this
00:05:00
here we have some source code command
00:05:02
gets Echo hello we make a scanner on
00:05:06
that source code we scan the tokens
00:05:09
then we assert on some things
00:05:14
first token should be an identifier then
00:05:16
it should be gets the gets token then
00:05:19
should be a string literal then it
00:05:22
should be a semicolon and finally an
00:05:25
enter file
00:05:26
and
00:05:29
if I run that test
00:05:35
then you can see it passes
00:05:37
so now let's go into the parser
00:05:40
so if you want to keep this syntax that
00:05:42
we just looked at
00:05:45
then once we pass we actually end up in
00:05:48
a statement
00:05:51
and
00:05:52
there's no
00:05:55
print keyword there's no left braces no
00:05:58
if there's no while there's no return
00:05:59
it's just an expression statement
00:06:02
and
00:06:03
it will consume an expression
00:06:07
and it will try to consume an assignment
00:06:11
so
00:06:18
I am a little bit worried about the
00:06:20
conflict with this but
00:06:23
that we can worry about for another day
00:06:28
so if you match the equals token
00:06:31
it's just a normal
00:06:33
assignments
00:06:41
but now if we match
00:06:45
the
00:06:48
gets token
00:06:52
then we need to do something
00:06:54
and we need to
00:06:59
we need to
00:07:02
get the right hand side and that can
00:07:04
just be an expression so I think this
00:07:06
probably
00:07:08
is
00:07:12
that's a little bit annoying so okay so
00:07:15
let's get the right hand side
00:07:17
would be an expression
00:07:20
and
00:07:25
then we need to make a callable
00:07:32
so how is it we do that
00:07:36
this guy is a coal
00:07:40
actually I think we have we have kind of
00:07:43
a problem here so I think this
00:07:48
thing that we're doing now should be a
00:07:51
statement similar to
00:07:54
a function declaration
00:08:00
so if we go
00:08:03
up here
00:08:09
okay let me take a look at this one
00:08:16
yeah so this is making an expression so
00:08:18
we hmm
00:08:21
how do we want to do this
00:08:24
maybe we we could make a new keyword
00:08:35
um
00:08:42
so actually let's
00:08:49
now we cannot do what what do we want
00:08:51
the keyword to be
00:08:56
because I don't want to do like look
00:08:57
ahead passing where we
00:09:03
that is not nice so
00:09:09
maybe we can just
00:09:12
do this
00:09:15
because it is kind of a function that
00:09:17
we're making so space that's consistent
00:09:21
so anyway
00:09:23
then we go
00:09:27
then we'll hit this this one so okay
00:09:30
we're making a function
00:09:32
we consume an identifier
00:09:36
then
00:09:37
we have to actually go somewhere else so
00:09:40
we have to say if
00:09:42
we are matching a gets token
00:09:48
then we need to return
00:09:52
self that gets
00:09:54
statement
00:09:57
and I think that's fine
00:10:05
so we'll make
00:10:08
this guy
00:10:14
okay
00:10:17
actually
00:10:19
so we have the name
00:10:23
and this should then return
00:10:27
overall this should return a
00:10:30
function
00:10:33
so let's say return okay
00:10:36
phone actually statement
00:10:40
function
00:10:42
like down here right
00:10:44
name parameters
00:10:47
so the name is the name
00:10:50
the parameters is an empty vector
00:10:53
and
00:10:55
the body is
00:11:00
let's call it let's call it command body
00:11:13
I don't know maybe it should be
00:11:20
it should be like a brand new type of
00:11:22
statement
00:11:28
I think that's fine so let's call it a
00:11:32
command function it has a name there's
00:11:35
no arguments
00:11:37
and then it just has
00:11:41
and let's call it the command which is a
00:11:43
string
00:11:47
and then we go back to the parser we're
00:11:50
not going to obtain a function we're
00:11:52
gonna return a command function which is
00:11:55
a name and
00:11:58
it has
00:12:00
so let's say
00:12:06
how do we consume specifically a string
00:12:12
by the way this one we can remove
00:12:15
it's a bit too much
00:12:25
we can consume a token type
00:12:30
and a string a token type
00:12:34
well we have string literal
00:12:39
which is a token type so we can actually
00:12:42
say
00:12:45
inside function
00:12:48
can say
00:12:50
that
00:12:53
the command body itself that consume a
00:12:58
string literal
00:13:01
and then
00:13:06
yeah whatever
00:13:09
this doesn't make any sense
00:13:11
why would we unwrap the we can do this
00:13:15
let's see
00:13:19
yeah this one is called command
00:13:33
so what is this one con returning again
00:13:35
it's returning a token
00:13:39
and
00:13:42
what does the token have
00:13:49
now I have to go check that
00:13:51
draw a token
00:13:53
has the token type has the leg seam so I
00:13:56
guess is the
00:14:02
oh we can take the literal
00:14:07
value
00:14:11
let's let's take the leg stream that
00:14:14
should be okay
00:14:21
and there we go
00:14:24
so now we have this specific
00:14:29
statement so now let's see there's going
00:14:31
to be a bunch of errors
00:14:34
for example
00:14:37
Insight statement
00:14:46
and
00:14:49
Shake instead inside there is solver
00:14:58
is
00:15:05
so actually
00:15:10
what do we want to do with this
00:15:13
it's kind of like a variable declaration
00:15:16
so let's treat it like that
00:15:24
and that should work so let's say
00:15:26
resolve variable
00:15:31
like so
00:15:35
see what else we can find
00:15:38
something in The Interpreter
00:15:43
and
00:15:45
okay so this is the fun part
00:15:49
now we have a command function
00:15:51
and when that is being interpreted we
00:15:53
need to return a callable that
00:15:58
runs
00:16:07
and runs a shell command
00:16:12
captures the STD out
00:16:17
and returns it in a string
00:16:22
something like that
00:16:28
so first
00:16:31
we need to make a callable
00:16:34
now what is what is inside a callable
00:16:41
it's a name
00:16:47
it's an airity it's a parent environment
00:16:53
uh some parameters and a body the body
00:16:58
is a list of statements
00:17:01
so actually I don't want to make a lux
00:17:09
function
00:17:11
I guess I maybe I want to treat it like
00:17:17
a native function where is it we have
00:17:19
that
00:17:23
okay we have some
00:17:26
nature function nature function
00:17:30
yeah a native function is just some
00:17:35
something like this and we have an
00:17:38
example of it in here
00:17:42
I'm just gonna
00:17:45
get this for reference
00:17:47
and not in here rather in here
00:17:52
okay
00:18:02
great
00:18:05
so we want to make a local function
00:18:11
that calls to the command line
00:18:19
so let's do like that
00:18:24
and
00:18:26
what's it complaining about
00:18:31
I can't just remove that for now
00:18:34
how
00:18:37
is it you make closures am I like losing
00:18:39
my mind right now
00:18:42
okay the the problem is this thing
00:18:46
and then this is wrong
00:18:48
should be like that okay great
00:18:52
anyway
00:18:53
okay after a lot of struggling with the
00:18:57
power check I guess
00:19:00
here is the code
00:19:04
you
00:19:05
interpret a command function statement
00:19:08
like this we have a name and we have the
00:19:10
command itself
00:19:12
we need to make a local clone don't ask
00:19:14
me why it's I mean it's basically to get
00:19:17
the data out of this reference that we
00:19:19
have up here this is actually a
00:19:20
reference or something
00:19:22
then we move that clone into the closure
00:19:27
we need to clone it again so that
00:19:31
uh the closure can use the data again
00:19:34
and again and again
00:19:37
but anyway we put that command into a
00:19:39
command type from
00:19:42
STD process command
00:19:47
we get the output we just forcibly
00:19:49
unwrap it
00:19:50
could be better
00:19:52
could be worse
00:19:53
then we return the output as a string
00:19:57
value
00:19:59
then we create a function value out of
00:20:01
that
00:20:02
which is a native function
00:20:06
and
00:20:09
it has the name that it's been given and
00:20:12
it has this function and then we Define
00:20:14
that
00:20:16
function in here
00:20:19
so let's run cover check again nothing
00:20:23
there
00:20:24
let's
00:20:26
take a look at this one again
00:20:30
so if we run it
00:20:34
cases Echo command what happens
00:20:38
expected
00:20:42
I wonder
00:20:50
like what the hell so we sit up here
00:20:55
yeah it's for some reason it's not
00:20:59
so it should be in here
00:21:03
consume a string literal
00:21:08
and
00:21:22
it's fine I don't know I don't know
00:21:23
what's happening so let's consume a
00:21:25
semicolon
00:21:27
do that run the same command again
00:21:32
so where is it saying that expected
00:21:37
ah so in the variable declaration
00:21:42
and why
00:21:48
let's get rid of that one
00:21:52
inheritance within its thought ahead
00:21:55
killed you
00:21:57
anyway
00:22:05
but it is for sure complaining here
00:22:13
all right
00:22:18
so
00:22:21
let's try to think about what the pass
00:22:23
does
00:22:25
gets a declaration
00:22:28
there's no VA token so we should hit
00:22:32
this statement
00:22:35
ah
00:22:36
now it's because we had actually changed
00:22:39
the
00:22:40
syntax
00:22:42
and it should look like that
00:22:47
and now it's saying expected expression
00:22:53
and
00:22:56
I have no idea where that is coming from
00:22:59
it's coming from in here
00:23:04
which is the parser
00:23:07
okay fair enough
00:23:13
so we should go here and we should say
00:23:16
passing gets
00:23:21
that works
00:23:26
command body is that
00:23:29
command body is token stringlet which
00:23:33
has that leg seam which has a
00:23:38
literal and some line number whatever
00:23:43
and then we
00:23:49
we will consume a semicolon
00:23:55
run that
00:23:59
okay
00:24:02
now we have another problem
00:24:05
the resolver
00:24:07
which has to do
00:24:12
with this hack with it most likely so
00:24:14
let's go in here
00:24:16
yeah so it's actually not supported so
00:24:19
let's say
00:24:21
if it is a command function
00:24:25
with a name and a commands which
00:24:28
probably don't need
00:24:34
then we do something and we will do
00:24:38
clear of the name
00:24:40
and the Define of the name there's no
00:24:46
need to
00:24:49
there's nothing in the
00:24:51
command we can
00:24:53
resolve so what is it now saying
00:24:59
it is saying something something
00:25:02
because I need this
00:25:11
right okay
00:25:13
so then we
00:25:15
need to go here and let's change this
00:25:17
unwrap because I have a
00:25:20
suspicion that this is what's happening
00:25:22
let's change this to an expect
00:25:24
and we'll say
00:25:27
failed
00:25:37
we'll say fail to run commands
00:25:40
I've done this
00:25:42
Panic at Fields run command
00:25:46
and it doesn't like what's
00:25:50
we have given it
00:25:52
and the reason is
00:25:54
so let's say
00:25:57
command that clone and let's say
00:26:00
it's become
00:26:02
command is a command
00:26:05
new Okay so
00:26:14
how do we split
00:26:20
thank you
00:26:21
we have any of that in this project
00:26:24
yeah we have this one
00:26:32
so you can say command that's split
00:26:34
Maybe
00:26:39
this one will have the first part
00:26:43
and then we can say
00:26:46
for
00:26:50
exactly
00:26:55
and this one has to be mutable in that
00:26:57
case
00:26:58
okay so what we're doing is we're taking
00:27:01
the command we're splitting it by white
00:27:03
space
00:27:04
the first part is the name of the
00:27:05
commander the rest is treated as
00:27:07
arguments
00:27:09
and then we can finally say
00:27:12
that the output is the output of this
00:27:14
command and let's say failed command now
00:27:17
I'm also a little bit worried that this
00:27:19
will not work
00:27:20
but let's try
00:27:26
a first again
00:27:30
so let's try actually a simpler one
00:27:36
we'll call Echo hello
00:27:46
hmm
00:27:48
so for some reason it's still failing
00:27:51
so what I want to do is to check what we
00:27:54
did in here so
00:27:57
[Music]
00:28:00
what that is
00:28:04
what does e mean
00:28:19
okay I have no idea what that means but
00:28:22
it should be relevant
00:28:26
can we print this
00:28:32
yeah running command that thing
00:28:42
it's
00:28:48
ah crack around me so so that was wrong
00:28:50
we need to say
00:28:54
okay running command
00:28:56
Echo
00:28:59
hello
00:29:05
and what's with
00:29:18
what's with this escaping
00:29:22
so something clearly went wrong
00:29:31
Amanda was
00:29:34
something
00:29:38
command was Echo hello
00:29:41
great and what is the
00:29:44
parts
00:29:46
exactly
00:29:50
so something funny happened here
00:30:00
foreign
00:30:02
I think the problem is
00:30:15
not a not a
00:30:21
how do we pass a
00:30:28
drink
00:30:31
literal
00:30:54
yeah so the problem is literally this
00:31:01
weird escaping that it's doing which is
00:31:04
really
00:31:07
Pizza
00:31:16
so can I do replace
00:31:21
yeah that's the same here
00:31:25
let's see if that works
00:31:30
and it's also making a new line which I
00:31:34
guess is fine
00:31:38
button means we need to fix up here
00:31:44
something like that now let's run the
00:31:46
tests
00:31:53
yeah and also there's a test here that's
00:31:56
failing now
00:31:58
hmm
00:32:03
right
00:32:06
so this has to be six now
00:32:09
then we have to
00:32:13
make another one of those we have to
00:32:17
increment that didn't work as I had
00:32:21
imagined
00:32:29
why does it do it like that one two
00:32:31
three
00:32:36
okay
00:32:37
nevermind
00:32:45
right and what is this fun thing
00:32:48
it's just fun
00:32:55
now it says passes
00:32:57
now everything passes
00:33:03
so now we have a scripting language
00:33:05
where there is building support for
00:33:08
command line stuff
00:33:13
so I think that's pretty cool
00:33:18
so here's just a fun example of what you
00:33:20
could do
00:33:21
let's define a command where we grip for
00:33:24
the word grip inside of this file that
00:33:28
we're in and that should actually return
00:33:31
this line
00:33:34
okay so let's put that line here and
00:33:37
then there's the extra new line
00:33:40
so let's run that
00:33:45
and
00:33:46
well now we have
00:33:49
kind of a problem that I didn't think
00:33:50
about that it will also produce
00:33:55
this line but then if we put that line
00:33:58
it will now produce
00:34:02
that line as well
00:34:04
so there's actually no way we can make
00:34:06
this work so let's let's
00:34:09
um
00:34:12
the script for result instead and that
00:34:15
should just give us those two lines
00:34:25
and extra new line and now it will now
00:34:28
it doesn't work no matter what you do uh
00:34:32
okay we have to grab some other file
00:34:36
we will
00:34:39
grip
00:34:40
the
00:34:42
Echo command thing
00:34:45
and we prefer results
00:34:48
and actually just repeat that as well so
00:34:50
let's try to run that now
00:34:53
okay that's
00:34:55
worked so let's run tests
00:35:00
and it failed
00:35:07
it failed
00:35:09
this one
00:35:21
oops
00:35:22
cases itself
00:35:29
funny when I run here it works but when
00:35:32
I run it here it
00:35:35
does not work
00:35:45
okay so that has to do with how
00:35:47
variables are captured out of something
00:35:48
when we run it we can see it works and
00:35:51
that's going to be enough for now
00:35:54
and
00:35:55
that's it there you have it uh we just
00:35:59
invented bash 2.0
00:36:01
see you in the next one

Description:

Source code: https://gitlab.com/codescope-reference/cii

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Creating a new programming language with Rust Part 48: The last feature" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Creating a new programming language with Rust Part 48: The last feature" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Creating a new programming language with Rust Part 48: The last feature" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Creating a new programming language with Rust Part 48: The last feature" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Creating a new programming language with Rust Part 48: The last feature"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Creating a new programming language with Rust Part 48: The last feature"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.