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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
parsetest
Commits
8f1449a6
Commit
8f1449a6
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
27db8763
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
+29
-3
29 additions, 3 deletions
examples/app.rs
src/lib.rs
+72
-30
72 additions, 30 deletions
src/lib.rs
with
101 additions
and
33 deletions
examples/app.rs
+
29
−
3
View file @
8f1449a6
...
...
@@ -4,11 +4,37 @@ extern crate parsetest;
use
parsetest
::
app
;
app!
{
id1
,
id2
,
id2
,
device
:
ab
::
cc
}
fn
main
()
{
println!
(
"here"
);
}
// impl Synom for UnitType {
// named!(parse -> Self, do_parse!(
// which: syn!(StructOrEnum) >>
// name: syn!(Ident) >>
// item: switch!(value!(which),
// StructOrEnum::Struct(struct_token) => map!(
// punct!(;),
// |semi_token| UnitType::Struct {
// struct_token,
// name,
// semi_token,
// }
// )
// |
// StructOrEnum::Enum(enum_token) => map!(
// braces!(syn!(Ident)),
// |(brace_token, variant)| UnitType::Enum {
// enum_token,
// name,
// brace_token,
// variant,
// }
// )
// ) >>
// (item)
// ));
// }
This diff is collapsed.
Click to expand it.
src/lib.rs
+
72
−
30
View file @
8f1449a6
...
...
@@ -55,8 +55,9 @@ pub fn lite(input: TokenStream) -> TokenStream {
}
}
}
use
syn
::
Path
;
enum
AppKeys
{
enum
AppKey
Word
s
{
Device
,
Resources
,
Interrupts
,
...
...
@@ -65,40 +66,74 @@ enum AppKeys {
Init
,
}
fn
to_app_keys
(
id
:
Ident
)
->
Option
<
AppKeys
>
{
match
id
.as_ref
()
{
"device"
=>
Some
(
AppKeys
::
Device
),
_
=>
None
,
impl
Synom
for
AppKeyWords
{
named!
(
parse
->
Self
,
do_parse!
(
key
:
call!
(
Ident
::
parse
)
>>
(
match
key
.as_ref
()
{
"device"
=>
AppKeyWords
::
Device
,
"resources"
=>
AppKeyWords
::
Resources
,
_
=>
panic!
(
"-- AppKeys"
)
}
)
));
}
// struct KeyVal {
enum
AppKeys
{
Device
(
Path
),
Resources
(
LitInt
),
Interrupts
,
Tasks
,
Idle
,
Init
,
}
// }
impl
Synom
for
AppKeys
{
named!
(
parse
->
Self
,
do_parse!
(
which
:
syn!
(
AppKeyWords
)
>>
name
:
punct!
(:)
>>
item
:
switch!
(
value!
(
which
),
AppKeyWords
::
Device
=>
map!
(
syn!
(
Path
),
|
path
|
AppKeys
::
Device
(
path
))
// |
// AppKeyWords::Resource => AppKeys::Tasks
|
_
=>
map!
(
syn!
(
Path
),
|
path
|
AppKeys
::
Device
(
path
))
)
>>
(
item
)
));
}
// impl Synom for KeyVal {
// named!(parse -> Self, do_parse!(
// val: syn!(Punctuadet) >> (KeyVal { })
#[proc_macro]
pub
fn
app
(
input
:
TokenStream
)
->
TokenStream
{
println!
(
"-- app --"
);
let
k
:
AppKeys
=
syn
::
parse
(
input
)
.unwrap
();
// field: syn!(Ident) >>
// _colon: punct!(:) >>
// + switch!(value!(field.as_ref()),
// "path" => map!(syn!(Path), |path| {
// + parsed_init.path = Some(path);
// + }) |
// + "resources" => map!(parse_resource_ident, |res| {
// + parsed_init.resources = Some(res);
// + }) |
// + _ => call!(|_| {
// + field.span.unstable().error(format!("Unknown field `{}`", field)).emit();
// + panic!("Unknown field `{}`", field);
// + })
// + ) >>
// + _comma: syn!(Token![,]) >>
// + (())
// ));
match
k
{
AppKeys
::
Device
(
dev
)
=>
println!
(
"device {}"
,
dev
.into_tokens
()),
AppKeys
::
Resources
(
res
)
=>
println!
(
"resources {}"
,
res
.into_tokens
()),
_
=>
println!
(
"not matched"
),
}
// for k in k.keyvals.into_iter() {
// println!("{:?}", k.key.as_ref());
// println!("{:?}", k.val);
// }
// {
// Ok(app) => {
// let tokens = quote!();
// tokens.into()
// }
// Err(err) => {
// let desc = err.description();
// let tokens = quote! {
// compile_error!(#desc)
// };
// tokens.into()
// }
// }
let
tokens
=
quote!
();
tokens
.into
()
}
use
syn
::
punctuated
::
Punctuated
;
struct
KeyVal
{
...
...
@@ -125,7 +160,7 @@ impl Synom for KeyVals {
}
#[proc_macro]
pub
fn
app
(
input
:
TokenStream
)
->
TokenStream
{
pub
fn
app
a
(
input
:
TokenStream
)
->
TokenStream
{
println!
(
"-- app --"
);
let
k
:
KeyVals
=
syn
::
parse
(
input
)
.unwrap
();
for
k
in
k
.keyvals
.into_iter
()
{
...
...
@@ -149,6 +184,13 @@ pub fn app(input: TokenStream) -> TokenStream {
tokens
.into
()
}
// fn to_app_keys(id: Ident) -> Option<AppKeys> {
// match id.as_ref() {
// "device" => Some(AppKeys::Device),
// _ => None,
// }
// }
// https://github.com/japaric/rtfm-syntax/pull/3
// named!(parse -> LitInt, do_parse!(
// val: syn!(LitInt) >> (val)
// ));
...
...
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