Skip to content

Commit

Permalink
Remove old parser
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Apr 7, 2024
1 parent 56e4691 commit fb35e5d
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 1,594 deletions.
104 changes: 1 addition & 103 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@


use crate::{errors::ErrorCollector, file_position::{BracketSpan, SingleCharSpan, Span}, flattening::FlattenedModule, instantiation::InstantiationList, linker::FileUUID, tokenizer::{get_token_type_name, TokenTypeIdx}, value::Value};
use crate::{errors::ErrorCollector, file_position::Span, flattening::FlattenedModule, instantiation::InstantiationList, linker::FileUUID};
use core::ops::Range;
use std::fmt::Display;

#[derive(Debug,Clone,Copy,PartialEq,Eq)]
pub enum IdentifierType {
Expand Down Expand Up @@ -31,96 +30,6 @@ impl IdentifierType {
}
}

#[derive(Debug)]
pub enum TypeExpression {
Named, // SpanTypeExpression Span gives name
Array(Box<(SpanTypeExpression, SpanExpression)>)
}

pub type SpanTypeExpression = (TypeExpression, Span);

#[derive(Debug)]
pub struct SignalDeclaration {
pub name_span : Span,
pub typ : SpanTypeExpression,
pub identifier_type : IdentifierType,
pub latency_expr : Option<SpanExpression>
}

#[derive(Debug,Clone,Copy)]
pub struct Operator {
pub op_typ : TokenTypeIdx
}

impl Display for Operator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(get_token_type_name(self.op_typ))
}
}

#[derive(Debug)]
pub struct Identifier {
pub span : Span
}

#[derive(Debug)]
pub enum Expression {
Named(Identifier),
Constant(Value),
UnaryOp(Box<(Operator, Span/*Operator token */, SpanExpression)>),
BinOp(Box<(SpanExpression, Operator, Span/*Operator token */, SpanExpression)>),
Array(Box<(SpanExpression, SpanExpression, BracketSpan)>), // first[second]
FuncCall(Vec<SpanExpression>) // first(second, third, ...)
}

impl Expression {
pub fn new_binop(left : SpanExpression, op : Operator, op_pos : Span/*Operator token */, right : SpanExpression) -> SpanExpression {
let span = Span::new_overarching(left.1, right.1);
(Expression::BinOp(Box::new((left, op, op_pos, right))), span)
}
}
pub type SpanExpression = (Expression, Span);
pub type SpanStatement = (Statement, Span);

#[derive(Debug)]
pub enum LeftExpression {
Assignable(Expression),
Declaration(SignalDeclaration)
}

#[derive(Debug)]
pub enum AssignableExpressionModifiers {
LatencyAdding{num_regs : i64, regs_span : Span},
Initial{initial_token : Span},
NoModifiers
}

#[derive(Debug)]
pub struct AssignableExpressionWithModifiers {
pub expr : LeftExpression,
pub span : Span,
pub modifiers : AssignableExpressionModifiers
}

#[derive(Debug)]
pub struct RangeExpression {
pub from : SpanExpression,
pub to : SpanExpression
}

#[derive(Debug)]
pub enum Statement {
Assign{to : Vec<AssignableExpressionWithModifiers>, eq_sign_position : Option<SingleCharSpan>, expr : Option<SpanExpression>}, // num_regs v = expr;
If{condition : SpanExpression, then : CodeBlock, els : Option<CodeBlock>},
For{var : SignalDeclaration, range : RangeExpression, code : CodeBlock},
Block(CodeBlock)
}

#[derive(Debug)]
pub struct CodeBlock {
pub statements : Vec<SpanStatement>
}

#[derive(Debug)]
pub struct LinkInfo {
pub file : FileUUID,
Expand All @@ -135,14 +44,6 @@ impl LinkInfo {
}
}


#[derive(Debug)]
pub struct ParsedInterface {
pub ports : Vec<SignalDeclaration>,
pub outputs_start : usize
}


#[derive(Debug, Clone)]
pub struct InterfacePorts<ID : Clone + Copy> {
pub outputs_start : usize,
Expand Down Expand Up @@ -183,9 +84,6 @@ impl<ID : Clone + Copy> InterfacePorts<ID> {
pub struct Module {
pub link_info : LinkInfo,

pub interface : ParsedInterface,
pub code : CodeBlock,

pub flattened : FlattenedModule,

pub instantiations : InstantiationList
Expand Down
11 changes: 4 additions & 7 deletions src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ fn convert_to_semantic_tokens(file_data : &FileData, ide_tokens : &mut[(IDEIdent
ide_tokens.sort_by(|a, b| a.1.cmp(&b.1));

let mut cursor = Position {line : 0, character : 0};
let mut semantic_tokens = Vec::with_capacity(file_data.tokens.len());

for (ide_kind, span) in ide_tokens.iter() {
ide_tokens.into_iter().map(|(ide_kind, span)| {
let typ = get_semantic_token_type_from_ide_token(*ide_kind);
let mod_bits = get_modifiers_for_token(*ide_kind);

Expand All @@ -185,16 +184,14 @@ fn convert_to_semantic_tokens(file_data : &FileData, ide_tokens : &mut[(IDEIdent
let delta_col = start_pos.character - cursor.character;
cursor = start_pos;

semantic_tokens.push(SemanticToken{
SemanticToken{
delta_line: delta_line,
delta_start: delta_col,
length: end_pos.character - start_pos.character,
token_type: typ,
token_modifiers_bitset: mod_bits,
});
}

semantic_tokens
}
}).collect()
}

fn do_syntax_highlight(file_data : &FileData, linker : &Linker) -> Vec<SemanticToken> {
Expand Down
2 changes: 0 additions & 2 deletions src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ pub fn compile_all(file_paths : Vec<PathBuf>) -> (Linker, ArenaVector<(PathBuf,
};

let full_parse = perform_full_semantic_parse(file_text, uuid);

println!("{:?}", full_parse.ast);

paths_arena.insert(uuid, (file_path, Source::from(full_parse.file_text.file_text.clone())));
linker.add_reserved_file(uuid, full_parse);
Expand Down
19 changes: 0 additions & 19 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::cell::{RefCell, Cell};

use crate::{linker::FileUUID, file_position::Span};

use crate::tokenizer::{TokenTypeIdx, get_token_type_name};

#[derive(Debug,Clone,PartialEq,Eq)]
pub enum ErrorLevel {
Error,
Expand All @@ -31,23 +29,6 @@ pub fn error_info<S : Into<String>>(position : Span, file : FileUUID, reason : S
ErrorInfo{position, file, info : reason.into()}
}

pub fn join_expected_list(expected : &[TokenTypeIdx]) -> String {
use std::fmt::Write;

assert!(!expected.is_empty());
let mut result = String::new();
for exp in expected.get(..expected.len() - 1).unwrap() {
let tok_typ_name = get_token_type_name(*exp);
writeln!(&mut result, "'{tok_typ_name}',").unwrap();
}
if expected.len() >= 2 {
result += " or ";
}
let tok_typ_name = get_token_type_name(expected[expected.len() - 1]);
writeln!(&mut result, "'{tok_typ_name}'").unwrap();
result
}

// Class that collects and manages errors and warnings
// Implemented such that it can be shared immutably. This makes many operations to do with parsing easier
// It doesn't allow indexing, so no immutable references to contents can exist
Expand Down
Loading

0 comments on commit fb35e5d

Please sign in to comment.