Skip to content

Commit ed2ae23

Browse files
authored
Merge pull request #20990 from Veykril/push-zzrzusnvwpzp
Merge `ungrammar` into rust-analyzer
2 parents 3efda63 + df009ee commit ed2ae23

File tree

16 files changed

+1496
-3
lines changed

16 files changed

+1496
-3
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["xtask/", "lib/*", "crates/*"]
2+
members = ["xtask/", "lib/*", "lib/ungrammar/ungrammar2json", "crates/*"]
33
exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
44
resolver = "2"
55

@@ -42,7 +42,7 @@ debug = 2
4242
# lsp-server = { path = "lib/lsp-server" }
4343

4444

45-
# ungrammar = { path = "../ungrammar" }
45+
# ungrammar = { path = "lin/ungrammar" }
4646

4747
# salsa = { path = "../salsa" }
4848
# salsa-macros = { path = "../salsa/components/salsa-macros" }

lib/ungrammar/.github/ci.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use std::{
2+
env, fs,
3+
process::{self, Command, ExitStatus, Stdio},
4+
time::Instant,
5+
};
6+
7+
type Error = Box<dyn std::error::Error>;
8+
type Result<T> = std::result::Result<T, Error>;
9+
10+
fn main() {
11+
if let Err(err) = try_main() {
12+
eprintln!("{}", err);
13+
process::exit(1);
14+
}
15+
}
16+
17+
fn try_main() -> Result<()> {
18+
let cwd = env::current_dir()?;
19+
let cargo_toml = cwd.join("Cargo.toml");
20+
assert!(
21+
cargo_toml.exists(),
22+
"Cargo.toml not found, cwd: {}",
23+
cwd.display()
24+
);
25+
26+
{
27+
let _s = Section::new("BUILD");
28+
shell("cargo test --workspace --no-run")?;
29+
}
30+
31+
{
32+
let _s = Section::new("TEST");
33+
shell("cargo test --workspace")?;
34+
}
35+
36+
let current_branch = shell_output("git branch --show-current")?;
37+
if &current_branch == "master" {
38+
let _s = Section::new("PUBLISH");
39+
let manifest = fs::read_to_string(&cargo_toml)?;
40+
let version = get_field(&manifest, "version")?;
41+
let tag = format!("v{}", version);
42+
let tags = shell_output("git tag --list")?;
43+
44+
if !tags.contains(&tag) {
45+
let token = env::var("CRATES_IO_TOKEN").unwrap();
46+
shell(&format!("git tag v{}", version))?;
47+
shell(&format!("cargo publish --token {}", token))?;
48+
shell("git push --tags")?;
49+
}
50+
}
51+
Ok(())
52+
}
53+
54+
fn get_field<'a>(text: &'a str, name: &str) -> Result<&'a str> {
55+
for line in text.lines() {
56+
let words = line.split_ascii_whitespace().collect::<Vec<_>>();
57+
match words.as_slice() {
58+
[n, "=", v, ..] if n.trim() == name => {
59+
assert!(v.starts_with('"') && v.ends_with('"'));
60+
return Ok(&v[1..v.len() - 1]);
61+
}
62+
_ => (),
63+
}
64+
}
65+
Err(format!("can't find `{}` in\n----\n{}\n----\n", name, text))?
66+
}
67+
68+
fn shell(cmd: &str) -> Result<()> {
69+
let status = command(cmd).status()?;
70+
check_status(status)
71+
}
72+
73+
fn shell_output(cmd: &str) -> Result<String> {
74+
let output = command(cmd).stderr(Stdio::inherit()).output()?;
75+
check_status(output.status)?;
76+
let res = String::from_utf8(output.stdout)?;
77+
Ok(res.trim().to_string())
78+
}
79+
80+
fn command(cmd: &str) -> Command {
81+
eprintln!("> {}", cmd);
82+
let words = cmd.split_ascii_whitespace().collect::<Vec<_>>();
83+
let (cmd, args) = words.split_first().unwrap();
84+
let mut res = Command::new(cmd);
85+
res.args(args);
86+
res
87+
}
88+
89+
fn check_status(status: ExitStatus) -> Result<()> {
90+
if !status.success() {
91+
Err(format!("$status: {}", status))?;
92+
}
93+
Ok(())
94+
}
95+
96+
struct Section {
97+
name: &'static str,
98+
start: Instant,
99+
}
100+
101+
impl Section {
102+
fn new(name: &'static str) -> Section {
103+
println!("::group::{}", name);
104+
let start = Instant::now();
105+
Section { name, start }
106+
}
107+
}
108+
109+
impl Drop for Section {
110+
fn drop(&mut self) {
111+
eprintln!("{}: {:.2?}", self.name, self.start.elapsed());
112+
println!("::endgroup::");
113+
}
114+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- staging
8+
- trying
9+
10+
env:
11+
CARGO_INCREMENTAL: 0
12+
CARGO_NET_RETRY: 10
13+
CI: 1
14+
RUST_BACKTRACE: short
15+
RUSTFLAGS: -D warnings
16+
RUSTUP_MAX_RETRIES: 10
17+
18+
jobs:
19+
rust:
20+
name: Rust
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: Install Rust toolchain
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
toolchain: stable
31+
profile: minimal
32+
override: true
33+
34+
- run: rustc ./.github/ci.rs && ./ci
35+
env:
36+
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

lib/ungrammar/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/ci
2+
/Cargo.lock
3+
/target

lib/ungrammar/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "ungrammar"
3+
description = "A DSL for describing concrete syntax trees"
4+
version = "1.16.1"
5+
license = "MIT OR Apache-2.0"
6+
repository = "https://github.com/rust-analyzer/ungrammar"
7+
edition = "2018"
8+
9+
exclude = ["/bors.toml", "/.github"]
10+
11+
12+
[dependencies]
13+
# nope

lib/ungrammar/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ungrammar
2+
3+
A DSL for specifying concrete syntax trees.
4+
5+
See the [blog post][post] for an introduction.
6+
7+
See [./rust.ungram](./rust.ungram) for an example.
8+
9+
## Editor support
10+
11+
- Vim
12+
- [vim-ungrammar][]
13+
- [ungrammar.vim][]
14+
- VSCode
15+
- [ungrammar-tools][]
16+
17+
[post]:
18+
https://rust-analyzer.github.io/blog/2020/10/24/introducing-ungrammar.html
19+
[vim-ungrammar]: https://github.com/Iron-E/vim-ungrammar
20+
[ungrammar.vim]: https://github.com/drtychai/ungrammar.vim
21+
[ungrammar-tools]: https://github.com/azdavis/ungrammar-tools

lib/ungrammar/bors.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
status = [ "Rust" ]
2+
delete_merged_branches = true

0 commit comments

Comments
 (0)