Skip to content

Commit

Permalink
Move macros into their own crate
Browse files Browse the repository at this point in the history
In preparation for procedural macros.
  • Loading branch information
kmcallister committed Mar 25, 2014
1 parent 3040b49 commit 35d43f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ LIB_TOP_SRC = $(VPATH)/src/html5.rs
LIB_ALL_SRC = $(GEN_LIB_SRC) $(shell find $(VPATH)/src -type f -name '*.rs')
LIB = $(shell $(RUSTC) --crate-file-name "$(LIB_TOP_SRC)")

MACROS_TOP_SRC = $(VPATH)/macros/mod.rs
MACROS_ALL_SRC = $(shell find $(VPATH)/macros -type f -name '*.rs')
MACROS = $(shell $(RUSTC) --crate-file-name "$(MACROS_TOP_SRC)")

EXT_TEST_TOP_SRC = $(VPATH)/test/mod.rs
EXT_TEST_ALL_SRC = $(shell find $(VPATH)/test -type f -name '*.rs')

Expand All @@ -21,7 +25,10 @@ $(VPATH)/generated/char_ref_data.rs: $(VPATH)/codegen/gen-char-ref-data.py
mkdir -p $(dir $@)
$< $(VPATH) > $@

$(LIB): $(LIB_ALL_SRC)
$(MACROS): $(MACROS_ALL_SRC)
$(RUSTC) $(RUSTFLAGS) $(MACROS_TOP_SRC)

$(LIB): $(MACROS) $(LIB_ALL_SRC)
$(RUSTC) $(RUSTFLAGS) $(LIB_TOP_SRC)

tokenize-example: $(VPATH)/examples/tokenize-example.rs $(LIB)
Expand Down
7 changes: 6 additions & 1 deletion src/macros.rs → macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[macro_escape];
#[crate_id="html5-macros"];
#[crate_type="dylib"];

#[feature(macro_rules)];

#[macro_export]
macro_rules! unwrap_or_return( ($opt:expr, $retval:expr) => (
match $opt {
None => return $retval,
Some(x) => x,
}
))

#[macro_export]
macro_rules! test_eq( ($name:ident, $left:expr, $right:expr) => (
#[test]
fn $name() {
Expand Down
5 changes: 3 additions & 2 deletions src/html5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#[phase(syntax)]
extern crate phf_mac;

#[phase(syntax)]
extern crate macros = "html5-macros";

extern crate phf;
extern crate collections;

mod macros;

mod util {
pub mod ascii;
pub mod buffer_queue;
Expand Down

0 comments on commit 35d43f2

Please sign in to comment.