Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# If this file is renamed, the incrementing run attempt number will be reset.

name: CI

on:
push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]

env:
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
build:

runs-on: ubuntu-24.04

permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Compute build number
run: |
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+200))" >> $GITHUB_ENV
- name: Build and Publish
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
./Build.ps1
72 changes: 46 additions & 26 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,57 +1,77 @@
# This script originally (c) 2016 Serilog Contributors - license Apache 2.0

echo "build: Build started"
Write-Output "build: Build started"

Push-Location $PSScriptRoot

Write-Output "build: Tool versions follow"

dotnet --version
dotnet --list-sdks

if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
Write-Output "build: Cleaning ./artifacts"
Remove-Item ./artifacts -Force -Recurse
}

& dotnet restore --no-cache

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)).Replace("/", "-"))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
$dbp = [Xml] (Get-Content .\Directory.Build.props)
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix

Write-Output "build: Package version prefix is $versionPrefix"

echo "build: Version suffix is $suffix"
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]

foreach ($src in ls src/*) {
Write-Output "build: Package version suffix is $suffix"

foreach ($src in Get-ChildItem src/*) {
Push-Location $src

echo "build: Packaging project in $src"
Write-Output "build: Packaging project in $src"

if ($suffix) {
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --include-source
& dotnet pack -c Release -o ../../artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release -o ..\..\artifacts --include-source
& dotnet pack -c Release -o ../../artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }

Pop-Location
}

foreach ($test in ls test/*.Benchmarks) {
Push-Location $test

echo "build: Building performance test project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
Write-Output "build: Checking complete solution builds"
& dotnet build
if($LASTEXITCODE -ne 0) { throw "Solution build failed" }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
foreach ($test in Get-ChildItem test/*.Tests) {
Push-Location $test

echo "build: Testing project in $test"
Write-Output "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }
if($LASTEXITCODE -ne 0) { throw "Testing failed" }

Pop-Location
}

Pop-Location

if ($env:NUGET_API_KEY) {
# GitHub Actions will only supply this to branch builds and not PRs. We publish
# builds from any branch this action targets (i.e. main and dev).

Write-Output "build: Publishing NuGet packages"

foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
}

if (!($suffix)) {
Write-Output "build: Creating release for version $versionPrefix"

iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
}
}
18 changes: 18 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<VersionPrefix>3.2.0</VersionPrefix>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- The condition is required to support BenchmarkDotNet -->
<SignAssembly Condition="Exists('../../asset/Superpower.snk')">true</SignAssembly>
<AssemblyOriginatorKeyFile>../../asset/Superpower.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>NETSDK1138</NoWarn>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Superpower [![Build status](https://ci.appveyor.com/api/projects/status/7bj6if6tyc68urpy?svg=true)](https://ci.appveyor.com/project/datalust/superpower) [![NuGet Version](https://img.shields.io/nuget/vpre/Superpower.svg?style=flat)](https://www.nuget.org/packages/Superpower/) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-superpower-orange.svg)](http://stackoverflow.com/questions/tagged/superpower)
# Superpower [![NuGet Version](https://img.shields.io/nuget/vpre/Superpower.svg?style=flat)](https://www.nuget.org/packages/Superpower/)

A [parser combinator](https://en.wikipedia.org/wiki/Parser_combinator) library based on
[Sprache](https://github.com/sprache/Sprache). Superpower generates friendlier error messages through its support for
Expand Down
1 change: 0 additions & 1 deletion Superpower.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AC295EEA-D31
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{66B005E9-A083-41E8-BD89-4D6E753CD8BF}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
Benchmark.ps1 = Benchmark.ps1
Build.ps1 = Build.ps1
LICENSE = LICENSE
Expand Down
2 changes: 2 additions & 0 deletions Superpower.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=2c62818f_002D621b_002D4425_002Dadc9_002D78611099bfcb/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Type parameters"&gt;&lt;ElementKinds&gt;&lt;Kind Name="TYPE_PARAMETER" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="T" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=allocs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=errloc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=expsign/@EntryIndexedValue">True</s:Boolean>
Expand Down
22 changes: 0 additions & 22 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.300",
"version": "10.0.201",
"rollForward": "latestFeature"
}
}
3 changes: 2 additions & 1 deletion sample/DateTimeTextParser/DateTimeParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion sample/IntCalc/IntCalc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion sample/JsonParser/JsonParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/Superpower/Model/TextSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ public string ToStringValue()
return Source!.Substring(Position.Absolute, Length);
}

/// <summary>
/// Compute the string value of this span and return the view of source directly.
/// </summary>
/// <returns>A view of string with the value of this span.</returns>
public ReadOnlySpan<char> AsReadOnlySpan()
{
EnsureHasValue();
return Source!.AsSpan(Position.Absolute, Length);
}

/// <summary>
/// Compare the contents of this span with <paramref name="otherValue"/>.
/// </summary>
Expand Down
14 changes: 3 additions & 11 deletions src/Superpower/Superpower.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<Description>A parser combinator library for C#</Description>
<VersionPrefix>3.1.0</VersionPrefix>
<Authors>Datalust;Superpower Contributors;Sprache Contributors</Authors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyOriginatorKeyFile>../../asset/Superpower.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageTags>superpower;parser</PackageTags>
<PackageProjectUrl>https://github.com/datalust/superpower</PackageProjectUrl>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<PackageIcon>Superpower-White-400px.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/datalust/superpower</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>$(DefineConstants);CHECKED</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\asset\Superpower-White-400px.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="System.Memory" Version="4.6.3" />
</ItemGroup>
</Project>
13 changes: 7 additions & 6 deletions test/Superpower.Benchmarks/Superpower.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Superpower\Superpower.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Sprache" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
<PackageReference Include="Sprache" Version="2.3.1" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions test/Superpower.Tests/Model/TextSpanTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Superpower.Model;
using Xunit;

namespace Superpower.Tests.Model
{
public class TextSpanTest
{
[Theory]
[InlineData("hello", 0, 5, "hello")]
[InlineData("hello", 1, 3, "ell")]
[InlineData("hello", 2, 0, "")]
[InlineData("The quick brown fox jumps over the lazy dog", 9, 7, " brown ")]
public void AsReadOnlySpanWorks(string input, int start, int length, string expected)
{
var span = new TextSpan(input).Skip(start).First(length);
var readOnlySpan = span.AsReadOnlySpan();
Assert.Equal(expected, readOnlySpan.ToString());
}

[Fact]
public void AsReadOnlySpanEnsureHasValue()
{
Assert.Throws<InvalidOperationException>(() => TextSpan.None.AsReadOnlySpan());
}
}
}
2 changes: 1 addition & 1 deletion test/Superpower.Tests/Parsers/SpanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SpanTests
public void RegularExpressionParsersAreApplied(
string input,
string regex,
string match,
string? match,
int start = 0,
int length = -1)
{
Expand Down
9 changes: 5 additions & 4 deletions test/Superpower.Tests/Superpower.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<AssemblyName>Superpower.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../../asset/Superpower.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -11,16 +11,17 @@
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Superpower\Superpower.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>
</Project>
Loading