Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
ink
Commits
145d889f
Unverified
Commit
145d889f
authored
Mar 14, 2019
by
Robin Freyler
Browse files
[lang] Refactor slightly to make the proc macro testable
parent
8d24e158
Changes
2
Hide whitespace changes
Inline
Side-by-side
lang/src/lib.rs
View file @
145d889f
...
...
@@ -22,7 +22,7 @@ use quote::ToTokens;
#[proc_macro]
pub
fn
contract
(
input
:
proc_macro
::
TokenStream
)
->
proc_macro
::
TokenStream
{
match
contract_gen_i
nner
(
input
)
{
match
contract_gen_i
mpl
(
input
)
{
Ok
(
tokens
)
=>
tokens
,
Err
(
err
)
=>
err
.into_token_stream
()
.into
(),
}
...
...
@@ -39,11 +39,24 @@ mod parser;
use
errors
::
Result
;
fn
contract_gen_inner
(
input
:
proc_macro
::
TokenStream
)
->
Result
<
proc_macro
::
TokenStream
>
{
/// Simple wrapper from `proc_macro` to `proc_macro2` and back again.
///
/// # Note
///
/// The actual `proc_macro` interface has to operate on `proc_macro::TokenStream`
/// but to keep this library testable we want to use only `proc_macro2::*` entities
/// internally.
fn
contract_gen_impl
(
input
:
proc_macro
::
TokenStream
)
->
Result
<
proc_macro
::
TokenStream
>
{
contract_gen_impl2
(
input
.into
())
.map
(
Into
::
into
)
}
/// Parses the given token stream as pDSL contract, performs some checks and returns
/// the corresponding contract as token stream.
fn
contract_gen_impl2
(
input
:
proc_macro2
::
TokenStream
)
->
Result
<
proc_macro2
::
TokenStream
>
{
let
ast_contract
=
parser
::
parse_contract
(
input
.clone
())
?
;
let
hir_contract
=
hir
::
Contract
::
from_ast
(
&
ast_contract
)
?
;
// gen::gir::generate(&hir_program)?;
let
tokens
=
gen
::
codegen
(
&
hir_contract
);
Ok
(
tokens
.into
())
// Ok(proc_macro::TokenStream::new())
}
}
lang/src/parser.rs
View file @
145d889f
...
...
@@ -16,7 +16,6 @@
use
crate
::{
ast
,
proc_macro
,
};
use
syn
::{
self
,
...
...
@@ -36,8 +35,8 @@ pub mod keywords {
custom_keyword!
(
external
);
}
pub
fn
parse_contract
(
token_stream
:
proc_macro
::
TokenStream
)
->
Result
<
ast
::
Contract
>
{
syn
::
parse
(
token_stream
)
.map_err
(|
e
|
e
.into
())
pub
fn
parse_contract
(
token_stream
:
proc_macro
2
::
TokenStream
)
->
Result
<
ast
::
Contract
>
{
syn
::
parse
2
(
token_stream
)
.map_err
(|
e
|
e
.into
())
}
impl
Parse
for
ast
::
Contract
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment