Struct passerine::compiler::rule::Rule [−][src]
A rule has an Argument Pattern and an AST
.
When a form matches the ArgPat
,
A set of bindings are produced,
which are then spliced into the Rule's AST
To make a new AST
.
This is done in a hygenic manner.
Fields
arg_pat: Spanned<ArgPat>
tree: Spanned<AST>
Implementations
impl Rule
[src]
pub fn new(arg_pat: Spanned<ArgPat>, tree: Spanned<AST>) -> Result<Rule, Syntax>
[src]
Builds a new rule, making sure the rule's signature is valid.
pub fn keywords(arg_pat: &Spanned<ArgPat>) -> Vec<String>
[src]
Returns all keywords, as strings, used by the macro, in order of usage. Does not filter for duplicates.
pub fn merge_safe(
base: &mut HashMap<String, Spanned<AST>>,
new: HashMap<String, Spanned<AST>>,
def: Span
) -> Result<(), Syntax>
[src]
base: &mut HashMap<String, Spanned<AST>>,
new: HashMap<String, Spanned<AST>>,
def: Span
) -> Result<(), Syntax>
Merges two maps of bindings. If there is a collision, i.e. a name bound in both bindings, An error highlighting the duplicate binding is returned.
pub fn bind(
arg_pat: &Spanned<ArgPat>,
reversed_form: &mut Vec<Spanned<AST>>
) -> Option<Result<HashMap<String, Spanned<AST>>, Syntax>>
[src]
arg_pat: &Spanned<ArgPat>,
reversed_form: &mut Vec<Spanned<AST>>
) -> Option<Result<HashMap<String, Spanned<AST>>, Syntax>>
Traverses a form, creating bindings for subsequent transformation.
Returns None
if the form does not match the argument pattern.
Some(Ok(_))
if it matches successfully,
and Some(Err(_))
if it matches but something is incorrect.
You must check that the passed &mut reversed_form
is empty
to gaurantee the match occured in full
Note that this function takes the form unwrapped and in reverse -
This is to make processing the bindings more efficient,
As this function works with the head of the form.
pub fn remove_tag(base: &str) -> String
[src]
Turns a tagged random identifier, like
<base>#XXXXXXXX
back into <base>
.
If the identifier is not tagged, this function just
returns <base>
.
pub fn unique_tag(
base: String,
bindings: &HashMap<String, Spanned<AST>>
) -> String
[src]
base: String,
bindings: &HashMap<String, Spanned<AST>>
) -> String
Turns a base identifier into a random identifier
of the format <base>#XXXXXXXX
,
Gauranteed not to exist in bindings.
pub fn resolve_symbol(
name: String,
span: Span,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Spanned<AST>
[src]
name: String,
span: Span,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Spanned<AST>
Resolves a symbol. If the symbol has been bound, i.e. is defined in the Argument Pattern, We simply splice that in. If not, we hygenically replace it with a unique variable.
pub fn expand_pattern(
pattern: Spanned<ASTPattern>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<ASTPattern>, Syntax>
[src]
pattern: Spanned<ASTPattern>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<ASTPattern>, Syntax>
Expands the bindings in a pattern.
pub fn expand_arg_pat(
arg_pat: Spanned<ArgPat>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<ArgPat>, Syntax>
[src]
arg_pat: Spanned<ArgPat>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<ArgPat>, Syntax>
~Macros inside of macros is a bit too meta for me to think about atm.~ No longer! A macro inside a macro is a macro completely local to that macro. The argument patterns inside a macro can be extended.
pub fn expand(
tree: Spanned<AST>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<AST>, Syntax>
[src]
tree: Spanned<AST>,
bindings: &mut HashMap<String, Spanned<AST>>
) -> Result<Spanned<AST>, Syntax>
Takes a macro's tree and a set of bindings and produces a new hygenic tree.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Rule
[src]
impl !Send for Rule
[src]
impl !Sync for Rule
[src]
impl Unpin for Rule
[src]
impl !UnwindSafe for Rule
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,