Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
parsetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
parsetest
Commits
909360a2
Commit
909360a2
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
3a52eec7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/app.rs
+3
-1
3 additions, 1 deletion
examples/app.rs
src/lib.rs
+20
-16
20 additions, 16 deletions
src/lib.rs
with
23 additions
and
17 deletions
examples/app.rs
+
3
−
1
View file @
909360a2
...
@@ -4,7 +4,9 @@ extern crate parsetest;
...
@@ -4,7 +4,9 @@ extern crate parsetest;
use
parsetest
::
app
;
use
parsetest
::
app
;
app!
{
app!
{
id1
,
id2
id1
,
id2
,
id2
,
}
}
fn
main
()
{
fn
main
()
{
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
20
−
16
View file @
909360a2
#![feature(proc_macro)]
#![feature(proc_macro)]
extern
crate
proc_macro
;
extern
crate
proc_macro
;
extern
crate
proc_macro2
as
pm2
;
#[macro_use]
#[macro_use]
extern
crate
quote
;
extern
crate
quote
;
#[macro_use]
#[macro_use]
...
@@ -24,10 +25,7 @@ pub fn lit(input: TokenStream) -> TokenStream {
...
@@ -24,10 +25,7 @@ pub fn lit(input: TokenStream) -> TokenStream {
if
!
(
10
<=
value
&&
value
<
100
)
{
if
!
(
10
<=
value
&&
value
<
100
)
{
v
.span
()
v
.span
()
.unstable
()
.unstable
()
.error
(
format!
(
.error
(
format!
(
"expected literal 10 <= x < 100, got {}"
,
value
,))
"expected literal 10 <= x < 100, got {}"
,
value
,
))
.emit
();
.emit
();
}
}
From
::
from
(
v
.into_tokens
())
From
::
from
(
v
.into_tokens
())
...
@@ -43,10 +41,7 @@ pub fn lite(input: TokenStream) -> TokenStream {
...
@@ -43,10 +41,7 @@ pub fn lite(input: TokenStream) -> TokenStream {
if
!
(
10
<=
value
&&
value
<
100
)
{
if
!
(
10
<=
value
&&
value
<
100
)
{
v
.span
()
v
.span
()
.unstable
()
.unstable
()
.error
(
format!
(
.error
(
format!
(
"expected literal 10 <= x < 100, got {}"
,
value
,))
"expected literal 10 <= x < 100, got {}"
,
value
,
))
.emit
();
.emit
();
}
}
From
::
from
(
v
.into_tokens
())
From
::
from
(
v
.into_tokens
())
...
@@ -61,8 +56,6 @@ pub fn lite(input: TokenStream) -> TokenStream {
...
@@ -61,8 +56,6 @@ pub fn lite(input: TokenStream) -> TokenStream {
}
}
}
}
use
syn
::
Path
;
enum
AppKeys
{
enum
AppKeys
{
Device
,
Device
,
Resources
,
Resources
,
...
@@ -107,24 +100,35 @@ fn to_app_keys(id: Ident) -> Option<AppKeys> {
...
@@ -107,24 +100,35 @@ fn to_app_keys(id: Ident) -> Option<AppKeys> {
// }
// }
use
syn
::
punctuated
::
Punctuated
;
use
syn
::
punctuated
::
Punctuated
;
struct
AppK
{}
struct
KeyVal
{
struct
KeyVal
{
kv
:
Punctuated
<
Ident
,
Token!
[,]
>
,
key
:
Ident
,
val
:
pm2
::
TokenStream
,
}
}
impl
Synom
for
KeyVal
{
impl
Synom
for
KeyVal
{
named!
(
parse
->
Self
,
do_parse!
(
named!
(
parse
->
Self
,
do_parse!
(
kv
:
call!
(
Punctuated
::
parse_terminated_nonempty
)
>>
key
:
call!
(
Ident
::
parse
)
>>
(
KeyVal
{
kv
})
val
:
call!
(
pm2
::
TokenStream
::
parse
)
>>
(
KeyVal
{
key
,
val
})
));
}
struct
KeyVals
{
keyvals
:
Punctuated
<
Ident
,
Token!
[,]
>
,
}
impl
Synom
for
KeyVals
{
named!
(
parse
->
Self
,
do_parse!
(
keyvals
:
call!
(
Punctuated
::
parse_terminated_nonempty
)
>>
(
KeyVals
{
keyvals
})
));
));
}
}
#[proc_macro]
#[proc_macro]
pub
fn
app
(
input
:
TokenStream
)
->
TokenStream
{
pub
fn
app
(
input
:
TokenStream
)
->
TokenStream
{
println!
(
"-- app --"
);
println!
(
"-- app --"
);
let
k
:
KeyVal
=
syn
::
parse
(
input
)
.unwrap
();
let
k
:
KeyVal
s
=
syn
::
parse
(
input
)
.unwrap
();
for
k
in
k
.k
v
.into_iter
()
{
for
k
in
k
.k
eyvals
.into_iter
()
{
println!
(
"{:?}"
,
k
.as_ref
());
println!
(
"{:?}"
,
k
.as_ref
());
}
}
// {
// {
...
...
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