Skip to content

Commit 3498498

Browse files
committed
Merge branch 'master' into simpler-large-char-set-code
2 parents 15fe07a + dcb7ace commit 3498498

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+914
-730
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/benches/benchmark.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
use std::{
2+
collections::BTreeMap,
3+
env, fs,
4+
path::{Path, PathBuf},
5+
str,
6+
time::Instant,
7+
usize,
8+
};
9+
110
use anyhow::Context;
211
use lazy_static::lazy_static;
3-
use std::collections::BTreeMap;
4-
use std::path::{Path, PathBuf};
5-
use std::time::Instant;
6-
use std::{env, fs, str, usize};
712
use tree_sitter::{Language, Parser, Query};
813
use tree_sitter_loader::{CompileConfig, Loader};
914

cli/config/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![doc = include_str!("../README.md")]
22

3+
use std::{env, fs, path::PathBuf};
4+
35
use anyhow::{anyhow, Context, Result};
46
use serde::{Deserialize, Serialize};
57
use serde_json::Value;
6-
use std::path::PathBuf;
7-
use std::{env, fs};
88

99
/// Holds the contents of tree-sitter's configuration file.
1010
///
@@ -62,8 +62,8 @@ impl Config {
6262
///
6363
/// - Location specified by the path parameter if provided
6464
/// - `$TREE_SITTER_DIR/config.json`, if the `TREE_SITTER_DIR` environment variable is set
65-
/// - `tree-sitter/config.json` in your default user configuration directory, as determined
66-
/// by [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html)
65+
/// - `tree-sitter/config.json` in your default user configuration directory, as determined by
66+
/// [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html)
6767
/// - `$HOME/.tree-sitter/config.json` as a fallback from where tree-sitter _used_ to store
6868
/// its configuration
6969
pub fn load(path: Option<PathBuf>) -> Result<Self> {

cli/loader/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ once_cell.workspace = true
2626
regex.workspace = true
2727
serde.workspace = true
2828
serde_json.workspace = true
29+
tempfile.workspace = true
2930

3031
tree-sitter.workspace = true
3132
tree-sitter-highlight.workspace = true

cli/loader/emscripten-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.37
1+
3.1.55

cli/loader/src/lib.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#![doc = include_str!("../README.md")]
22

3-
use std::collections::HashMap;
4-
use std::ffi::{OsStr, OsString};
5-
use std::io::{BufRead, BufReader};
6-
use std::ops::Range;
7-
use std::path::{Path, PathBuf};
8-
use std::process::Command;
9-
use std::sync::Mutex;
10-
use std::time::SystemTime;
11-
use std::{env, fs, mem};
3+
use std::{
4+
collections::HashMap,
5+
env,
6+
ffi::{OsStr, OsString},
7+
fs,
8+
io::{BufRead, BufReader},
9+
mem,
10+
ops::Range,
11+
path::{Path, PathBuf},
12+
process::Command,
13+
sync::Mutex,
14+
time::SystemTime,
15+
};
1216

1317
use anyhow::{anyhow, Context, Error, Result};
1418
use fs4::FileExt;
@@ -126,11 +130,12 @@ pub struct CompileConfig<'a> {
126130
}
127131

128132
impl<'a> CompileConfig<'a> {
133+
#[must_use]
129134
pub fn new(
130135
src_path: &'a Path,
131136
externals: Option<&'a [PathBuf]>,
132137
output_path: Option<PathBuf>,
133-
) -> CompileConfig<'a> {
138+
) -> Self {
134139
Self {
135140
src_path,
136141
header_paths: vec![src_path],
@@ -445,7 +450,7 @@ impl Loader {
445450
let parser_path = config.src_path.join("parser.c");
446451
config.scanner_path = self.get_scanner_path(config.src_path);
447452

448-
let mut paths_to_check = vec![parser_path.clone()];
453+
let mut paths_to_check = vec![parser_path];
449454

450455
if let Some(scanner_path) = config.scanner_path.as_ref() {
451456
paths_to_check.push(scanner_path.clone());
@@ -484,7 +489,9 @@ impl Loader {
484489
}
485490

486491
let lock_path = if env::var("CROSS_RUNNER").is_ok() {
487-
PathBuf::from("/tmp")
492+
tempfile::tempdir()
493+
.unwrap()
494+
.path()
488495
.join("tree-sitter")
489496
.join("lock")
490497
.join(format!("{}.lock", config.name))
@@ -499,7 +506,8 @@ impl Loader {
499506
if let Ok(lock_file) = fs::OpenOptions::new().write(true).open(&lock_path) {
500507
recompile = false;
501508
if lock_file.try_lock_exclusive().is_err() {
502-
// if we can't acquire the lock, another process is compiling the parser, wait for it and don't recompile
509+
// if we can't acquire the lock, another process is compiling the parser, wait for
510+
// it and don't recompile
503511
lock_file.lock_exclusive()?;
504512
recompile = false;
505513
} else {
@@ -1016,7 +1024,7 @@ impl Loader {
10161024
language_name: grammar_json.name.clone(),
10171025
scope: config_json.scope,
10181026
language_id,
1019-
file_types: config_json.file_types.unwrap_or(Vec::new()),
1027+
file_types: config_json.file_types.unwrap_or_default(),
10201028
content_regex: Self::regex(config_json.content_regex.as_deref()),
10211029
first_line_regex: Self::regex(config_json.first_line_regex.as_deref()),
10221030
injection_regex: Self::regex(config_json.injection_regex.as_deref()),
@@ -1043,8 +1051,11 @@ impl Loader {
10431051
.push(self.language_configurations.len());
10441052
}
10451053

1046-
self.language_configurations
1047-
.push(unsafe { mem::transmute(configuration) });
1054+
self.language_configurations.push(unsafe {
1055+
mem::transmute::<LanguageConfiguration<'_>, LanguageConfiguration<'static>>(
1056+
configuration,
1057+
)
1058+
});
10481059

10491060
if set_current_path_config
10501061
&& self.language_configuration_in_current_path.is_none()
@@ -1083,8 +1094,11 @@ impl Loader {
10831094
highlight_names: &self.highlight_names,
10841095
use_all_highlight_names: self.use_all_highlight_names,
10851096
};
1086-
self.language_configurations
1087-
.push(unsafe { mem::transmute(configuration) });
1097+
self.language_configurations.push(unsafe {
1098+
mem::transmute::<LanguageConfiguration<'_>, LanguageConfiguration<'static>>(
1099+
configuration,
1100+
)
1101+
});
10881102
self.languages_by_id
10891103
.push((parser_path.to_owned(), OnceCell::new(), None));
10901104
}
@@ -1322,8 +1336,7 @@ impl<'a> LanguageConfiguration<'a> {
13221336
.unwrap_or_else(|| ranges.last().unwrap());
13231337
error.offset = offset_within_section - range.start;
13241338
error.row = source[range.start..offset_within_section]
1325-
.chars()
1326-
.filter(|c| *c == '\n')
1339+
.matches(|c| c == '\n')
13271340
.count();
13281341
Error::from(error).context(format!("Error in query file {path:?}"))
13291342
}

cli/npm/install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const matrix = {
4040

4141
// Determine the URL of the file.
4242
const platform = matrix.platform[process.platform];
43-
const arch = platform && platform.arch[process.arch];
43+
const arch = platform?.arch[process.arch];
4444

4545
if (!platform || !platform.name || !arch || !arch.name) {
4646
console.error(
@@ -91,7 +91,7 @@ function get(url, callback) {
9191
}
9292
};
9393

94-
const proxyEnv = process.env['HTTPS_PROXY'] || process.env['https_proxy'];
94+
const proxyEnv = process.env.HTTPS_PROXY || process.env.https_proxy;
9595
if (!proxyEnv) {
9696
https.get(url, processResponse);
9797
return;

cli/src/generate/build_tables/build_lex_table.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
use std::{
2+
collections::{hash_map::Entry, HashMap, VecDeque},
3+
mem,
4+
};
5+
6+
use log::info;
7+
8+
use super::{coincident_tokens::CoincidentTokenIndex, token_conflicts::TokenConflictMap};
19
use crate::generate::{
2-
build_tables::{coincident_tokens::CoincidentTokenIndex, token_conflicts::TokenConflictMap},
310
dedup::split_state_id_groups,
411
grammars::{LexicalGrammar, SyntaxGrammar},
512
nfa::{CharacterSet, NfaCursor},
613
rules::{Symbol, TokenSet},
714
tables::{AdvanceAction, LexState, LexTable, ParseStateId, ParseTable},
815
};
9-
use log::info;
10-
use std::collections::{hash_map::Entry, HashMap, VecDeque};
11-
use std::mem;
1216

1317
pub const LARGE_CHARACTER_RANGE_COUNT: usize = 8;
1418

cli/src/generate/build_tables/build_parse_table.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
use super::item::{ParseItem, ParseItemSet, ParseItemSetCore};
2-
use super::item_set_builder::ParseItemSetBuilder;
3-
use crate::generate::grammars::PrecedenceEntry;
4-
use crate::generate::grammars::{
5-
InlinedProductionMap, LexicalGrammar, SyntaxGrammar, VariableType,
1+
use std::{
2+
cmp::Ordering,
3+
collections::{BTreeMap, HashMap, HashSet, VecDeque},
4+
fmt::Write,
5+
hash::BuildHasherDefault,
66
};
7-
use crate::generate::node_types::VariableInfo;
8-
use crate::generate::rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet};
9-
use crate::generate::tables::{
10-
FieldLocation, GotoAction, ParseAction, ParseState, ParseStateId, ParseTable, ParseTableEntry,
11-
ProductionInfo, ProductionInfoId,
12-
};
13-
use anyhow::{anyhow, Result};
14-
use std::cmp::Ordering;
15-
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
16-
use std::fmt::Write;
17-
use std::hash::BuildHasherDefault;
18-
use std::u32;
197

8+
use anyhow::{anyhow, Result};
209
use indexmap::{map::Entry, IndexMap};
2110
use rustc_hash::FxHasher;
2211

12+
use super::{
13+
item::{ParseItem, ParseItemSet, ParseItemSetCore},
14+
item_set_builder::ParseItemSetBuilder,
15+
};
16+
use crate::generate::{
17+
grammars::{
18+
InlinedProductionMap, LexicalGrammar, PrecedenceEntry, SyntaxGrammar, VariableType,
19+
},
20+
node_types::VariableInfo,
21+
rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet},
22+
tables::{
23+
FieldLocation, GotoAction, ParseAction, ParseState, ParseStateId, ParseTable,
24+
ParseTableEntry, ProductionInfo, ProductionInfoId,
25+
},
26+
};
27+
2328
// For conflict reporting, each parse state is associated with an example
2429
// sequence of symbols that could lead to that parse state.
2530
type SymbolSequence = Vec<Symbol>;
@@ -293,7 +298,7 @@ impl<'a> ParseTableBuilder<'a> {
293298
}
294299
}
295300

296-
reduction_info.precedence = precedence.clone();
301+
reduction_info.precedence.clone_from(precedence);
297302
if let Err(i) = reduction_info.symbols.binary_search(&symbol) {
298303
reduction_info.symbols.insert(i, symbol);
299304
}
@@ -599,13 +604,13 @@ impl<'a> ParseTableBuilder<'a> {
599604
write!(&mut msg, " {}", self.symbol_name(symbol)).unwrap();
600605
}
601606

602-
write!(
607+
writeln!(
603608
&mut msg,
604-
" • {} …\n\n",
609+
" • {} …\n",
605610
self.symbol_name(&conflicting_lookahead)
606611
)
607612
.unwrap();
608-
write!(&mut msg, "Possible interpretations:\n\n").unwrap();
613+
writeln!(&mut msg, "Possible interpretations:\n").unwrap();
609614

610615
let mut interpretations = conflicting_items
611616
.iter()
@@ -680,7 +685,7 @@ impl<'a> ParseTableBuilder<'a> {
680685
}
681686

682687
let mut resolution_count = 0;
683-
write!(&mut msg, "\nPossible resolutions:\n\n").unwrap();
688+
writeln!(&mut msg, "\nPossible resolutions:\n").unwrap();
684689
let mut shift_items = Vec::new();
685690
let mut reduce_items = Vec::new();
686691
for item in conflicting_items {
@@ -956,7 +961,7 @@ fn populate_following_tokens(
956961
for entry in result.iter_mut() {
957962
entry.insert(*extra);
958963
}
959-
result[extra.index] = all_tokens.clone();
964+
result[extra.index].clone_from(&all_tokens);
960965
}
961966
}
962967
}

cli/src/generate/build_tables/coincident_tokens.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use crate::generate::grammars::LexicalGrammar;
2-
use crate::generate::rules::Symbol;
3-
use crate::generate::tables::{ParseStateId, ParseTable};
41
use std::fmt;
52

3+
use crate::generate::{
4+
grammars::LexicalGrammar,
5+
rules::Symbol,
6+
tables::{ParseStateId, ParseTable},
7+
};
8+
69
pub struct CoincidentTokenIndex<'a> {
710
entries: Vec<Vec<ParseStateId>>,
811
grammar: &'a LexicalGrammar,

0 commit comments

Comments
 (0)