Skip to content
Permalink
Browse files

Update rust

  • Loading branch information...
aidanhs committed Apr 16, 2015
1 parent ffbfe05 commit e7b1084845ed2df6cbc1751dfa25328ba600a0e8
Showing with 72 additions and 44 deletions.
  1. +27 −11 Cargo.lock
  2. +3 −3 Cargo.toml
  3. +1 −1 mkbind.sh
  4. +7 −7 src/lib.rs
  5. +29 −16 src/main.rs
  6. +5 −6 src/rstcl.rs

Some generated files are not rendered by default. Learn more.

@@ -5,9 +5,9 @@ version = "0.0.1"
authors = ["Aidan Hobson Sayers <aidanhs@cantab.net>"]

[dependencies]
docopt = "0.6.34"
docopt_macros = "0.6.34"
rustc-serialize = "0.2.12"
docopt = "0.6.62"
docopt_macros = "0.6.62"
rustc-serialize = "0.3.12"

[dependencies.rust-bindgen]
git = "https://github.com/crabtw/rust-bindgen.git"
@@ -1,3 +1,3 @@
cd ~/rust/rust-bindgen/target
cd ~/rust/rust-bindgen/target/debug
LD_PRELOAD=/usr/lib/llvm-3.4/lib/libclang.so ./bindgen -ltcl -builtins \
-o $(cd -)/src/tcl.rs $(cd -)/src/mytcl.h
@@ -1,8 +1,8 @@
#![feature(slicing_syntax)]
#![feature(core)]
#![feature(collections)]
#![feature(libc)]
#![feature(std_misc)]
#![feature(slice_patterns)]
#![feature(str_char)]

extern crate libc;

@@ -55,9 +55,9 @@ fn check_literal<'a, 'b>(ctx: &'a str, token: &'b rstcl::TclToken<'a>) -> Vec<Ch
assert!(token_str.len() > 0);
return if token_str.char_at(0) == '{' {
vec![]
} else if token_str.contains_char('$') {
} else if token_str.contains('$') {
vec![Danger(ctx, "Expected literal, found $", token_str)]
} else if token_str.contains_char('[') {
} else if token_str.contains('[') {
vec![Danger(ctx, "Expected literal, found [", token_str)]
} else {
vec![]
@@ -83,7 +83,7 @@ fn is_safe_cmd(token: &rstcl::TclToken) -> bool {
return true;
}
let token_strs: Vec<&str> = parses[0].tokens.iter().map(|e| e.val).collect();
return match &token_strs[] {
return match &token_strs[..] {
["info", "exists", ..] |
["catch", ..] => true,
_ => false,
@@ -160,7 +160,7 @@ pub fn check_command<'a, 'b>(ctx: &'a str, tokens: &'b Vec<rstcl::TclToken<'a>>)
let mut param_types = vec![Code::Block];
if tokens.len() == 3 || tokens.len() == 4 {
let new_params: Vec<Code> = iter::repeat(Code::Literal).take(tokens.len()-2).collect();
param_types.push_all(&new_params[]);
param_types.push_all(&new_params);
}
param_types
}
@@ -183,7 +183,7 @@ pub fn check_command<'a, 'b>(ctx: &'a str, tokens: &'b Vec<rstcl::TclToken<'a>>)
"elseif" => vec![Code::Literal, Code::Expr, Code::Block],
"else" => vec![Code::Literal, Code::Block],
_ => { break; },
}[]);
});
i = param_types.len() + 1;
}
param_types
@@ -1,19 +1,20 @@
#![feature(plugin)]
#![feature(io)]
#![feature(path)]
#![feature(core)]
#![plugin(docopt_macros)]

extern crate "rustc-serialize" as rustc_serialize;
extern crate rustc_serialize;
extern crate docopt;
#[plugin] #[no_link] extern crate docopt_macros;
extern crate tclscan;

use std::old_io;
use std::error::Error;
use std::fs;
use std::io::prelude::*;
use std::io;
use std::path::Path;
use docopt::Docopt;
use tclscan::rstcl;
use tclscan::CheckResult;

docopt!(Args derive Show, "
docopt!(Args derive Debug, "
Usage: tclscan check [--no-warn] ( - | <path> )
tclscan parsestr ( - | <script-str> )
");
@@ -23,21 +24,33 @@ pub fn main() {
let take_stdin = args.cmd__;
let script_in = match (args.cmd_check, args.cmd_parsestr, take_stdin) {
(true, false, false) => {
let path = &args.arg_path[];
let mut file = old_io::File::open(&Path::new(path));
let read_result = file.read_to_string();
if read_result.is_err() {
println!("WARN: Couldn't read {}: {}", path, read_result.unwrap_err());
return;
let path = Path::new(&args.arg_path);
let path_display = path.display();
let mut file = match fs::File::open(&path) {
Err(err) => panic!("ERROR: Couldn't open {}: {}",
path_display, Error::description(&err)),
Ok(file) => file,
};
let mut file_content = String::new();
match file.read_to_string(&mut file_content) {
Err(err) => panic!("ERROR: Couldn't read {}: {}",
path_display, Error::description(&err)),
Ok(_) => file_content,
}
read_result.unwrap()
},
(true, false, true) |
(false, true, true) => old_io::stdin().read_to_string().unwrap(),
(false, true, true) => {
let mut stdin_content = String::new();
match io::stdin().read_to_string(&mut stdin_content) {
Err(err) => panic!("ERROR: Couldn't read stdin: {}",
Error::description(&err)),
Ok(_) => stdin_content,
}
},
(false, true, false) => args.arg_script_str,
_ => panic!("Internal error: could not load script"),
};
let script = &script_in[];
let script = &script_in;
match (args.cmd_check, args.cmd_parsestr) {
(true, false) => {
let mut results = tclscan::scan_script(script);
@@ -1,5 +1,4 @@
use std::mem::uninitialized;
use std::iter::AdditiveIterator;
use std::num::FromPrimitive;
use std::ffi::CString;

@@ -14,7 +13,7 @@ unsafe fn tcl_interp() -> *mut tcl::Tcl_Interp {
return I.unwrap();
}

#[derive(Copy, Debug, FromPrimitive, PartialEq)]
#[derive(Clone, Copy, Debug, FromPrimitive, PartialEq)]
pub enum TokenType {
Word = 1, // TCL_TOKEN_WORD
SimpleWord = 2, // TCL_TOKEN_SIMPLE_WORD
@@ -244,7 +243,7 @@ fn parse<'a>(string: &'a str, is_command: bool, is_expr: bool) -> (TclParse<'a>,
let parse_ptr: *mut tcl::Tcl_Parse = &mut parse;

// https://github.com/rust-lang/rust/issues/16035
let string_cstr = CString::from_slice(string.as_bytes());
let string_cstr = CString::new(string.as_bytes()).unwrap();
let string_ptr = string_cstr.as_ptr();
let string_start = string_ptr as usize;

@@ -291,7 +290,7 @@ fn parse<'a>(string: &'a str, is_command: bool, is_expr: bool) -> (TclParse<'a>,

unsafe fn make_tokens<'a>(string: &'a str, string_start: usize, tcl_parse: &tcl::Tcl_Parse) -> Vec<TclToken<'a>> {
let mut acc = vec![];
for i in range(0, tcl_parse.numTokens as isize).rev() {
for i in (0..tcl_parse.numTokens as isize).rev() {
let tcl_token = *(tcl_parse.tokenPtr).offset(i);
assert!(tcl_token.start as usize > 0);
let offset = tcl_token.start as usize - string_start;
@@ -304,11 +303,11 @@ unsafe fn make_tokens<'a>(string: &'a str, string_start: usize, tcl_parse: &tcl:
}

fn count_tokens(token: &TclToken) -> usize {
token.tokens.iter().map(|t| count_tokens(t)).sum() + 1
token.tokens.iter().map(|t| count_tokens(t)).sum::<usize>() + 1
}

fn make_tcltoken<'a>(tcl_token: &tcl::Tcl_Token, tokenval: &'a str, acc: &mut Vec<TclToken<'a>>) {
let token_type: TokenType = FromPrimitive::from_uint(tcl_token._type as usize).unwrap();
let token_type: TokenType = FromPrimitive::from_usize(tcl_token._type as usize).unwrap();
let num_subtokens = tcl_token.numComponents as usize;

let subtokens = match token_type {

0 comments on commit e7b1084

Please sign in to comment.
You can’t perform that action at this time.