Skip to content

Commit

Permalink
Used existing macro code as a basis for implementing a source argumen…
Browse files Browse the repository at this point in the history
…t for the derive macro. This should allow users to derive their own Source using the provided trait, which was previously missing from derive. (#225)

Co-authored-by: Maciej Hirsz <hello@maciej.codes>
  • Loading branch information
philliard3 and maciejhirsz committed Feb 26, 2023
1 parent ec25e2c commit 883cdfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions logos-codegen/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use self::type_params::{replace_lifetime, traverse_type, TypeParams};
pub struct Parser {
pub errors: Errors,
pub mode: Mode,
pub source: Option<TokenStream>,
pub extras: MaybeVoid,
pub error_type: MaybeVoid,
pub subpatterns: Subpatterns,
Expand Down Expand Up @@ -96,6 +97,16 @@ impl Parser {
};

match (name.to_string().as_str(), value) {
("source", NestedValue::Assign(value)) => {
let span = value.span();
if let Some(previous) = self.source.replace(value) {
self.err("Source can be defined only once", span)
.err("Previous definition here", previous.span());
}
}
("source", _) => {
self.err("Expected: source = SomeType", name.span());
}
("error", NestedValue::Assign(value)) => {
let span = value.span();

Expand Down
2 changes: 1 addition & 1 deletion logos-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use proc_macro::TokenStream;

#[proc_macro_derive(Logos, attributes(logos, extras, error, end, token, regex))]
pub fn logos(input: TokenStream) -> TokenStream {
return logos_codegen::generate(input.into()).into();
logos_codegen::generate(input.into()).into()
}

0 comments on commit 883cdfa

Please sign in to comment.