From be51899f7d5f1f9ede689ca0a9707a0aca3d31c4 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Sep 2019 13:51:12 +0200 Subject: Rewrite the make_parser macro as a proc_macro --- dhall_proc_macros/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 5304429..37c9985 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -6,6 +6,7 @@ extern crate proc_macro; mod derive; +mod parser; use proc_macro::TokenStream; @@ -13,3 +14,11 @@ use proc_macro::TokenStream; pub fn derive_static_type(input: TokenStream) -> TokenStream { derive::derive_static_type(input) } + +#[proc_macro] +pub fn make_parser(input: TokenStream) -> TokenStream { + TokenStream::from(match parser::make_parser(input) { + Ok(tokens) => tokens, + Err(err) => err.to_compile_error(), + }) +} -- cgit v1.2.3 From 1baef509afe52ab285e73469fc597de8f4e166b6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Sep 2019 18:38:39 +0200 Subject: Change parser macros to use a function-like syntax This makes the parser code look much less magical. --- dhall_proc_macros/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 37c9985..46d93e9 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -22,3 +22,11 @@ pub fn make_parser(input: TokenStream) -> TokenStream { Err(err) => err.to_compile_error(), }) } + +#[proc_macro] +pub fn parse_children(input: TokenStream) -> TokenStream { + TokenStream::from(match parser::parse_children(input) { + Ok(tokens) => tokens, + Err(err) => err.to_compile_error(), + }) +} -- cgit v1.2.3 From 3e9aa3e46bd5906469751c908a0daedfe26dac22 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Sep 2019 22:46:03 +0200 Subject: Make make_parser into a proc_macro_attribute That way rustfmt will format the contents of the parser. --- dhall_proc_macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 46d93e9..92cf981 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -15,8 +15,8 @@ pub fn derive_static_type(input: TokenStream) -> TokenStream { derive::derive_static_type(input) } -#[proc_macro] -pub fn make_parser(input: TokenStream) -> TokenStream { +#[proc_macro_attribute] +pub fn make_parser(_attr: TokenStream, input: TokenStream) -> TokenStream { TokenStream::from(match parser::make_parser(input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), -- cgit v1.2.3 From 4bc3380f57e6ce1c7766df0d6b720371b216490d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 2 Sep 2019 17:44:23 +0200 Subject: Get rid of EntryPoint magic --- dhall_proc_macros/src/lib.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 92cf981..3e41254 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(drain_filter)] //! This crate contains the code-generation primitives for the [dhall-rust][dhall-rust] crate. //! This is highly unstable and breaks regularly; use at your own risk. //! -- cgit v1.2.3 From 41f598a75de41665dd9ec0aad56b5ef526698151 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 2 Sep 2019 18:46:53 +0200 Subject: Use proper hygiene for `Parsers` and `Rule` --- dhall_proc_macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 3e41254..63dd29a 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -17,8 +17,8 @@ pub fn derive_static_type(input: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn make_parser(_attr: TokenStream, input: TokenStream) -> TokenStream { - TokenStream::from(match parser::make_parser(input) { +pub fn make_parser(attrs: TokenStream, input: TokenStream) -> TokenStream { + TokenStream::from(match parser::make_parser(attrs, input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), }) -- cgit v1.2.3 From 97d74f514bd8c5c4b96fb4f4071f4a93ac28572d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 2 Sep 2019 18:59:30 +0200 Subject: Separate both parser proc_macros into their own files --- dhall_proc_macros/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'dhall_proc_macros/src/lib.rs') diff --git a/dhall_proc_macros/src/lib.rs b/dhall_proc_macros/src/lib.rs index 63dd29a..37e8f9f 100644 --- a/dhall_proc_macros/src/lib.rs +++ b/dhall_proc_macros/src/lib.rs @@ -7,7 +7,8 @@ extern crate proc_macro; mod derive; -mod parser; +mod make_parser; +mod parse_children; use proc_macro::TokenStream; @@ -18,7 +19,7 @@ pub fn derive_static_type(input: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn make_parser(attrs: TokenStream, input: TokenStream) -> TokenStream { - TokenStream::from(match parser::make_parser(attrs, input) { + TokenStream::from(match make_parser::make_parser(attrs, input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), }) @@ -26,7 +27,7 @@ pub fn make_parser(attrs: TokenStream, input: TokenStream) -> TokenStream { #[proc_macro] pub fn parse_children(input: TokenStream) -> TokenStream { - TokenStream::from(match parser::parse_children(input) { + TokenStream::from(match parse_children::parse_children(input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), }) -- cgit v1.2.3