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
50d4e2c1
Commit
50d4e2c1
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
checking
parent
73597032
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+136
-55
136 additions, 55 deletions
src/lib.rs
with
136 additions
and
55 deletions
src/lib.rs
+
136
−
55
View file @
50d4e2c1
...
...
@@ -69,8 +69,33 @@ key!{KeyEnabled, "enabled"}
#[proc_macro]
pub
fn
app
(
input
:
proc_macro
::
TokenStream
)
->
proc_macro
::
TokenStream
{
let
app
=
parse_app
(
input
);
//let app = check_app(app);
// let v = kv.value.as_ref().right().unwrap();
// let tokens = quote!(#v);
// panic!("{}", v)
quote!
()
.into
()
}
struct
App
{
device
:
Option
<
Path
>
,
resources
:
Vec
<
ResFields
>
,
init
:
Option
<
Path
>
,
idle
:
Vec
<
IdleFields
>
,
tasks
:
Vec
<
(
Ident
,
Vec
<
EnumTask
>
)
>
,
}
fn
parse_app
(
input
:
proc_macro
::
TokenStream
)
->
Option
<
App
>
{
let
app
:
Punct
<
AppFields
,
Token!
[,]
>
=
syn
::
parse
(
input
)
.unwrap
();
let
mut
device
:
Option
<
Path
>
=
None
;
let
mut
resources
:
Vec
<
ResFields
>
=
Vec
::
new
();
let
mut
init
:
Option
<
Path
>
=
None
;
let
mut
idle
:
Vec
<
IdleFields
>
=
Vec
::
new
();
let
mut
tasks
:
Vec
<
(
Ident
,
Vec
<
EnumTask
>
)
>
=
Vec
::
new
();
let
mut
ok
=
true
;
for
AppFields
{
key
,
value
}
in
app
.data
.into_iter
()
{
//println!("k {:?} v {:?}", key, value)
match
key
.as_ref
()
{
...
...
@@ -80,6 +105,12 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Some
(
path
)
=>
{
println!
(
"path"
);
println!
(
"path {:?}"
,
path
);
if
device
==
None
{
device
=
Some
(
path
.clone
());
}
else
{
println!
(
"Field `device` multiple defined."
);
ok
=
false
;
}
}
_
=>
{
println!
(
"device should be a path"
);
...
...
@@ -89,6 +120,7 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
}
"resources"
=>
{
println!
(
"resources"
);
if
resources
.is_empty
()
{
match
value
.right
()
{
Some
(
ts
)
=>
{
println!
(
"ts"
);
...
...
@@ -99,9 +131,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!
(
"internal error"
);
}
}
}
else
{
println!
(
"Field `resource` multiple defined."
);
ok
=
false
;
}
}
"init"
=>
{
println!
(
"init"
);
if
init
==
None
{
match
value
.right
()
{
Some
(
ts
)
=>
{
println!
(
"ts"
);
...
...
@@ -112,9 +149,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!
(
"internal error"
);
}
}
}
else
{
println!
(
"Field `init` multiple defined."
);
ok
=
false
;
}
}
"idle"
=>
{
println!
(
"idle"
);
if
idle
.is_empty
()
{
match
value
.right
()
{
Some
(
ts
)
=>
{
println!
(
"ts"
);
...
...
@@ -132,9 +174,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!
(
"internal error"
);
}
}
}
else
{
println!
(
"Field `idle` multiple defined."
);
ok
=
false
;
}
}
"tasks"
=>
{
println!
(
"tasks"
);
if
tasks
.is_empty
()
{
match
value
.right
()
{
Some
(
ts
)
=>
{
println!
(
"ts"
);
...
...
@@ -144,7 +191,10 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
for
Tasks
{
id
,
task
}
in
tasks
.data
.into_iter
()
{
println!
(
"task {}"
,
id
.as_ref
());
let
task
:
Punct
<
EnumTask
,
Token!
[,]
>
=
syn
::
parse2
(
task
)
.unwrap
();
let
task
:
Punct
<
EnumTask
,
Token!
[,],
>
=
syn
::
parse2
(
task
)
.unwrap
();
for
tf
in
task
.data
{
match
tf
{
EnumTask
::
TaskPrio
(
prio
)
=>
println!
(
"prio"
),
...
...
@@ -160,16 +210,30 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!
(
"internal error"
);
}
}
}
else
{
println!
(
"Field `tasks` multiple defined."
);
ok
=
false
;
}
}
_
=>
{
println!
(
"Illegal field"
);
ok
=
false
;
}
_
=>
(),
// unimplemented!(),
}
// println!("k {:?} ", key);
}
// let v = kv.value.as_ref().right().unwrap();
// let tokens = quote!(#v);
// panic!("{}", v)
quote!
()
.into
()
if
ok
{
Some
(
App
{
device
,
resources
,
init
,
idle
,
tasks
,
})
}
else
{
None
}
}
// Vec[T] (or perhaps not quite)
...
...
@@ -352,3 +416,20 @@ impl Synom for Tasks {
(
Tasks
{
id
,
task
:
task
.1
})
));
}
fn
check_app
(
app
:
App
)
->
Option
<
App
>
{
let
mut
ok
=
true
;
// check device
if
app
.device
==
None
{
println!
(
"Device field missing"
);
ok
=
false
;
}
// check idle
if
ok
{
Some
(
app
)
}
else
{
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