feat: refs map library from rust-onig

上级 168a02f2
......@@ -14,13 +14,9 @@ path = "scie-grammar"
[dependencies.scie_scanner]
path = "scie-scanner"
[dependencies.scie_onig]
path = "scie-onig"
[workspace]
members = [
"scie-grammar",
"scie-scanner",
"benchmark",
"scie-onig"
"benchmark"
]
......@@ -10,9 +10,18 @@ edition = "2018"
onig_sys = "69.5.1"
# regex library
onig = "6"
lazy_static = "1.2"
bitflags = "1.0"
# unicode support for chart splice
unicode-segmentation = "1.6.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_derive = "1.0.115"
[target.'cfg(windows)'.dependencies]
libc = "0.2"
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;
#[cfg(windows)]
extern crate libc;
extern crate onig_sys;
pub mod scanner;
use crate::scie_scanner::ScieScanner;
use crate::scanner::scie_scanner::ScieScanner;
use std::ptr::null_mut;
use onig::{Syntax, EncodedChars};
use std::sync::Mutex;
pub struct ScieOnig {
lazy_static! {
static ref REGEX_NEW_MUTEX: Mutex<()> = Mutex::new(());
}
bitflags! {
pub struct ScieOnigOptions: onig_sys::OnigOptionType {
const REGEX_OPTION_NONE
= onig_sys::ONIG_OPTION_NONE;
}
}
pub struct ScieOnig {}
impl ScieOnig {
pub fn create_onig_scanner(sources: Vec<String>) -> ScieScanner {
pub fn hello(pattern: &str) {
let option = ScieOnigOptions::REGEX_OPTION_NONE;
let syntax = Syntax::default();
// `onig_new`.
let mut reg: onig_sys::OnigRegex = null_mut();
let reg_ptr = &mut reg as *mut onig_sys::OnigRegex;
// We can use this later to get an error message to pass back
// if regex creation fails.
let mut error = onig_sys::OnigErrorInfo {
enc: null_mut(),
par: null_mut(),
par_end: null_mut(),
};
let _err = unsafe {
// Grab a lock to make sure that `onig_new` isn't called by
// more than one thread at a time.
let _guard = REGEX_NEW_MUTEX.lock().unwrap();
onig_sys::onig_new(
reg_ptr,
pattern.start_ptr(),
pattern.limit_ptr(),
option.bits(),
pattern.encoding(),
syntax as *const Syntax as *mut Syntax as *mut onig_sys::OnigSyntaxType,
&mut error,
);
};
}
pub fn create_onig_scanner(_sources: Vec<String>) {}
}
#[cfg(test)]
mod tests {
use crate::scanner::scie_onig::ScieOnig;
#[test]
fn it_works() {
ScieOnig::hello(r"^");
assert!(true)
}
}
......@@ -39,7 +39,7 @@ impl ScieScanner {
return None;
}
let mut searchIndexes = vec![];
let mut search_indexes = vec![];
let mut all_results: Vec<IOnigMatch> = vec![];
for (index, pattern) in self.patterns.iter().enumerate() {
let mut after_pos_str = String::from("");
......@@ -72,7 +72,7 @@ impl ScieScanner {
let zz = regex.search_with_options(&*origin_str.clone(), start_pos as usize, origin_str.clone().len(), SearchOptions::SEARCH_OPTION_NOTBOL, None);
if let Some(pos) = zz {
// println!("pos: {:?}", pos);
searchIndexes.push(pos);
search_indexes.push(pos);
}
if let Some(captures) = _captures {
......@@ -102,8 +102,8 @@ impl ScieScanner {
}
// let mut best_index = 0;
// if searchIndexes.len() > 1 {
// for x in searchIndexes {
// if search_indexes.len() > 1 {
// for x in search_indexes {
// if best_index > x {
// best_index = x;
// }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册