Skip to content

Commit b20c9b7

Browse files
committed
📩 merge: rfc-ast into master
2 parents fd97703 + 7862601 commit b20c9b7

File tree

32 files changed

+834
-704
lines changed

32 files changed

+834
-704
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Typesharp is a typesafe compiled language written in rustlang aiming to memory safe and fast! <br />
1212
You can view the [documentation here](https://github.com/TypeSharp/Documentation).
1313

14-
**NOTICE:** This is a rewrite of the original compiler, and therefore is public. I will not explain how to use, or interact with this source code until I am comfortable releasing the CLI.
14+
**NOTICE:** This is a rewrite of the original compiler, and therefore is public.
1515

1616
## Why Typesharp?
1717

‎src/compiler/ReadMe.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- This file was auto generated by Typesharp. -->
22
# Compiler - The TypeSharp Compiler.
3-
- **[typesharp_ast](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_ast)** - Package that contains abstract syntax tree tokens for typesharp.
4-
- **[typesharp_lexer](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_lexer)** - Lexing utilities, help parse tokens in to AST.
5-
- **[typesharp_parser](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_parser)** - The typesharp parser is responsible for "parsing" or identifying tokens after `tokenization`.
3+
- **[typesharp_ast](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_ast)** - Package that contains abstract syntax tree tokens for typesharp.
4+
- **[typesharp_lexer](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_lexer)** - Lexing utilities, help parse tokens in to AST.
5+
- **[typesharp_parser](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_parser)** - The typesharp parser is responsible for "parsing" or identifying tokens after `tokenization`.

‎src/compiler/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod typesharp_ast;
22
pub mod typesharp_lexer;
3-
pub mod typesharp_parser;
3+
pub mod typesharp_parser;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# typesharp_ast
2-
Package that contains abstract syntax tree tokens for typesharp.
2+
Package that contains abstract syntax tree tokens for typesharp.
Lines changed: 39 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,57 @@
11
// Typesharp ast
22
// use crate::{ typesharp_parser::Module };
3-
use super::position::{ Position };
4-
use super::op::*;
53
use super::types;
6-
use crate::{ compiler::typesharp_lexer::token::Token };
4+
use super::util::position;
5+
use super::node::NodeId;
6+
use crate::{ compiler::typesharp_parser as parser };
7+
use crate::compiler::typesharp_lexer::token::Token;
78

8-
pub struct AST {
9-
name: String,
10-
typ: ProgramType,
11-
body: Vec<ASTStatement>
9+
pub struct Identifier {
10+
pub loc: position::Span,
11+
pub tokens: Option<Vec<Token>>
1212
}
1313

14-
#[derive(Clone, PartialEq, Debug)]
15-
pub struct IContextResource {
16-
pub name: String,
17-
pub contents: Vec<char>
14+
pub enum StatementKind {
15+
Constant(Constant),
16+
Item,
17+
Expression,
18+
Label,
19+
Scope,
20+
TypeDeclaration(types::Type),
21+
Class(Constant)
1822
}
1923

20-
pub trait IContext {
21-
/// Initializes a new context
22-
fn new(&self) -> Self;
23-
24-
// Gets the current resource to be parsed.
25-
fn getCurrentResource(&self) -> Option<IContextResource>;
26-
27-
/// Gets the current AST scope
28-
fn getCurrentScope(&self) -> Option<&ASTStatement>;
29-
30-
/// Gets all AST scopes
31-
fn getScopes(&self) -> Vec<ASTStatement>;
32-
33-
fn nextResource(&self) -> bool;
34-
}
35-
36-
#[derive(Clone, PartialEq, Debug)]
37-
pub struct AnyContext;
38-
39-
impl AnyContext {
40-
fn new(&self) -> AnyContext {
41-
return Self;
42-
}
43-
44-
fn getLine() -> u8 {
45-
0
46-
}
24+
pub enum ExpressionKind {
25+
/// An array of any expression
26+
Array(Vec<Expression>),
27+
/// Private context
28+
Scope,
29+
/// A call to a function or reference to a signature
30+
Function,
31+
/// A method call eg: `foo.bar(a, b)`
32+
///
33+
/// The `Identifier` here represents the Name of the method being called
34+
/// `Vec<Expression>` represents the arguments given to the expression
35+
Method(Identifier, Vec<Expression>, position::Span)
4736
}
4837

49-
pub enum ProgramType {
50-
/// Production
51-
PRO,
52-
/// Library
53-
LIB,
54-
/// External Foreign Function Interface
55-
FFI,
56-
/// Systematic compile, (NOT COMPILED FOR ANY OS, REQUIRES AN OBJMP)
57-
SYS,
58-
/// A driver
59-
INTERNAL
38+
pub struct Constant {
39+
pub id: NodeId,
40+
pub typ: types::Type
6041
}
6142

62-
pub struct Library;
63-
64-
#[derive(Clone, PartialEq, Debug)]
65-
pub struct ASTStatement<Context = IContextResource> {
66-
pub body: ASTStateBody,
67-
pub context: Context,
68-
pub pos: Position
43+
pub struct Statement {
44+
pub id: NodeId,
45+
pub kind: StatementKind,
46+
pub loc: position::Span
6947
}
7048

71-
#[derive(Clone, PartialEq, Debug)]
72-
pub enum ASTStateBody {
73-
// expressions, function calls, returns etc should be here.
74-
FuncCall(Signature),
75-
Expression(Expression),
76-
StackVar(Var),
77-
Constant(HeapVar),
78-
AnyConstant(AnyVar),
79-
If(Conditional)
49+
pub struct Param {
50+
pub id: NodeId,
51+
// pub val: Node
8052
}
8153

82-
// Context and definitions
83-
/// A variable, const, class, etc.
84-
#[derive(Clone, PartialEq, Debug)]
85-
pub struct Var {
86-
pub op: Option<AnyOp>,
87-
pub typ: Option<types::Type>,
88-
pub val: Token,
89-
pub pos: Position,
90-
pub dies: bool,
91-
// pub typ: Type
92-
}
93-
94-
/// Dynamic variable, extends var, which is static.
95-
#[derive(Clone, PartialEq, Debug)]
96-
pub struct HeapVar {
97-
pub var: Var,
98-
pub mangled: bool
99-
}
100-
101-
#[derive(Clone, PartialEq, Debug)]
102-
pub enum AnyVar {
103-
Static(Var),
104-
Heap(HeapVar)
105-
}
106-
107-
/// Functions
108-
#[derive(Clone, PartialEq, Debug)]
109-
pub struct Signature {
110-
pub name: Var,
111-
pub dynamic: bool
112-
}
113-
114-
#[derive(Clone, PartialEq, Debug)]
11554
pub struct Expression {
116-
pub ops: Vec<AnyOp>,
117-
pub v: Vec<AnyVar>
118-
}
119-
120-
#[derive(Clone, PartialEq, Debug)]
121-
pub struct Conditional {
122-
pub condition: Expression,
123-
pub body: Vec<ASTStatement>,
124-
pub fin: Option<Vec<ASTStatement>>
55+
pub id: NodeId,
56+
pub kind: ExpressionKind,
12557
}

‎src/compiler/typesharp_ast/cursor.rs‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎src/compiler/typesharp_ast/keyword.rs‎ renamed to ‎src/compiler/typesharp_ast/keyword/mod.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::compiler::typesharp_lexer::token::TokenValue;
12
use std::{error, fmt};
23

34
/// These keywords are reserved.
@@ -318,6 +319,12 @@ impl KeyWord {
318319
}
319320
}
320321

322+
impl TokenValue<String> for KeyWord {
323+
fn get(&self) -> String {
324+
String::from(self.as_str())
325+
}
326+
}
327+
321328
impl From<&'static str> for KeyWord {
322329
fn from(m: &'static str) -> KeyWord {
323330
return KeyWord::from_str(m);
@@ -345,4 +352,4 @@ impl fmt::Display for KeyWord {
345352
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
346353
return fmt::Display::fmt(self.as_str(), f);
347354
}
348-
}
355+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
pub mod ast;
2-
pub mod position;
32
pub mod keyword;
4-
pub mod cursor;
5-
pub mod op;
63
pub mod types;
4+
pub mod util;
5+
pub mod node;
76

87
pub use self::{
9-
position::{ Position, Span },
10-
keyword::{ KeyWord, KeyWordError },
11-
cursor::{ Cursor }
12-
};
8+
keyword::{KeyWord, KeyWordError},
9+
util::cursor::Cursor,
10+
util::position::{Position, Span},
11+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub struct NodeId {
2+
id: u16
3+
}
4+
5+
pub struct Node {
6+
7+
}

0 commit comments

Comments
 (0)