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
02186451
Commit
02186451
authored
5 years ago
by
AdminXVII
Browse files
Options
Downloads
Patches
Plain Diff
Use the std-native functions instead of hand-rolled ones
parent
1d02419d
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/lib/parser/statement/functions.rs
+2
-2
2 additions, 2 deletions
src/lib/parser/statement/functions.rs
src/lib/parser/statement/mod.rs
+0
-38
0 additions, 38 deletions
src/lib/parser/statement/mod.rs
with
2 additions
and
40 deletions
src/lib/parser/statement/functions.rs
+
2
−
2
View file @
02186451
use
super
::
split_pattern
;
use
crate
::
parser
::
lexers
::
assignments
::{
KeyBuf
,
KeyIterator
,
TypeError
};
use
crate
::
parser
::
lexers
::
assignments
::{
KeyBuf
,
KeyIterator
,
TypeError
};
use
err_derive
::
Error
;
use
err_derive
::
Error
;
...
@@ -14,7 +13,8 @@ pub enum FunctionParseError {
...
@@ -14,7 +13,8 @@ pub enum FunctionParseError {
/// converted into a tuple consisting of a `KeyIterator` iterator, which will collect type
/// converted into a tuple consisting of a `KeyIterator` iterator, which will collect type
/// information, and an optional description of the function.
/// information, and an optional description of the function.
pub
fn
parse_function
(
arg
:
&
str
)
->
(
KeyIterator
<
'_
>
,
Option
<&
str
>
)
{
pub
fn
parse_function
(
arg
:
&
str
)
->
(
KeyIterator
<
'_
>
,
Option
<&
str
>
)
{
let
(
args
,
description
)
=
split_pattern
(
arg
,
"--"
);
let
mut
parts
=
arg
.splitn
(
2
,
"--"
);
let
(
args
,
description
)
=
(
parts
.next
()
.unwrap
()
.trim
(),
parts
.next
()
.map
(
str
::
trim
));
(
KeyIterator
::
new
(
args
),
description
)
(
KeyIterator
::
new
(
args
),
description
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib/parser/statement/mod.rs
+
0
−
38
View file @
02186451
...
@@ -103,41 +103,3 @@ pub fn parse_and_validate<'b>(
...
@@ -103,41 +103,3 @@ pub fn parse_and_validate<'b>(
StatementVariant
::
Default
(
statement
)
=>
parse
(
statement
,
builtins
),
StatementVariant
::
Default
(
statement
)
=>
parse
(
statement
,
builtins
),
}
}
}
}
/// Splits a string into two, based on a given pattern. We know that the first string will always
/// exist, but if the pattern is not found, or no string follows the pattern, then the second
/// string will not exist. Useful for splitting the function expression by the "--" pattern.
fn
split_pattern
<
'a
>
(
arg
:
&
'a
str
,
pattern
:
&
str
)
->
(
&
'a
str
,
Option
<&
'a
str
>
)
{
match
arg
.find
(
pattern
)
{
Some
(
pos
)
=>
{
let
args
=
&
arg
[
..
pos
]
.trim
();
let
comment
=
&
arg
[
pos
+
pattern
.len
()
..
]
.trim
();
if
comment
.is_empty
()
{
(
args
,
None
)
}
else
{
(
args
,
Some
(
comment
))
}
}
None
=>
(
arg
,
None
),
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
statement_pattern_splitting
()
{
let
(
args
,
description
)
=
split_pattern
(
"a:int b:bool -- a comment"
,
"--"
);
assert_eq!
(
args
,
"a:int b:bool"
);
assert_eq!
(
description
,
Some
(
"a comment"
));
let
(
args
,
description
)
=
split_pattern
(
"a --"
,
"--"
);
assert_eq!
(
args
,
"a"
);
assert_eq!
(
description
,
None
);
let
(
args
,
description
)
=
split_pattern
(
"a"
,
"--"
);
assert_eq!
(
args
,
"a"
);
assert_eq!
(
description
,
None
);
}
}
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