Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Enzo Cioppettini
ion
Commits
a09aa7d6
Commit
a09aa7d6
authored
7 years ago
by
Michael Aaron Murphy
Browse files
Options
Downloads
Patches
Plain Diff
Refactor quote termination logic
parent
9f8e9e53
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shell/binary/mod.rs
+5
-42
5 additions, 42 deletions
src/shell/binary/mod.rs
src/shell/binary/terminate.rs
+51
-0
51 additions, 0 deletions
src/shell/binary/terminate.rs
with
56 additions
and
42 deletions
src/shell/binary/mod.rs
+
5
−
42
View file @
a09aa7d6
//! Contains the binary logic of Ion.
//! Contains the binary logic of Ion.
mod
prompt
;
mod
prompt
;
mod
readln
;
mod
readln
;
mod
terminate
;
use
self
::
prompt
::{
prompt
,
prompt_fn
};
use
self
::
prompt
::{
prompt
,
prompt_fn
};
use
self
::
readln
::
readln
;
use
self
::
readln
::
readln
;
use
self
::
terminate
::{
terminate_quotes
,
terminate_script_quotes
};
use
super
::{
FlowLogic
,
JobControl
,
Shell
,
ShellHistory
};
use
super
::{
FlowLogic
,
JobControl
,
Shell
,
ShellHistory
};
use
super
::
flags
::
*
;
use
super
::
flags
::
*
;
use
super
::
flow_control
::
Statement
;
use
super
::
flow_control
::
Statement
;
use
super
::
library
::
IonLibrary
;
use
super
::
library
::
IonLibrary
;
use
super
::
status
::
*
;
use
super
::
status
::
*
;
use
liner
::{
Buffer
,
Context
};
use
liner
::{
Buffer
,
Context
};
use
parser
::
QuoteTerminator
;
use
smallvec
::
SmallVec
;
use
smallvec
::
SmallVec
;
use
std
::
env
;
use
std
::
env
;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
...
@@ -49,50 +50,12 @@ impl Binary for Shell {
...
@@ -49,50 +50,12 @@ impl Binary for Shell {
fn
readln
(
&
mut
self
)
->
Option
<
String
>
{
readln
(
self
)
}
fn
readln
(
&
mut
self
)
->
Option
<
String
>
{
readln
(
self
)
}
fn
terminate_script_quotes
<
I
:
Iterator
<
Item
=
String
>>
(
&
mut
self
,
mut
lines
:
I
)
->
i32
{
fn
terminate_script_quotes
<
I
:
Iterator
<
Item
=
String
>>
(
&
mut
self
,
lines
:
I
)
->
i32
{
while
let
Some
(
command
)
=
lines
.next
()
{
terminate_script_quotes
(
self
,
lines
)
let
mut
buffer
=
QuoteTerminator
::
new
(
command
);
while
!
buffer
.check_termination
()
{
loop
{
if
let
Some
(
command
)
=
lines
.next
()
{
buffer
.append
(
command
);
break
;
}
else
{
let
stderr
=
io
::
stderr
();
let
_
=
writeln!
(
stderr
.lock
(),
"ion: unterminated quote in script"
);
return
FAILURE
;
}
}
}
self
.on_command
(
&
buffer
.consume
());
}
// The flow control level being non zero means that we have a statement that has
// only been partially parsed.
if
self
.flow_control.level
!=
0
{
eprintln!
(
"ion: unexpected end of script: expected end block for `{}`"
,
self
.flow_control.current_statement
.short
()
);
return
FAILURE
;
}
SUCCESS
}
}
fn
terminate_quotes
(
&
mut
self
,
command
:
String
)
->
Result
<
String
,
()
>
{
fn
terminate_quotes
(
&
mut
self
,
command
:
String
)
->
Result
<
String
,
()
>
{
let
mut
buffer
=
QuoteTerminator
::
new
(
command
);
terminate_quotes
(
self
,
command
)
self
.flow_control.level
+=
1
;
while
!
buffer
.check_termination
()
{
if
let
Some
(
command
)
=
self
.readln
()
{
buffer
.append
(
command
);
}
else
{
return
Err
(());
}
}
self
.flow_control.level
-=
1
;
let
terminated
=
buffer
.consume
();
Ok
(
terminated
)
}
}
fn
execute_arguments
<
A
:
Iterator
<
Item
=
String
>>
(
&
mut
self
,
mut
args
:
A
)
{
fn
execute_arguments
<
A
:
Iterator
<
Item
=
String
>>
(
&
mut
self
,
mut
args
:
A
)
{
...
...
This diff is collapsed.
Click to expand it.
src/shell/binary/terminate.rs
0 → 100644
+
51
−
0
View file @
a09aa7d6
use
super
::
super
::{
Binary
,
FlowLogic
,
Shell
};
use
super
::
super
::
status
::
*
;
use
parser
::
QuoteTerminator
;
pub
(
crate
)
fn
terminate_script_quotes
<
I
:
Iterator
<
Item
=
String
>>
(
shell
:
&
mut
Shell
,
mut
lines
:
I
,
)
->
i32
{
while
let
Some
(
command
)
=
lines
.next
()
{
let
mut
buffer
=
QuoteTerminator
::
new
(
command
);
while
!
buffer
.check_termination
()
{
loop
{
if
let
Some
(
command
)
=
lines
.next
()
{
buffer
.append
(
command
);
break
;
}
else
{
eprintln!
(
"ion: unterminated quote in script"
);
return
FAILURE
;
}
}
}
shell
.on_command
(
&
buffer
.consume
());
}
// The flow control level being non zero means that we have a statement that has
// only been partially parsed.
if
shell
.flow_control.level
!=
0
{
eprintln!
(
"ion: unexpected end of script: expected end block for `{}`"
,
shell
.flow_control.current_statement
.short
()
);
return
FAILURE
;
}
SUCCESS
}
pub
(
crate
)
fn
terminate_quotes
(
shell
:
&
mut
Shell
,
command
:
String
)
->
Result
<
String
,
()
>
{
let
mut
buffer
=
QuoteTerminator
::
new
(
command
);
shell
.flow_control.level
+=
1
;
while
!
buffer
.check_termination
()
{
if
let
Some
(
command
)
=
shell
.readln
()
{
buffer
.append
(
command
);
}
else
{
return
Err
(());
}
}
shell
.flow_control.level
-=
1
;
let
terminated
=
buffer
.consume
();
Ok
(
terminated
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment