Created
October 9, 2012 03:08
-
-
Save brendanzab/3856343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use io::*; | |
fn main() { | |
let (meta, consts, functions) = parse_ext("../core/GL_VERSION_1_1"); | |
io::println(fmt!("%?", meta)); | |
} | |
struct ExtMeta { | |
name: ~str, | |
url: ~str, | |
string: ~str, | |
} | |
struct Type { | |
name: ~str, | |
is_const: bool, | |
is_pointer: bool, | |
} | |
struct Const { | |
name: ~str, | |
value: ~str, | |
} | |
struct Function { | |
name: ~str, | |
return_type: Type, | |
args: ~[(Type, ~str)], | |
} | |
fn parse_ext(filename: &str) -> (ExtMeta, ~[Const], ~[Function]) { | |
let src = io::file_reader(&Path(filename)).get(); | |
let meta = ExtMeta { | |
name: src.read_line(), | |
url: src.read_line(), | |
string: src.read_line(), | |
}; | |
let mut consts: ~[Const] = ~[]; | |
let mut functions: ~[Function] = ~[]; | |
for src.each_line |line| { | |
if is_const(line) { | |
types.push(parse_type(line)); | |
} else if is_function(line) { | |
types.push(parse_function(line)) | |
} else { | |
fail(fmt!("Could not find a match for: %s", line)); | |
} | |
} | |
return (meta, consts, functions); | |
} | |
fn is_const(string: &str) -> bool { ... } | |
fn is_function(string: &str) -> bool { ... } | |
fn parse_const(string: &str) -> Const { ... } | |
fn parse_function(string: &str) -> Function { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment