Bve5_Parsing 0.7.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Bve5_Parsing --version 0.7.0
NuGet\Install-Package Bve5_Parsing -Version 0.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bve5_Parsing" Version="0.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bve5_Parsing --version 0.7.0
#r "nuget: Bve5_Parsing, 0.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bve5_Parsing as a Cake Addin
#addin nuget:?package=Bve5_Parsing&version=0.7.0

// Install Bve5_Parsing as a Cake Tool
#tool nuget:?package=Bve5_Parsing&version=0.7.0

Build Status NuGet version MIT License

Bve5_Parsing

bve5PasingImage

Bve5構文のC#パーサライブラリです。 Bve5の構文はどのように処理されているのか?という疑問を解消すべく、パーサジェネレータ「ANTLR」を利用し、Bve5.7構文のパーサを実装してみました。現在、Bve5.7.6224.40815の一部構文に対応しています。 特にイレギュラーな入力(引数の数が異なる,構文名が異なる等)に対する処理が本家ソフトウェアと比べてかなり相違があります。

Notes on use

Bve5_Parsingは開発中のライブラリです。Nugetでパッケージを公開してますが、破壊的変更を行う可能性があるのでバージョンアップには注意して下さい。

Supported Syntaxes

  • Scenario File
    • Bve5.7全構文に対応
    • namespace: ScenarioGrammar
    • 出力: ScenarioDataクラス 構文解析の結果は、ScenarioDataクラスで返します。ScenarioDataクラスは以下のフィールドで構成されています。
      • string Version: シナリオファイルのバージョン情報
      • List<FilePath> Route: マップファイルの相対パス
      • List<FilePath> Vehicle: 車両ファイルの相対パス
      • string Image: サムネイル画像の相対パス
      • string Title: シナリオタイトル
      • string RouteTitle: 路線名
      • string VehicleTitle: 車両名
      • string Author: 路線と車両の作者
      • string Comment: シナリオの説明

    なお、RouteとVechicleに関しては、複数ファイルの指定と重み係数に対応するため、相対パスと重み係数をまとめたFilePath構造体のリストを返します。相対パスはFilePath.Value、重み係数はFilePath.Weightに対応しています。

    詳しくは、ScenarioData.csを参照してください。

  • Map File
    • Bve5.7全構文と変数、一部の古い構文(Legacy構文)に対応

    • namespace: MapGrammar

    • 出力: MapDataクラス 構文解析の結果は、MapDataクラスで返します。MapDataクラスは以下のフィールドで構成されています。

      • string Version: バージョン情報
      • string Encoding: ファイルエンコーディング
      • string StructureListPath: ストラクチャリストの相対パス
      • string StationListPath: 停車場リストの相対パス
      • string SignalListPath: 信号リストの相対パス
      • string SoundListPath: サウンドリストの相対パス
      • string Sound3DListPath: 固定音源リストの相対パス
      • List<SyntaxData> Statements: 各構文情報をまとめたSyntaxDataクラスのリスト
    • そのうち、Statementsは各構文情報をまとめたSyntaxDataクラスのリストを返します。SyntaxDataクラスは以下のフィールドで構成されてます。

      • double Distance: 構文の距離程
      • string[] MapElement: 構文のマップ要素(ex.Structure,Repeaterなど)
      • string Key: 構文のキー(Track['この部分'])
      • string Function: 構文の関数名(ex.Interpolate)
      • Dictionary<string, object> Arguments: 構文の引数名。引数がキーであれば型はstring、引数が数値であれば型はdoubleで返します。

    詳しくは、MapData.csを参照してください

その他は今後作っていきます👍

Requirements

  • ANTLR4.Runtime(C#)
  • .Net Standard 2.0で実装しているため、特定のバージョン以降の.Netであれば利用できます。詳しくはこちらを参照して下さい。

Installation

NugetからBve5_Parsingをインストールするか、このプロジェクトをビルドしてdllを入手し、各自のプロジェクトにインポートしてください。

Usage for C#

ex. C#でMapFileの構文解析を行う場合.

using Bve5_Parsing.MapGrammar;

...
    string input; //String to be analyzed
    MapGrammarParser parser = new MapGrammarParser();

    var mapData = parser.Parse(input);

    Console.WriteLine(mapData.Version); //マップ構文のバージョン情報を表示
    foreach(var statement in mapData.Statements) {
      /* 各構文情報 */
      Console.WriteLine(statement.Distance); //構文の距離程
      Console.WriteLine(statement.Function); //構文の関数名
    }
...

構文が解析された場合、結果はMapDataクラスで返ってきます。例えば、ファイルヘッダのバージョン情報はMapData.Versionに格納されています。また、構文解析のエラーはMapGrammarParser.ParserErrorsに格納されています。MapGrammarParser.ParserErrorsではエラーの種別(警告かエラーか)やエラーとなった構文の位置、エラーメッセージが取得出来ます。独自のエラーメッセージを実装する場合は、ParserErrorListenerを継承したカスタムクラスを実装し、MapGrammarParser.ErrorListenerに指定して下さい。

Bve5_Parsing.slnに含まれているParseSampleAppプロジェクトからは、コンソール上でパーサの動作を確かめることができます。Bve5_Parsingの実装例として適宜利用して下さい。

Used Librarys

Bve5_Parsing is using the following library.

ANTLR v4

The BSD License (3-clause BSD License)

Copyright (c) 2012 Terence Parr and Sam Harwell

License

The MIT License (MIT)

Copyright(c) 2017-2019 aoisupersix

License.md

TechnicalCommentary

Bve5_Parsingの技術解説です。
TechnicalCommentary.md

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 754 6/9/2019
1.0.0 668 4/27/2019
0.8.1 635 4/13/2019
0.8.0 626 4/10/2019
0.7.0 597 2/25/2019
0.6.2 736 10/23/2018
0.6.1 722 10/23/2018
0.6.0 716 10/22/2018