Skip to content

Commit

Permalink
Update to syn 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Mar 1, 2024
1 parent 6d94535 commit 579406c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 112 deletions.
54 changes: 28 additions & 26 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish crates on crates.io
name: Release crate

on:
workflow_dispatch:
Expand All @@ -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 [email protected]
- 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 [email protected]
- 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 }}
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 }}
78 changes: 39 additions & 39 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
12 changes: 6 additions & 6 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[workspace]
members = ["derive-finite-automaton", "derive-finite-automaton-derive"]

[workspace.lints.clippy]
all = "deny"
pedantic = "deny"
2 changes: 1 addition & 1 deletion derive-finite-automaton-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion derive-finite-automaton-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<trie::Mappings>().unwrap();
Expand Down
59 changes: 21 additions & 38 deletions derive-finite-automaton-derive/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -114,7 +114,7 @@ pub(super) struct Mappings(syn::punctuated::Punctuated<(Vec<Matcher>, Expr), syn
impl syn::parse::Parse for Mappings {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
input
.parse_terminated::<_, Token![,]>(parse_item_to_matchers_and_expression)
.parse_terminated(parse_item_to_matchers_and_expression, Token![,])
.map(Self)
}
}
Expand All @@ -128,41 +128,24 @@ impl Mappings {
fn parse_item_to_matchers_and_expression(
input: &syn::parse::ParseBuffer<'_>,
) -> Result<(Vec<Matcher>, Expr), SynError> {
let pat: Pat = input.parse()?;
let pat: Pat = Pat::parse_multi(input)?;
let matchers: Vec<Matcher> = 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(),
Expand All @@ -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),
Expand All @@ -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(),
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion derive-finite-automaton/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 579406c

Please sign in to comment.