Skip to content

Instantly share code, notes, and snippets.

View brendanzab's full-sized avatar
😵‍💫
writing elaborators

Brendan Zabarauskas brendanzab

😵‍💫
writing elaborators
View GitHub Profile
#include <stdlib.h>
#include <stdio.h>
#include <GL/glfw3.h>
int main()
{
GLFWwindow window;
if( !glfwInit() )
{
import glfw3::*;
fn run(init_fn: &fn(), update_fn: &fn(tpf: f64), render_fn: &fn(), cleanup_fn: &fn()) {
init(init_fn, cleanup_fn);
mainloop(update_fn, render_fn, cleanup_fn);
cleanup(cleanup_fn);
}
fn init(init_fn: &fn(), cleanup_fn: &fn()) {
init_fn();
@brendanzab
brendanzab / glcorearb.rs
Created October 2, 2012 04:01
glcorearb
// #ifndef __glcorearb_h_
// #define __glcorearb_h_
// #ifdef __cplusplus
// extern "C" {
// #endif
/*
** Copyright (c) 2007-2012 The Khronos Group Inc.
**
GL_VERSION_2_0
http://www.opengl.org/documentation/specs/version2.0/glspec20.pdf
GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
GL_CURRENT_VERTEX_ATTRIB 0x8626
GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
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,
@brendanzab
brendanzab / macros.md
Created October 12, 2012 06:56
cond! and switch! macros for Rust

Scheme-style cond

macro_rules! cond(
    ($($pred:expr => $body:block),+ _ => $default:block) => (
        $(if $pred $body else)+
        
        $default
    )
)
@brendanzab
brendanzab / baby3.rs
Created October 15, 2012 06:29
Baby's First Parser Combinators
enum ParseNode {
NonTerminal(~[ParseNode]),
Terminal(~str),
}
enum ParseResult {
ParseOk(ParseNode, ~str),
ParseEnd(ParseNode),
NoParse,
}
@brendanzab
brendanzab / baby1.rs
Created October 15, 2012 06:29
Baby's First Parser Combinators
fn match_a(s: &str) -> bool { s == "a" }
fn main() {
io::println(fmt!("match_a(\"a\") -> %?", match_a("a")));
io::println(fmt!("match_a(\"b\") -> %?", match_a("b")));
}
// based off the examples shown in this blog post:
// http://blog.rfw.name/2012/10/12/parser_combinators.html
enum ParseNode {
NonTerminal(&self/[ParseNode]),
Terminal(&self/str),
Empty,
}
enum ParseResult {