Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost-spiritの導入を検討する #1808

Closed
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tests/googletest"]
path = tests/googletest
url = https://github.com/google/googletest.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/Microsoft/vcpkg.git
8 changes: 8 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="local" value=".\" />
</packageSources>
</configuration>
Binary file added .nuget/tests1.dependencies.1.0.0.nupkg
Binary file not shown.
145 changes: 145 additions & 0 deletions BuildDependencies.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
@echo off
setlocal

cd "%~dp0vcpkg"

IF not EXIST vcpkg.exe (
CALL bootstrap-vcpkg.bat
)

vcpkg install boost-spirit:x64-windows
vcpkg install boost-spirit:x86-windows

IF not EXIST "%~dp0.nuget" (
MKDIR "%~dp0.nuget"
)

vcpkg export ^
boost-algorithm:x86-windows ^
boost-align:x86-windows ^
boost-array:x86-windows ^
boost-assert:x86-windows ^
boost-atomic:x86-windows ^
boost-bind:x86-windows ^
boost-build:x64-windows ^
boost-chrono:x86-windows ^
boost-concept-check:x86-windows ^
boost-config:x86-windows ^
boost-container:x86-windows ^
boost-container-hash:x86-windows ^
boost-conversion:x86-windows ^
boost-core:x86-windows ^
boost-date-time:x86-windows ^
boost-detail:x86-windows ^
boost-endian:x86-windows ^
boost-exception:x86-windows ^
boost-function:x86-windows ^
boost-function-types:x86-windows ^
boost-fusion:x86-windows ^
boost-integer:x86-windows ^
boost-intrusive:x86-windows ^
boost-io:x86-windows ^
boost-iterator:x86-windows ^
boost-lexical-cast:x86-windows ^
boost-modular-build-helper:x64-windows ^
boost-move:x86-windows ^
boost-mp11:x86-windows ^
boost-mpl:x86-windows ^
boost-numeric-conversion:x86-windows ^
boost-optional:x86-windows ^
boost-phoenix:x86-windows ^
boost-pool:x86-windows ^
boost-predef:x86-windows ^
boost-preprocessor:x86-windows ^
boost-proto:x86-windows ^
boost-range:x86-windows ^
boost-ratio:x86-windows ^
boost-rational:x86-windows ^
boost-regex:x86-windows ^
boost-smart-ptr:x86-windows ^
boost-spirit:x86-windows ^
boost-static-assert:x86-windows ^
boost-system:x86-windows ^
boost-thread:x86-windows ^
boost-throw-exception:x86-windows ^
boost-tokenizer:x86-windows ^
boost-tuple:x86-windows ^
boost-type-index:x86-windows ^
boost-type-traits:x86-windows ^
boost-typeof:x86-windows ^
boost-uninstall:x86-windows ^
boost-uninstall:x64-windows ^
boost-unordered:x86-windows ^
boost-utility:x86-windows ^
boost-variant:x86-windows ^
boost-variant2:x86-windows ^
boost-vcpkg-helpers:x86-windows ^
boost-winapi:x86-windows ^
vcpkg-cmake:x64-windows ^
boost-spirit:x64-windows ^
--nuget --nuget-id=sakura.dependencies --nuget-version=1.0.0 --output-dir="%~dp0.nuget"

vcpkg export ^
boost-algorithm:x86-windows ^
boost-align:x86-windows ^
boost-array:x86-windows ^
boost-assert:x86-windows ^
boost-atomic:x86-windows ^
boost-bind:x86-windows ^
boost-build:x64-windows ^
boost-chrono:x86-windows ^
boost-concept-check:x86-windows ^
boost-config:x86-windows ^
boost-container:x86-windows ^
boost-container-hash:x86-windows ^
boost-conversion:x86-windows ^
boost-core:x86-windows ^
boost-date-time:x86-windows ^
boost-detail:x86-windows ^
boost-endian:x86-windows ^
boost-exception:x86-windows ^
boost-function:x86-windows ^
boost-function-types:x86-windows ^
boost-fusion:x86-windows ^
boost-integer:x86-windows ^
boost-intrusive:x86-windows ^
boost-io:x86-windows ^
boost-iterator:x86-windows ^
boost-lexical-cast:x86-windows ^
boost-modular-build-helper:x64-windows ^
boost-move:x86-windows ^
boost-mp11:x86-windows ^
boost-mpl:x86-windows ^
boost-numeric-conversion:x86-windows ^
boost-optional:x86-windows ^
boost-phoenix:x86-windows ^
boost-pool:x86-windows ^
boost-predef:x86-windows ^
boost-preprocessor:x86-windows ^
boost-proto:x86-windows ^
boost-range:x86-windows ^
boost-ratio:x86-windows ^
boost-rational:x86-windows ^
boost-regex:x86-windows ^
boost-smart-ptr:x86-windows ^
boost-spirit:x86-windows ^
boost-static-assert:x86-windows ^
boost-system:x86-windows ^
boost-thread:x86-windows ^
boost-throw-exception:x86-windows ^
boost-tokenizer:x86-windows ^
boost-tuple:x86-windows ^
boost-type-index:x86-windows ^
boost-type-traits:x86-windows ^
boost-typeof:x86-windows ^
boost-uninstall:x86-windows ^
boost-uninstall:x64-windows ^
boost-unordered:x86-windows ^
boost-utility:x86-windows ^
boost-variant:x86-windows ^
boost-variant2:x86-windows ^
boost-vcpkg-helpers:x86-windows ^
boost-winapi:x86-windows ^
vcpkg-cmake:x64-windows ^
boost-spirit:x64-windows ^
--nuget --nuget-id=tests1.dependencies --nuget-version=1.0.0 --output-dir="%~dp0.nuget"
4 changes: 4 additions & 0 deletions tests/unittests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="tests1.dependencies" version="1.0.0" targetFramework="native" />
</packages>
50 changes: 50 additions & 0 deletions tests/unittests/test-ccommandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,56 @@ bool operator != (const EditInfo& lhs, const EditInfo& rhs) noexcept;
bool operator == (const GrepInfo& lhs, const GrepInfo& rhs) noexcept;
bool operator != (const GrepInfo& lhs, const GrepInfo& rhs) noexcept;

// Boost spirit の導入検証
// http://www.kmonos.net/alang/boost/classes/spirit.html
#include <iostream>
#include <boost/spirit/include/qi.hpp>
#include <boost/phoenix.hpp>

// 例3: 少しちゃんとした例。数式を計算します
// 文法定義
// expr ::= term ('+' term | '-' term)*
// term ::= fctr ('*' fctr | '/' fctr)*
// fctr ::= int | '(' expr ')'
// 開始記号
// expr
//
template<typename Iterator>
struct calc
: boost::spirit::qi::grammar<Iterator, int(), boost::spirit::ascii::space_type>
{
using namespace std;
using namespace boost;
using namespace boost::spirit;

qi::rule<Iterator, int(), ascii::space_type> expr;
qi::rule<Iterator, int(), ascii::space_type> term;
qi::rule<Iterator, int(), ascii::space_type> fctr;

calc() : calc::base_type(expr)
{
expr = term[_val = _1] >> *(('+' >> term[_val += _1]) | ('-' >> term[_val -= _1]));
term = fctr[_val = _1] >> *(('*' >> fctr[_val *= _1]) | ('/' >> fctr[_val /= _1]))[&Oops];
fctr = int_ | '(' >> expr >> ')';
}

// 計算ついでに、* と / を見ると意味もなく Oops! と叫ぶコード
static void Oops() { cout << "Oops!" << endl; }
};

TEST(CCommandLine, UseBoostSpirit)
{
std::string str = "100 + 101 * 4";
calc<std::string::iterator> c;

int result = -1;

std::string::iterator it = str.begin();
if (boost::spirit::qi::phrase_parse(it, str.end(), c, boost::spirit::ascii::space, result)) {
std::cout << result << std::endl;
}
}

/*!
* ローカルパスをフルパスに変換する
*
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/tests1.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.props" Condition="Exists('..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -160,6 +161,7 @@
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="tests1_rc.rc" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
Expand All @@ -182,6 +184,14 @@
<ItemGroup>
<TestResource Include="test-plugin\plugin.def" />
</ItemGroup>
<Import Project="..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.targets" Condition="Exists('..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.props'))" />
<Error Condition="!Exists('..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\tests1.dependencies.1.0.0\build\native\tests1.dependencies.targets'))" />
</Target>
<Target Name="MakeTestResource" BeforeTargets="ResourceCompile" Inputs="@(TestResource->'resources\ja-JP\%(RelativeDir)%(filename)%(Extension)')" Outputs="$(IntDir)resources.ja-JP.zip">
<Exec Command="7z u &quot;$(IntDir)resources.ja-JP.zip&quot; -tzip @(TestResource->'%(RelativeDir)%(filename)%(Extension)',' ')" WorkingDirectory="$(ProjectDir)resources\ja-JP" />
</Target>
Expand Down
5 changes: 5 additions & 0 deletions tests/unittests/tests1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,9 @@
<Filter>Other Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
<Filter>Other Files</Filter>
</None>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at 5cf601