<commit_before>extern crate polydraw;

use polydraw::node::{Data, NodeBuilder};
use polydraw::lang::{parse, compile, tokenize};


pub const SOURCE: &'static str = "

double = frame * 2

result = <80 60> + double

";


fn main() {
   match tokenize(SOURCE) {
      Ok(tokens) => {
         match parse(tokens) {
            Ok(ast_list) => {
               let mut builder = NodeBuilder::new();

               let frame_index = builder.input(String::from("frame"));

               compile(&mut builder, ast_list);

               let mut program = builder.compile();

               program.input(frame_index, Data::Int(100));

               let result = program.execute();

               println!("{:?}", result);
            },
            Err(err) => println!("{}", err),
         }
      },
      Err(err) => println!("{}", err)
   }
}

<commit_msg>The lang example executing from a source file<commit_after>extern crate polydraw;

use std::env;
use std::io::prelude::*;
use std::fs::File;

use polydraw::node::{Data, NodeBuilder};
use polydraw::lang::{parse, compile, tokenize};


fn main() {
   let filename = match env::args().nth(1) {
      Some(filename) => filename,
      None => {
         println!("No source file specified");
         return;
      }
   };

   let mut f = match File::open(&filename) {
      Ok(f) => f,
      Err(_) => {
         println!("Cannot open {}", &filename);
         return;
      }
   };

   let mut source = String::new();

   f.read_to_string(&mut source).unwrap();

   match tokenize(&source) {
      Ok(tokens) => {
         match parse(tokens) {
            Ok(ast_list) => {
               let mut builder = NodeBuilder::new();

               let frame_index = builder.input(String::from("frame"));

               compile(&mut builder, ast_list);

               let mut program = builder.compile();

               program.input(frame_index, Data::Bool(false));

               let result = program.execute();

               println!(">> {:?}", result);
            },
            Err(err) => println!("{}", err),
         }
      },
      Err(err) => println!("{}", err)
   }
}


{'fraction_non_alphanumeric': 0.1647168928404305, 'fraction_numerical': 0.004211511464670099, 'mean_word_length': 2.0412517780938835, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5777019', 'n_tokens_mistral': 648, 'n_tokens_neox': 621, 'n_words': 145}