M README.md +4 -1
@@ 9,6 9,8 @@ and then interpret these tokens into a s
into `Svg` objects that hold the `Render` trait. The rendering system, located in the file `renderer.rs`, then takes these objects
and outputs the correct svg code.
+- [ ] implement better labelling system
+
Note: main repository is developed using Mercurial, at [https://hg.sr.ht/~lnjng/elements](https://hg.sr.ht/~lnjng/elements).
## Usage
@@ 27,13 29,14 @@ The language is written in simple lisp s
and the interpreter will automatically substitute the value of the variable and render the appropriate object. For example, the
following code will render a triangle with vertices at (0, 0), (0, 3), and (4, 0):
```lisp
+; this is a triangle
(setq A (point 0 0))
(setq B (point 0 3))
(setq C (point 4 0))
(setq T (triangle A B C))
T
```
-Notice how the `setq` function is used to set variables.
+Notice how the `setq` function is used to set variables, and how comments are started with a semicolon.
Functions are also often overloaded to provide more functionality with the same easy syntax. The following are the available
geometric functions:
M src/lexer.rs +27 -0
@@ 1,6 1,7 @@
use crate::lang::functions;
use crate::lang::types::{Operation, Value};
use std::fmt::{Debug, Error, Formatter};
+use std::rc::Weak;
#[derive(Clone, Debug, PartialEq)]
pub enum Token {
@@ 187,14 188,40 @@ pub fn tokenize(s: String) -> Vec<Token>
let separated: Vec<String> = s
.replace("(", " ( ")
.replace(")", " ) ")
+ .replace(";", " ; ")
+ .replace("\n", " \\n ")
.split_whitespace()
.map(String::from)
.collect();
+ println!("{:?}", separated);
+
// match the tokens
let mut tokens: Vec<Token> = Vec::new();
let mut prev_paren = false;
+ let mut is_comment = false;
for word in separated {
+ // catch comments
+ if word == ";" {
+ is_comment = true;
+ continue;
+ }
+
+ // handle comments
+ if is_comment {
+ if word == "(" || word == ")" || word == "\\n" {
+ is_comment = false;
+ } else {
+ continue;
+ }
+ }
+
+ // catch newlines
+ if word == "\\n" {
+ continue;
+ }
+
+ // match and push the appropriate token
let token: Token = match_token(word, prev_paren);
prev_paren = token == Token::LeftParen;
tokens.push(token);