Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dalance/veryl
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Aug 4, 2023
2 parents 3d13ce4 + 9f713a4 commit 0cb7451
Show file tree
Hide file tree
Showing 14 changed files with 2,456 additions and 2,455 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
exclude = [
# "crates/wasm",
]
resolver = "2"

[workspace.package]
authors = ["[email protected]"]
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/handlers/create_symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct CreateSymbolTable<'a> {
default_block: Option<StrId>,
for_identifier: Option<VerylToken>,
anonymous_namespace: usize,
attribute_lines: HashSet<usize>,
attribute_lines: HashSet<u32>,
}

impl<'a> CreateSymbolTable<'a> {
Expand Down
22 changes: 11 additions & 11 deletions crates/emitter/src/aligner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use veryl_parser::Stringifier;

#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub struct Location {
pub line: usize,
pub column: usize,
pub length: usize,
pub line: u32,
pub column: u32,
pub length: u32,
pub duplicated: Option<usize>,
}

Expand Down Expand Up @@ -39,11 +39,11 @@ impl From<Token> for Location {
pub struct Align {
enable: bool,
index: usize,
max_width: usize,
width: usize,
line: usize,
rest: Vec<(Location, usize)>,
additions: HashMap<Location, usize>,
max_width: u32,
width: u32,
line: u32,
rest: Vec<(Location, u32)>,
additions: HashMap<Location, u32>,
last_location: Option<Location>,
}

Expand All @@ -62,7 +62,7 @@ impl Align {
if loc.line - self.line > 1 {
self.finish_group();
}
self.max_width = usize::max(self.max_width, self.width);
self.max_width = u32::max(self.max_width, self.width);
self.line = loc.line;
self.rest.push((loc, self.width));

Expand Down Expand Up @@ -102,7 +102,7 @@ impl Align {

fn space(&mut self, x: usize) {
if self.enable {
self.width += x;
self.width += x as u32;
}
}
}
Expand All @@ -120,7 +120,7 @@ mod align_kind {

#[derive(Default)]
pub struct Aligner {
pub additions: HashMap<Location, usize>,
pub additions: HashMap<Location, u32>,
aligns: [Align; 8],
in_type_expression: bool,
build_opt: Build,
Expand Down
8 changes: 4 additions & 4 deletions crates/emitter/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct Emitter {
format_opt: Format,
string: String,
indent: usize,
line: usize,
line: u32,
aligner: Aligner,
last_newline: usize,
last_newline: u32,
in_start_token: bool,
consumed_next_newline: bool,
single_line: bool,
Expand Down Expand Up @@ -175,7 +175,7 @@ impl Emitter {
} else {
&text
};
self.last_newline = text.matches('\n').count();
self.last_newline = text.matches('\n').count() as u32;
self.str(text);
self.line = x.line;
}
Expand All @@ -186,7 +186,7 @@ impl Emitter {
let mut loc: Location = x.token.into();
loc.duplicated = duplicated;
if let Some(width) = self.aligner.additions.get(&loc) {
self.space(*width);
self.space(*width as usize);
}

if duplicated.is_some() {
Expand Down
28 changes: 14 additions & 14 deletions crates/formatter/src/aligner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use veryl_parser::veryl_walker::VerylWalker;

#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub struct Location {
pub line: usize,
pub column: usize,
pub length: usize,
pub line: u32,
pub column: u32,
pub length: u32,
}

impl From<&Token> for Location {
Expand All @@ -34,11 +34,11 @@ impl From<Token> for Location {
pub struct Align {
enable: bool,
index: usize,
max_width: usize,
width: usize,
line: usize,
rest: Vec<(Location, usize)>,
additions: HashMap<Location, usize>,
max_width: u32,
width: u32,
line: u32,
rest: Vec<(Location, u32)>,
additions: HashMap<Location, u32>,
last_location: Option<Location>,
}

Expand All @@ -57,7 +57,7 @@ impl Align {
if loc.line - self.line > 1 {
self.finish_group();
}
self.max_width = usize::max(self.max_width, self.width);
self.max_width = u32::max(self.max_width, self.width);
self.line = loc.line;
self.rest.push((loc, self.width));

Expand Down Expand Up @@ -94,7 +94,7 @@ impl Align {
}
}

fn space(&mut self, x: usize) {
fn space(&mut self, x: u32) {
if self.enable {
self.width += x;
}
Expand All @@ -114,7 +114,7 @@ mod align_kind {

#[derive(Default)]
pub struct Aligner {
pub additions: HashMap<Location, usize>,
pub additions: HashMap<Location, u32>,
aligns: [Align; 8],
in_type_expression: bool,
}
Expand Down Expand Up @@ -147,11 +147,11 @@ impl Aligner {
let loc: Location = token.token.into();
self.additions
.entry(loc)
.and_modify(|val| *val += width)
.or_insert(width);
.and_modify(|val| *val += width as u32)
.or_insert(width as u32);
}

fn space(&mut self, repeat: usize) {
fn space(&mut self, repeat: u32) {
for i in 0..self.aligns.len() {
self.aligns[i].space(repeat);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/formatter/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub struct Formatter {
format_opt: Format,
string: String,
indent: usize,
line: usize,
line: u32,
aligner: Aligner,
last_newline: usize,
last_newline: u32,
in_start_token: bool,
consumed_next_newline: bool,
single_line: bool,
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Formatter {
} else {
&text
};
self.last_newline = text.matches('\n').count();
self.last_newline = text.matches('\n').count() as u32;
self.str(text);
self.line = x.line;
}
Expand All @@ -145,7 +145,7 @@ impl Formatter {

let loc: Location = x.token.into();
if let Some(width) = self.aligner.additions.get(&loc) {
self.space(*width);
self.space(*width as usize);
}

// temporary indent to adjust indent of comments with the next push
Expand Down
24 changes: 12 additions & 12 deletions crates/languageserver/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ impl Server {

if let Some(parser) = self.parser_map.get(path) {
let mut finder = Finder::new();
finder.line = line;
finder.column = column;
finder.line = line as u32;
finder.column = column as u32;
finder.veryl(&parser.veryl);

if let Some(token) = finder.token {
Expand Down Expand Up @@ -298,8 +298,8 @@ impl Server {

if let Some(parser) = self.parser_map.get(path) {
let mut finder = Finder::new();
finder.line = line;
finder.column = column;
finder.line = line as u32;
finder.column = column as u32;
finder.veryl(&parser.veryl);
if let Some(token) = finder.token {
if let Some(namespace) = namespace_table::get(token.id) {
Expand Down Expand Up @@ -333,8 +333,8 @@ impl Server {
let mut ret = Vec::new();
if let Some(parser) = self.parser_map.get(path) {
let mut finder = Finder::new();
finder.line = line;
finder.column = column;
finder.line = line as u32;
finder.column = column as u32;
finder.veryl(&parser.veryl);
if let Some(token) = finder.token {
if let Some(namespace) = namespace_table::get(token.id) {
Expand Down Expand Up @@ -392,17 +392,17 @@ impl Server {
let token_line = token.line - 1;
let token_column = token.column - 1;

let delta_line = (token_line - line) as u32;
let delta_line = token_line - line;
let delta_start = if delta_line == 0 {
token_column - column
} else {
token_column
} as u32;
};

let semantic_token = SemanticToken {
delta_line,
delta_start,
length: token.length as u32,
length: token.length,
token_type,
token_modifiers_bitset: 0,
};
Expand Down Expand Up @@ -669,9 +669,9 @@ fn demangle_unexpected_token(text: &str) -> String {
}

fn to_location(token: &Token) -> Location {
let line = token.line as u32 - 1;
let column = token.column as u32 - 1;
let length = token.length as u32;
let line = token.line - 1;
let column = token.column - 1;
let length = token.length;
let uri = Url::parse(&token.file_path.to_string()).unwrap();
let range = Range::new(
Position::new(line, column),
Expand Down
6 changes: 3 additions & 3 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ anyhow = {workspace = true}
bimap = "0.6.3"
miette = {workspace = true}
once_cell = "1.18"
parol_runtime = {version = "0.17.1", features = ["auto_generation"]}
parol_runtime = {version = "0.18.0", features = ["auto_generation"]}
paste = "1.0"
regex = {workspace = true}
thiserror = {workspace = true}

[build-dependencies]
parol = "0.22.1"
parol_runtime = {version = "0.17.1", features = ["auto_generation"]}
parol = "0.23.0"
parol_runtime = {version = "0.18.0", features = ["auto_generation"]}
walkdir = "2.3.3"
10 changes: 5 additions & 5 deletions crates/parser/src/doc_comment_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ use std::collections::HashMap;

#[derive(Clone, Debug, Default)]
pub struct DocCommentTable {
table: HashMap<(PathId, usize), StrId>,
table: HashMap<(PathId, u32), StrId>,
}

impl DocCommentTable {
pub fn insert(&mut self, path: PathId, line: usize, text: StrId) {
pub fn insert(&mut self, path: PathId, line: u32, text: StrId) {
self.table.insert((path, line), text);
}

pub fn get(&self, path: PathId, line: usize) -> Option<StrId> {
pub fn get(&self, path: PathId, line: u32) -> Option<StrId> {
self.table.get(&(path, line)).cloned()
}
}

thread_local!(static DOC_COMMENT_TABLE: RefCell<DocCommentTable> = RefCell::new(DocCommentTable::default()));

pub fn insert(path: PathId, line: usize, text: StrId) {
pub fn insert(path: PathId, line: u32, text: StrId) {
DOC_COMMENT_TABLE.with(|f| f.borrow_mut().insert(path, line, text))
}

pub fn get(path: PathId, line: usize) -> Option<StrId> {
pub fn get(path: PathId, line: u32) -> Option<StrId> {
DOC_COMMENT_TABLE.with(|f| f.borrow().get(path, line))
}
4 changes: 2 additions & 2 deletions crates/parser/src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::veryl_walker::VerylWalker;

#[derive(Default)]
pub struct Finder {
pub line: usize,
pub column: usize,
pub line: u32,
pub column: u32,
pub token: Option<Token>,
pub token_group: Vec<Token>,
hit: bool,
Expand Down
Loading

0 comments on commit 0cb7451

Please sign in to comment.