Compare commits
14 Commits
a-star
...
looking-at
| Author | SHA1 | Date | |
|---|---|---|---|
| 83688b5246 | |||
| 152a1670c5 | |||
| 8ceb805a52 | |||
| 32ae95b3d0 | |||
| d00f3b06b2 | |||
| 89d42909df | |||
| 280bc4d1a0 | |||
| b80a87dd18 | |||
| 59a945b474 | |||
| bae64b0851 | |||
| 86ce4821a4 | |||
| efb786ca8a | |||
| 846a082f79 | |||
| d1373fc061 |
@@ -32,4 +32,5 @@ winit = "0.22.0"
|
||||
hprof = "0.1.3"
|
||||
rusttype = { version = "0.7.0", features = ["gpu_cache"] }
|
||||
vulkano_text = "0.12.0"
|
||||
petgraph = "0.5.1"
|
||||
petgraph = "0.5.1"
|
||||
nom = "6.0.0-alpha3"
|
||||
@@ -10,14 +10,16 @@ Creation-Date: 2020-02-03T22:11:42-08:00
|
||||
TODO:
|
||||
[X] Text rendering is mocked.
|
||||
[?] Pathfinder vulkan backend implementation
|
||||
* Kinda big meh on this. It's very much oneshot based
|
||||
and not incredibly compatible with vulkano...
|
||||
[ ] Investigate lyon maybe
|
||||
[X] Currently using local copies of a few libraries:
|
||||
* Kinda big meh on this. It's very much oneshot based
|
||||
and not incredibly compatible with vulkano...
|
||||
[ ] Investigate lyon maybe
|
||||
[ ] Event system
|
||||
[ ] HTML like layout scripts
|
||||
[x] Currently using local copies of a few libraries:
|
||||
[x] shade_runner ( not gonna happen, my fork has diverged too far )
|
||||
[ ] Make a toolpath
|
||||
[X] Read from GPU?
|
||||
[ ] Figure out a way to vectorize the simple edge
|
||||
[X] Read from GPU?
|
||||
[ ] Figure out a way to vectorize the simple edge
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
95
notes/layout-scripts.txt
Normal file
95
notes/layout-scripts.txt
Normal file
@@ -0,0 +1,95 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2020-10-06T22:33:37-07:00
|
||||
|
||||
====== layout-scripts ======
|
||||
Created Tuesday 06 October 2020
|
||||
|
||||
===== Keywords =====
|
||||
|
||||
***table will need some description of it's requested elements***
|
||||
**Actually I think this could just be done in the parser. Emitting warnings if names dont match**
|
||||
|
||||
elem table {
|
||||
}
|
||||
|
||||
**elem is a keyword specifying that the next token will implement some type of rendering behaviour in this case, it is a table.**
|
||||
|
||||
elem table : globalTableFormatting {
|
||||
meta tableFormatting {
|
||||
}
|
||||
}
|
||||
|
||||
meta globalTableFormatting {
|
||||
|
||||
}
|
||||
|
||||
**meta is a keyword specifying that the next token will contain some subset of the data that an elem that needs to render.**
|
||||
|
||||
|
||||
===== Nesting =====
|
||||
|
||||
**There is no way around a tree structure in the markup.**
|
||||
|
||||
elem div {
|
||||
|
||||
}
|
||||
|
||||
elem table {
|
||||
meta tableFormatting {
|
||||
color: Black,
|
||||
}
|
||||
elem tr {
|
||||
elem tc {
|
||||
text: "testText1"
|
||||
}
|
||||
elem tc {
|
||||
text: "testText2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
**But I think I can strongly type the nesting structure, e.g**
|
||||
|
||||
struct Table {
|
||||
fn addChild(child: TableRow)
|
||||
}
|
||||
elem!(table, Table)
|
||||
|
||||
struct TableRow {
|
||||
fn addChild(child: TableColumn)
|
||||
}
|
||||
elem!(table, TableRow)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
resources/edge-detect-screenshot.png
Normal file
BIN
resources/edge-detect-screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
BIN
resources/images/ford.png
Normal file
BIN
resources/images/ford.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
16
resources/scripts/scratch
Normal file
16
resources/scripts/scratch
Normal file
@@ -0,0 +1,16 @@
|
||||
# this is a comment
|
||||
elem table {
|
||||
elem tr {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
elem table {
|
||||
elem tr {
|
||||
|
||||
}
|
||||
elem tr {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BIN
resources/whiteboard-drawing.jpg
Normal file
BIN
resources/whiteboard-drawing.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 407 KiB |
@@ -4,8 +4,6 @@ use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
|
||||
use vulkano::swapchain::Surface;
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::canvas::canvas_frame::CanvasFrame;
|
||||
use crate::canvas::compu_frame::CompuFrame;
|
||||
use crate::PersistentState;
|
||||
use crate::render_system::Position;
|
||||
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
|
||||
@@ -26,7 +24,6 @@ pub struct EventSystem;
|
||||
impl<'a> System<'a> for EventSystem {
|
||||
type SystemData = (
|
||||
Entities<'a>,
|
||||
WriteStorage<'a, Position>,
|
||||
WriteStorage<'a, Evented>,
|
||||
Write<'a, PersistentState>,
|
||||
Write<'a, VkProcessor>,
|
||||
@@ -35,21 +32,19 @@ impl<'a> System<'a> for EventSystem {
|
||||
|
||||
fn run(&mut self, (
|
||||
entity,
|
||||
mut position_list,
|
||||
mut evented_list,
|
||||
mut state,
|
||||
mut vk_processor,
|
||||
event_stack
|
||||
): Self::SystemData) {
|
||||
|
||||
for (position, evented) in (&mut position_list, &evented_list).join() {
|
||||
for (evented) in (&evented_list).join() {
|
||||
for event in &*event_stack {
|
||||
match event {
|
||||
TrEvent::WindowEvent { window_id, event } => {
|
||||
match event {
|
||||
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
|
||||
if *state == ElementState::Pressed {
|
||||
position.x += 100.0;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -10,6 +10,8 @@ extern crate nalgebra as na;
|
||||
extern crate rand;
|
||||
extern crate specs;
|
||||
extern crate time;
|
||||
#[macro_use]
|
||||
extern crate nom;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
@@ -57,6 +59,7 @@ pub mod canvas;
|
||||
pub mod render_system;
|
||||
pub mod compu_system;
|
||||
pub mod event_system;
|
||||
pub mod parser;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PersistentState {
|
||||
@@ -71,7 +74,27 @@ struct TrSprite {
|
||||
entity: Entity,
|
||||
}
|
||||
|
||||
|
||||
use std::fs;
|
||||
use nom::sequence::{preceded, tuple};
|
||||
use nom::bytes::complete::{take_while1, tag, take_while_m_n};
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::error::ErrorKind;
|
||||
use nom::combinator::map_res;
|
||||
use nom::IResult;
|
||||
use crate::parser::parser::{Color, hex_color, parse_script};
|
||||
|
||||
|
||||
pub fn main() {
|
||||
|
||||
//https://dylanede.github.io/cassowary-rs/cassowary/index.html
|
||||
|
||||
let input_string = fs::read_to_string("./resources/scripts/scratch").unwrap();
|
||||
|
||||
parse_script::<(&str, ErrorKind)>(&input_string);
|
||||
|
||||
return;
|
||||
|
||||
//hprof::start_frame();
|
||||
//let g = hprof::enter("vulkan preload");
|
||||
|
||||
@@ -148,7 +171,7 @@ pub fn main() {
|
||||
compu_frame: CompuFrame::new((0, 0)),
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
let mut g = Graph::new();
|
||||
let mut matrix : Vec<Vec<NodeIndex<u32>>> = vec![vec![NodeIndex::new(1); 20]; 20];
|
||||
|
||||
@@ -158,7 +181,7 @@ pub fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for x in 0..20 {
|
||||
for y in 0..20 {
|
||||
|
||||
@@ -176,10 +199,7 @@ pub fn main() {
|
||||
(c, e, 1),
|
||||
(e, f, 1),
|
||||
(d, e, 1),
|
||||
]);
|
||||
|
||||
|
||||
|
||||
]);*/
|
||||
|
||||
// and the thing that renders it
|
||||
world.create_entity()
|
||||
|
||||
1
src/parser/mod.rs
Normal file
1
src/parser/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod parser;
|
||||
270
src/parser/parser.rs
Normal file
270
src/parser/parser.rs
Normal file
@@ -0,0 +1,270 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::{escaped, is_not, take, take_till, take_until, take_while};
|
||||
use nom::bytes::complete::{tag, take_while1, take_while_m_n};
|
||||
use nom::character::complete::{anychar, char, line_ending, multispace1, newline, not_line_ending, one_of};
|
||||
use nom::character::complete::alphanumeric1 as alphanumeric;
|
||||
use nom::character::is_alphabetic;
|
||||
use nom::combinator::{cut, map, map_opt, map_res, opt, value, verify};
|
||||
use nom::error::{FromExternalError, ParseError};
|
||||
use nom::IResult;
|
||||
use nom::multi::{fold_many0, many0};
|
||||
use nom::number::complete::be_u16;
|
||||
use nom::sequence::{delimited, preceded, terminated, tuple};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Color {
|
||||
pub red: u8,
|
||||
pub green: u8,
|
||||
pub blue: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum StringFragment<'a> {
|
||||
Literal(&'a str),
|
||||
EscapedChar(char),
|
||||
EscapedWS,
|
||||
}
|
||||
|
||||
pub enum ScriptMeta {
|
||||
Comment(String),
|
||||
Element(String),
|
||||
Meta(String),
|
||||
}
|
||||
|
||||
// I think this is the space for petgraph...
|
||||
pub enum ElementGraph {
|
||||
|
||||
}
|
||||
|
||||
pub struct ElemBuilder();
|
||||
|
||||
impl ElemBuilder {
|
||||
|
||||
}
|
||||
|
||||
// ENTRY
|
||||
pub fn parse_script<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, ScriptMeta, E> {
|
||||
println!("Full input string : {:?}\n", input);
|
||||
|
||||
let mut remaining_str = input;
|
||||
let mut scope = Vec::new();
|
||||
|
||||
// While there is text left in the string
|
||||
while remaining_str.len() > 0 {
|
||||
println!("Remaining Length : {:?}", remaining_str.len());
|
||||
println!("Remaining String: {:?}", remaining_str);
|
||||
|
||||
// Consume whitespace and test
|
||||
let match_type = delimited(
|
||||
sp,
|
||||
alt((
|
||||
map(comment, |s| ScriptMeta::Comment(String::from(s))),
|
||||
// consume an element by pulling all metadata
|
||||
map(elem::<'a, E>, |s| ScriptMeta::Element(String::from(s))),
|
||||
)),
|
||||
opt(sp),
|
||||
)(remaining_str);
|
||||
|
||||
|
||||
remaining_str = match_type.unwrap().0;
|
||||
}
|
||||
|
||||
return Ok((remaining_str, ScriptMeta::Comment(String::default())));
|
||||
}
|
||||
|
||||
pub fn scope<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str> {
|
||||
let (input, _) = delimited(opt(sp), delimited(char('{'), is_not("}"), char('}')), opt(sp))(input)?;
|
||||
//let (input, _) = delimited(char('{'), is_not("}"), char('}'))(input)?;
|
||||
|
||||
Ok((input, input))
|
||||
}
|
||||
|
||||
pub fn elem<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str> {
|
||||
let (input, _) = delimited(opt(sp), tag("elem"), sp)(input)?;
|
||||
|
||||
let (input, elem_name) = parse_token(input)?;
|
||||
|
||||
let (input, _) = scope::<'a, E>(input)?;
|
||||
|
||||
println!("elem , name : {:?} || scope : {:?}", elem_name, input);
|
||||
|
||||
Ok((input, elem_name))
|
||||
}
|
||||
|
||||
// Parse a single alphanumeric token delimited by spaces
|
||||
fn parse_token<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
|
||||
let chars = "\n";
|
||||
escaped(alphanumeric, '\\', one_of(""))(i)
|
||||
}
|
||||
|
||||
// Parse from a # to a newline character
|
||||
pub fn comment<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
|
||||
let v = preceded(char('#'),
|
||||
cut(terminated(
|
||||
is_not("\n"),
|
||||
newline,
|
||||
)),
|
||||
)(input)?;
|
||||
|
||||
println!("comment : # {:?}", v.1);
|
||||
|
||||
Ok((v.0, v.0))
|
||||
}
|
||||
|
||||
// Eat up whitespace characters
|
||||
fn sp<'a>(i: &'a str) -> IResult<&'a str, &'a str> {
|
||||
let chars = " \t\r\n";
|
||||
take_while(move |c| chars.contains(c))(i)
|
||||
}
|
||||
|
||||
fn parse_unicode<'a, E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>>(input: &'a str)
|
||||
-> IResult<&'a str, char, E> {
|
||||
// `take_while_m_n` parses between `m` and `n` bytes (inclusive) that match
|
||||
// a predicate. `parse_hex` here parses between 1 and 6 hexadecimal numerals.
|
||||
let parse_hex = take_while_m_n(1, 6, |c: char| c.is_ascii_hexdigit());
|
||||
|
||||
// `preceeded` takes a prefix parser, and if it succeeds, returns the result
|
||||
// of the body parser. In this case, it parses u{XXXX}.
|
||||
let parse_delimited_hex = preceded(
|
||||
char('u'),
|
||||
// `delimited` is like `preceded`, but it parses both a prefix and a suffix.
|
||||
// It returns the result of the middle parser. In this case, it parses
|
||||
// {XXXX}, where XXXX is 1 to 6 hex numerals, and returns XXXX
|
||||
delimited(char('{'), parse_hex, char('}')),
|
||||
);
|
||||
|
||||
// `map_res` takes the result of a parser and applies a function that returns
|
||||
// a Result. In this case we take the hex bytes from parse_hex and attempt to
|
||||
// convert them to a u32.
|
||||
let parse_u32 = map_res(parse_delimited_hex, move |hex| u32::from_str_radix(hex, 16));
|
||||
|
||||
// map_opt is like map_res, but it takes an Option instead of a Result. If
|
||||
// the function returns None, map_opt returns an error. In this case, because
|
||||
// not all u32 values are valid unicode code points, we have to fallibly
|
||||
// convert to char with from_u32.
|
||||
map_opt(parse_u32, |value| std::char::from_u32(value))(input)
|
||||
}
|
||||
|
||||
/// Parse an escaped character: \n, \t, \r, \u{00AC}, etc.
|
||||
fn parse_escaped_char<'a, E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>>(input: &'a str)
|
||||
-> IResult<&'a str, char, E> {
|
||||
preceded(
|
||||
char('\\'),
|
||||
// `alt` tries each parser in sequence, returning the result of
|
||||
// the first successful match
|
||||
alt((
|
||||
parse_unicode,
|
||||
// The `value` parser returns a fixed value (the first argument) if its
|
||||
// parser (the second argument) succeeds. In these cases, it looks for
|
||||
// the marker characters (n, r, t, etc) and returns the matching
|
||||
// character (\n, \r, \t, etc).
|
||||
value('\n', char('n')),
|
||||
value('\r', char('r')),
|
||||
value('\t', char('t')),
|
||||
value('\u{08}', char('b')),
|
||||
value('\u{0C}', char('f')),
|
||||
value('\\', char('\\')),
|
||||
value('/', char('/')),
|
||||
value('"', char('"')),
|
||||
)),
|
||||
)(input)
|
||||
}
|
||||
|
||||
/// Parse a backslash, followed by any amount of whitespace. This is used later
|
||||
/// to discard any escaped whitespace.
|
||||
fn parse_escaped_whitespace<'a, E: ParseError<&'a str>>(
|
||||
input: &'a str,
|
||||
) -> IResult<&'a str, &'a str, E> {
|
||||
preceded(char('\\'), multispace1)(input)
|
||||
}
|
||||
|
||||
/// Parse a non-empty block of text that doesn't include \ or "
|
||||
fn parse_literal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
|
||||
// `is_not` parses a string of 0 or more characters that aren't one of the
|
||||
// given characters.
|
||||
let not_quote_slash = is_not("\"\\");
|
||||
|
||||
// `verify` runs a parser, then runs a verification function on the output of
|
||||
// the parser. The verification function accepts out output only if it
|
||||
// returns true. In this case, we want to ensure that the output of is_not
|
||||
// is non-empty.
|
||||
verify(not_quote_slash, |s: &str| !s.is_empty())(input)
|
||||
}
|
||||
|
||||
/// Combine parse_literal, parse_escaped_whitespace, and parse_escaped_char
|
||||
/// into a StringFragment.
|
||||
fn parse_fragment<'a, E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>>(
|
||||
input: &'a str,
|
||||
) -> IResult<&'a str, StringFragment<'a>, E> {
|
||||
alt((
|
||||
// The `map` combinator runs a parser, then applies a function to the output
|
||||
// of that parser.
|
||||
map(parse_literal, StringFragment::Literal),
|
||||
map(parse_escaped_char, StringFragment::EscapedChar),
|
||||
value(StringFragment::EscapedWS, parse_escaped_whitespace),
|
||||
))(input)
|
||||
}
|
||||
|
||||
/// Parse a string. Use a loop of parse_fragment and push all of the fragments
|
||||
/// into an output string.
|
||||
fn parse_string<'a, E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>>(input: &'a str) -> IResult<&'a str, String, E> {
|
||||
// fold_many0 is the equivalent of iterator::fold. It runs a parser in a loop,
|
||||
// and for each output value, calls a folding function on each output value.
|
||||
let build_string = fold_many0(
|
||||
// Our parser function– parses a single string fragment
|
||||
parse_fragment,
|
||||
// Our init value, an empty string
|
||||
String::new(),
|
||||
// Our folding function. For each fragment, append the fragment to the
|
||||
// string.
|
||||
|mut string, fragment| {
|
||||
match fragment {
|
||||
StringFragment::Literal(s) => string.push_str(s),
|
||||
StringFragment::EscapedChar(c) => string.push(c),
|
||||
StringFragment::EscapedWS => {}
|
||||
}
|
||||
string
|
||||
},
|
||||
);
|
||||
|
||||
delimited(char('"'), build_string, char('"'))(input)
|
||||
}
|
||||
|
||||
// Unused stuff
|
||||
pub fn length_value(input: &[u8]) -> IResult<&[u8], &[u8]> {
|
||||
let (input, length) = be_u16(input)?;
|
||||
take(length)(input)
|
||||
}
|
||||
|
||||
pub fn from_hex(input: &str) -> Result<u8, std::num::ParseIntError> {
|
||||
u8::from_str_radix(input, 16)
|
||||
}
|
||||
|
||||
pub fn is_hex_digit(c: char) -> bool {
|
||||
c.is_digit(16)
|
||||
}
|
||||
|
||||
pub fn hex_primary(input: &str) -> IResult<&str, u8> {
|
||||
map_res(
|
||||
take_while_m_n(2, 2, is_hex_digit),
|
||||
from_hex,
|
||||
)(input)
|
||||
}
|
||||
|
||||
pub fn hex_color(input: &str) -> IResult<&str, Color> {
|
||||
let (input, _) = tag("#")(input)?;
|
||||
let (input, (red, green, blue)) = tuple((hex_primary, hex_primary, hex_primary))(input)?;
|
||||
|
||||
Ok((input, Color { red, green, blue }))
|
||||
}
|
||||
|
||||
/*
|
||||
// ( and any amount of bytes ). Returns the bytes between the ()
|
||||
fn parens(input: &str) -> IResult<&str, &str> {
|
||||
delimited(char('('), is_not(")"), char(')'))(input)
|
||||
}
|
||||
|
||||
// `take_while_m_n` parses between `m` and `n` bytes (inclusive) that match
|
||||
// a predicate. `parse_hex` here parses between 1 and 6 hexadecimal numerals.
|
||||
let parse_hex = take_while_m_n(1, 6, |c: char| c.is_ascii_hexdigit());
|
||||
*/
|
||||
Reference in New Issue
Block a user