wip
This commit is contained in:
+42
-7
@@ -2,19 +2,54 @@
|
|||||||
|
|
||||||
* Syntax example:
|
* Syntax example:
|
||||||
#+begin_src
|
#+begin_src
|
||||||
funzione :: fn(parametro1: Number, parametro2: String): String do
|
#this is what a struct delcaration shoul lool like
|
||||||
|
Point :: struct{
|
||||||
|
x: Numeric, # btw Numeric in my imagination is a Interface/Trai/Contrato comune to all numberic type
|
||||||
|
y: Numeric,
|
||||||
|
}
|
||||||
|
|
||||||
end
|
Point.new :: fn(x:Numeric, y:Numeric) Self:
|
||||||
|
return Point{x,y}
|
||||||
|
|
||||||
|
|
||||||
|
Point.sum :: fn(self, other: Point) Self:
|
||||||
|
return Point{x: self.x+other.x, y: self.y+self.y}
|
||||||
|
|
||||||
|
|
||||||
|
@(entrypoint)
|
||||||
|
main :: fn(parametro1: Numeric, parametro2: String) Void :
|
||||||
|
a := Point.new(67, 420)
|
||||||
|
b := Point.new(42, 47)
|
||||||
|
a = a.sum(b)
|
||||||
|
|
||||||
|
print("par: {},{}", touple(parametro1, parametro2))
|
||||||
|
if parametro1 == 0:
|
||||||
|
print("What do you epexted to happen?")
|
||||||
|
else if parametro1 > 0:
|
||||||
|
for i in range(0,parametro1,1):
|
||||||
|
print("{}", parametro2)
|
||||||
|
else:
|
||||||
|
for i in range(0,parametro1,-1):
|
||||||
|
print("{}", parametro2)
|
||||||
|
range_gen := precook(range, args: [0,parametro1]);
|
||||||
|
match parametro1 is:
|
||||||
|
== 0 => print("{}", parametro2),
|
||||||
|
> 0 => forEach(range_gen(1), |x| print("{}", parametro2)),
|
||||||
|
< 0 => forEach(range_gen(-1), |x| print("{}", parametro2)),
|
||||||
|
_ => panic()
|
||||||
|
match a is:
|
||||||
|
Point(x > 100, y) => print("YEAAA :)"),
|
||||||
|
_ => print("NAIH :(")
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Planning:
|
* Planning:
|
||||||
allora quello che devo fare è:
|
allora quello che devo fare è:
|
||||||
** TODO Controllare se ho finito la questione del retourn:labe
|
** TODO Controllare se ho finito la questione del return:label
|
||||||
** TODO Complete the use os source slice inside parser (many node hase syntetic source slice or badly wrpapped)
|
** TODO Complete the use os source slice inside parser (many node has synthetic source slice or badly wrapped)
|
||||||
** TODO implement struct:
|
** TODO implement struct:
|
||||||
#+begin_src rlox
|
#+begin_src rlox
|
||||||
Cosa :: struct{
|
Cosa :: struct{
|
||||||
field1: Number
|
field1: Numeric
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
*** TODO update lexer
|
*** TODO update lexer
|
||||||
@@ -23,7 +58,7 @@ Cosa :: struct{
|
|||||||
** TODO implement partial function ...
|
** TODO implement partial function ...
|
||||||
#+begin_src rlox
|
#+begin_src rlox
|
||||||
cosa := Cosa{feld1: 42}
|
cosa := Cosa{feld1: 42}
|
||||||
function :: fn(self:Cosa, b: Number) -> Number
|
function :: fn(self:Cosa, b: Numeric) -> Numeric
|
||||||
res := function(cosa,44)
|
res := function(cosa,44)
|
||||||
#+end_src
|
#+end_src
|
||||||
*** TODO ... to undirectly create method
|
*** TODO ... to undirectly create method
|
||||||
@@ -37,7 +72,7 @@ res := cosa |> function(44);
|
|||||||
** TODO Understand what is a type system
|
** TODO Understand what is a type system
|
||||||
** TODO implement struct method:
|
** TODO implement struct method:
|
||||||
#+begin_src rlox
|
#+begin_src rlox
|
||||||
Cosa.new :: fn(field1: Number):Self #+begin_src do
|
Cosa.new :: fn(field1: Numeric):Self #+begin_src do
|
||||||
return Self{ field1 };
|
return Self{ field1 };
|
||||||
end;
|
end;
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ use crate::{common::base_value::BaseValue, frontend::source_registry::SourceSlic
|
|||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum TokenType {
|
pub enum TokenType {
|
||||||
// Single character tokens
|
// Single character tokens
|
||||||
|
Space,
|
||||||
|
Tab,
|
||||||
|
NewLine,
|
||||||
LeftParen,
|
LeftParen,
|
||||||
RightParen,
|
RightParen,
|
||||||
LeftBrace,
|
LeftBrace,
|
||||||
@@ -70,6 +73,9 @@ pub enum TokenType {
|
|||||||
impl fmt::Display for TokenType {
|
impl fmt::Display for TokenType {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
TokenType::Space => write!(f, "/s"),
|
||||||
|
TokenType::Tab => write!(f, "/t"),
|
||||||
|
TokenType::NewLine => write!(f, "/n"),
|
||||||
TokenType::Bang => write!(f, "!"),
|
TokenType::Bang => write!(f, "!"),
|
||||||
TokenType::BangEqual => write!(f, "!="),
|
TokenType::BangEqual => write!(f, "!="),
|
||||||
TokenType::Equal => write!(f, "="),
|
TokenType::Equal => write!(f, "="),
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ impl Token {
|
|||||||
|
|
||||||
fn token_type_symbol(&self) -> &'static str {
|
fn token_type_symbol(&self) -> &'static str {
|
||||||
match self.token_type {
|
match self.token_type {
|
||||||
|
TokenType::Space => "SPC",
|
||||||
|
TokenType::Tab => "TAB",
|
||||||
|
TokenType::NewLine => "NEL",
|
||||||
TokenType::LeftParen => "(",
|
TokenType::LeftParen => "(",
|
||||||
TokenType::RightParen => ")",
|
TokenType::RightParen => ")",
|
||||||
TokenType::LeftBrace => "{",
|
TokenType::LeftBrace => "{",
|
||||||
@@ -256,7 +259,9 @@ impl Token {
|
|||||||
| TokenType::Dot
|
| TokenType::Dot
|
||||||
| TokenType::Semicolon => ("\x1b[37m", self.token_type_symbol()),
|
| TokenType::Semicolon => ("\x1b[37m", self.token_type_symbol()),
|
||||||
TokenType::StartBlock | TokenType::EndBlock => ("\x1b[35m", self.token_type_symbol()),
|
TokenType::StartBlock | TokenType::EndBlock => ("\x1b[35m", self.token_type_symbol()),
|
||||||
TokenType::Eof => ("\x1b[33m", self.token_type_symbol()),
|
TokenType::Eof | TokenType::Space | TokenType::Tab | TokenType::NewLine => {
|
||||||
|
("\x1b[33m", self.token_type_symbol())
|
||||||
|
}
|
||||||
TokenType::In => ("\x1b[36m", self.token_type_symbol()),
|
TokenType::In => ("\x1b[36m", self.token_type_symbol()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user