From 579406cd3db89fa3104d1f87e3ca01d8c8e42b12 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 1 Mar 2024 09:08:45 +0000 Subject: [PATCH] Update to syn 2 --- .github/workflows/crates.yml | 54 +++++++-------- .github/workflows/rust.yml | 78 +++++++++++----------- Cargo.lock | 12 ++-- Cargo.toml | 4 ++ derive-finite-automaton-derive/Cargo.toml | 2 +- derive-finite-automaton-derive/src/lib.rs | 2 +- derive-finite-automaton-derive/src/trie.rs | 59 ++++++---------- derive-finite-automaton/examples/main.rs | 2 +- 8 files changed, 101 insertions(+), 112 deletions(-) diff --git a/.github/workflows/crates.yml b/.github/workflows/crates.yml index 7449d52..d55e0d9 100644 --- a/.github/workflows/crates.yml +++ b/.github/workflows/crates.yml @@ -1,4 +1,4 @@ -name: Publish crates on crates.io +name: Release crate on: workflow_dispatch: @@ -12,38 +12,40 @@ on: required: false default: "none" +concurrency: release-crate + jobs: publish: runs-on: ubuntu-latest permissions: contents: write steps: - - uses: actions/checkout@v2 - - name: Set git credentials - run: | - git config user.name github-actions - git config user.email github-actions@github.com - - name: Publish crates - uses: kaleidawave/crates-release-gh-action@main - id: release - with: - version: | + - uses: actions/checkout@v4 + - name: Set git credentials + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: Crates publish + uses: kaleidawave/crates-release-gh-action@main + id: release + with: + version: | { "derive-finite-automaton": "${{ github.event.inputs.version }}", "derive-finite-automaton-derive": "${{ github.event.inputs.derive-version }}" } - crates-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Push updated Cargo.toml - run: | - echo '${{ steps.release.outputs.new-versions }}' | jq -r '.[]' | while read -r update; do - git tag "release/$update" - done - git add . - git commit -m "Release: ${{ steps.release.outputs.new-versions-description }}" - git push --tags origin main - - name: Discord - uses: dusmartijngames/discord-webhook-notify@master - with: - severity: info - text: "Released version ${{ steps.release.outputs.new-versions-description }}" - webhookUrl: ${{ secrets.DISCORD_WEBHOOK_ENDPOINT }} \ No newline at end of file + crates-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: Push updated Cargo.toml + run: | + git add . + git commit -m "Release: ${{ steps.release.outputs.new-versions-description }}" + echo '${{ steps.release.outputs.new-versions }}' | jq -r '.[]' | while read -r update; do + git tag "release/$update" + done + git push --tags origin main + - name: Discord + uses: dusmartijngames/discord-webhook-notify@master + with: + severity: info + text: "Released version ${{ steps.release.outputs.new-versions-description }}" + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_ENDPOINT }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 303b505..e349069 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,60 +19,60 @@ jobs: validity: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: ${{ env.CACHE_PATHS }} - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Check source is valid - run: cargo check --workspace + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Check source is valid + run: cargo check --workspace formating: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Check Rust formatting with rustfmt - run: cargo fmt --all --check - - uses: brndnmtthws/rust-action-cargo-binstall@v1 - with: - packages: taplo-cli - - name: Check TOML formatting with taplo - run: | - taplo fmt --check **/*/Cargo.toml + - uses: actions/checkout@v4 + - name: Check formatting with rustfmt + run: cargo fmt --all --check + - uses: brndnmtthws/rust-action-cargo-binstall@v1 + with: + packages: taplo-cli + - name: Check TOML formatting with taplo + run: | + taplo fmt --check **/*/Cargo.toml tests: needs: validity runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: ${{ env.CACHE_PATHS }} - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Run all tests - run: cargo test --workspace --verbose --all-features + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Run all tests + run: cargo test --workspace --verbose --all-features clippy: needs: validity runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: ${{ env.CACHE_PATHS }} - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Lint code with clippy - run: cargo clippy + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Lint code with clippy + run: cargo clippy publish-ability: runs-on: ubuntu-latest + if: false steps: - - uses: actions/checkout@v3 - - name: Check that it will publish to crates - run: | - cargo metadata --offline --format-version 1 --no-deps | jq -r ".workspace_members[]" | while read -r _n _v pathInfo ; do - cd ${pathInfo:13:-1} - cargo publish --no-verify --dry-run - done - shell: bash \ No newline at end of file + - uses: actions/checkout@v4 + - name: Check that it will publish to crates + run: | + cargo metadata --offline --format-version 1 --no-deps | jq -r ".workspace_members[]" | while read -r _n _v pathInfo ; do + cd ${pathInfo:13:-1} + cargo publish --no-verify --dry-run + done + shell: bash diff --git a/Cargo.lock b/Cargo.lock index 5dd388c..7f5c11f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,27 +27,27 @@ checksum = "4c91ae510829160d5cfb19eb4ae7b6e01d44b767ca8f727c6cee936e53cc9ae5" [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] [[package]] name = "syn" -version = "1.0.109" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7164796..82e4868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,6 @@ [workspace] members = ["derive-finite-automaton", "derive-finite-automaton-derive"] + +[workspace.lints.clippy] +all = "deny" +pedantic = "deny" diff --git a/derive-finite-automaton-derive/Cargo.toml b/derive-finite-automaton-derive/Cargo.toml index e8c27f5..5ad8ef3 100644 --- a/derive-finite-automaton-derive/Cargo.toml +++ b/derive-finite-automaton-derive/Cargo.toml @@ -19,7 +19,7 @@ proc-macro = true proc-macro2 = "1.0" either_n = "0.2" quote = "1.0" -syn = { version = "1.0", features = [ +syn = { version = "2.0", features = [ "printing", "full", "parsing", diff --git a/derive-finite-automaton-derive/src/lib.rs b/derive-finite-automaton-derive/src/lib.rs index 0827951..3f5f1f2 100644 --- a/derive-finite-automaton-derive/src/lib.rs +++ b/derive-finite-automaton-derive/src/lib.rs @@ -18,7 +18,7 @@ pub fn stateful_trie_constructor(input: TokenStream) -> TokenStream { let filter = input .attrs .iter() - .filter(|attr| attr.path.is_ident("automaton_mappings")); + .filter(|attr| attr.path().is_ident("automaton_mappings")); for attribute in filter { let m = attribute.parse_args::().unwrap(); diff --git a/derive-finite-automaton-derive/src/trie.rs b/derive-finite-automaton-derive/src/trie.rs index 8851c7e..47f67a5 100644 --- a/derive-finite-automaton-derive/src/trie.rs +++ b/derive-finite-automaton-derive/src/trie.rs @@ -48,7 +48,7 @@ pub(super) fn expand_trie( let new_state_name_ident = { let as_string = prev_state.to_string(); count += 1; - let state_name = (count + 'A' as u8) as char; + let state_name = (count + b'A') as char; // Creating state names: if as_string.is_empty() || as_string == crate::NO_STATE_NAME { Ident::new(&state_name.to_string(), Span::call_site()) @@ -114,7 +114,7 @@ pub(super) struct Mappings(syn::punctuated::Punctuated<(Vec, Expr), syn impl syn::parse::Parse for Mappings { fn parse(input: syn::parse::ParseStream) -> syn::Result { input - .parse_terminated::<_, Token![,]>(parse_item_to_matchers_and_expression) + .parse_terminated(parse_item_to_matchers_and_expression, Token![,]) .map(Self) } } @@ -128,41 +128,24 @@ impl Mappings { fn parse_item_to_matchers_and_expression( input: &syn::parse::ParseBuffer<'_>, ) -> Result<(Vec, Expr), SynError> { - let pat: Pat = input.parse()?; + let pat: Pat = Pat::parse_multi(input)?; let matchers: Vec = if let Pat::Slice(slice) = pat { let mut matchers = Vec::new(); for pat in slice.elems.iter() { let matcher = match pat { - Pat::Lit(PatLit { expr, .. }) => { - if let Expr::Lit(ExprLit { - lit: Lit::Char(chr), - .. - }) = &**expr - { - Matcher::Single(chr.value()) - } else { - return Err(SynError::new( - Span::call_site(), - "Expected character matcher", - )); - } - } + Pat::Lit(PatLit { + lit: Lit::Char(chr), + .. + }) => Matcher::Single(chr.value()), Pat::Or(PatOr { cases, .. }) => { let mut char_cases = Vec::new(); for case in cases { - if let Pat::Lit(PatLit { expr, .. }) = case { - if let Expr::Lit(ExprLit { - lit: Lit::Char(chr), - .. - }) = &**expr - { - char_cases.push(chr.value()); - } else { - return Err(SynError::new( - Span::call_site(), - "Expected character matcher", - )); - } + if let Pat::Lit(PatLit { + lit: Lit::Char(chr), + .. + }) = case + { + char_cases.push(chr.value()); } else { return Err(SynError::new( Span::call_site(), @@ -172,7 +155,11 @@ fn parse_item_to_matchers_and_expression( } Matcher::Or(char_cases) } - Pat::Range(PatRange { lo, hi, .. }) => { + Pat::Range(PatRange { + start: Some(start), + end: Some(end), + .. + }) => { if let ( Expr::Lit(ExprLit { lit: Lit::Char(chr_lo), @@ -182,7 +169,7 @@ fn parse_item_to_matchers_and_expression( lit: Lit::Char(chr_hi), .. }), - ) = (&**lo, &**hi) + ) = (&**start, &**end) { Matcher::Range { from: chr_lo.value(), @@ -206,12 +193,8 @@ fn parse_item_to_matchers_and_expression( matchers.push(matcher); } matchers - } else if let Pat::Lit(PatLit { expr, .. }) = pat { - if let Expr::Lit(ExprLit { - lit: Lit::Str(string), - .. - }) = &*expr - { + } else if let Pat::Lit(PatLit { lit, .. }) = pat { + if let Lit::Str(string) = lit { string.value().chars().map(Matcher::Single).collect() } else { return Err(SynError::new( diff --git a/derive-finite-automaton/examples/main.rs b/derive-finite-automaton/examples/main.rs index 1ec6c9a..2eba7f5 100644 --- a/derive-finite-automaton/examples/main.rs +++ b/derive-finite-automaton/examples/main.rs @@ -44,7 +44,7 @@ fn main() { for (idx, chr) in source.char_indices() { match state { LexingState::Literal => { - if !matches!(chr, 'a'..='z' | 'A'..='Z') { + if !chr.is_ascii_alphabetic() { tokens.push(Tokens::Literal(source[start..idx].to_owned())); start = 0; state = LexingState::None;