}
Pieces
-Pieces::collect (const std::string &to_parse, bool append_newline)
+Pieces::collect (const std::string &to_parse, bool append_newline,
+ ffi::ParseMode parse_mode)
{
- auto handle = ffi::collect_pieces (to_parse.c_str (), append_newline);
+ auto handle
+ = ffi::collect_pieces (to_parse.c_str (), append_newline, parse_mode);
// this performs multiple copies, can we avoid them maybe?
// TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we
RustString rust_string;
};
+typedef enum
+{
+ Format,
+ InlineAsm,
+} ParseMode;
+
extern "C" {
FormatArgsHandle
-collect_pieces (const char *input, bool append_newline);
+collect_pieces (const char *input, bool append_newline, ParseMode parse_mode);
FormatArgsHandle
clone_pieces (const FormatArgsHandle &);
struct Pieces
{
- static Pieces collect (const std::string &to_parse, bool append_newline);
+ static Pieces collect (const std::string &to_parse, bool append_newline,
+ ffi::ParseMode parse_mode);
~Pieces ();
Pieces (const Pieces &other);
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "rust-ast-fragment.h"
+#include "rust-fmt.h"
#include "rust-macro-builtins-helpers.h"
#include "rust-expand-format-args.h"
if (append_newline)
fmt_str += '\n';
- auto pieces = Fmt::Pieces::collect (fmt_str, append_newline);
+ auto pieces = Fmt::Pieces::collect (fmt_str, append_newline,
+ Fmt::ffi::ParseMode::Format);
// TODO:
// do the transformation into an AST::FormatArgs node
// invoc.get_delim_tok_tree ().to_token_stream ());
}
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
}
/// The type of format string that we are parsing.
+#[repr(C)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ParseMode {
/// A normal format string as per `format_args!`.
std::env::args().nth(1).unwrap().as_str(),
None,
None,
- false
+ false,
+ generic_format_parser::ParseMode::Format
));
}
style: Option<usize>,
snippet: Option<String>,
append_newline: bool,
+ parse_mode: ParseMode
) -> Vec<Piece<'_>> {
- let parser = Parser::new(input, style, snippet, append_newline, ParseMode::Format);
+ let parser = Parser::new(input, style, snippet, append_newline, parse_mode);
parser.into_iter().collect()
}
#[repr(C)]
pub struct FormatArgsHandle(PieceSlice, RustString);
+
#[no_mangle]
pub extern "C" fn collect_pieces(
input: *const libc::c_char,
append_newline: bool,
+ parse_mode : generic_format_parser::ParseMode
) -> FormatArgsHandle {
// FIXME: Add comment
let str = unsafe { CStr::from_ptr(input) };
let s = unsafe { std::mem::transmute::<&'_ str, &'static str>(s) };
// FIXME: No unwrap
- let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(s, None, None, append_newline)
+ let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(s, None, None, append_newline, parse_mode)
.into_iter()
.map(Into::into)
.collect();