Giter Club home page Giter Club logo

bve5_parsing's Introduction

Build Status All Contributors NuGet version MIT License

Bve5_Parsing

bve5PasingImage

BveTrainSim5構文の.NETパーサライブラリです。 入力された文字列やファイルを解析し、プログラム上で利用しやすい形式に変換します。 現在マップファイルとシナリオファイル構文に対応しています。

Supported Syntaxes

  • Scenario File

    • Bve5の全構文に対応
  • Map File

    • マップファイルのバージョン1.00から2.02に対応。
    • 数式や変数、Includeディレクティブにも対応しています。

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

Requirements

  • .Net Standard 2.0 or .Net framework 4.0

Installation

NugetでBve5_Parsingとしてパッケージを公開しています。

  • コマンドラインからインストールする場合

    nuget install Bve5_Parsing
    
  • VisualStudioからインストールする場合

    1. ツール > Nugetパッケージマネージャ > ソリューションのNugetパッケージの管理をクリック
    2. 参照タブでBve5_Parsingを検索
    3. インストールをクリック

Usage for C#

C#でマップファイルのパースを行う場合

using Bve5_Parsing.MapGrammar;
using Bve5_Parsing.MapGrammar.EvaluateData;
using System.Linq;

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

    // 文字列をマップ構文としてパースする
    MapData mapData = parser.Parse(input);
    // マップファイルへのファイルパスを指定してパースする
    MapData mapData2 = parser.ParseFromFile(@"PATH/TO/MAP/FILE");
    // Include構文の参照先を再帰的にパースする
    MapData mapDataWithInclude = parser.ParseFromFile(@"PATH/TO/MAP/FILE", MapGrammarParserOption.ParseIncludeSyntaxRecursively)
    // AST(抽象構文木)にパースする
    MapData ast = parser.ParseToAst(input, @"PATH/TO/FILE/PATH");

    // パースエラーの取得
    if (parser.ParseErrors.Any()) {
      // error handling
    }

    // 旧形式でステートメントのデータを取得する場合(通常は必要ありません)
    var syntaxData = mapData.Statements.Select(state => state.ToSyntaxData());

    mapData.Version //マップ構文のバージョン情報
    mapData.Encoding // マップ構文のエンコーディング指定
    foreach(var statement in mapData.Statements) {
      /* 各構文情報 */
      statement.Distance; //構文の距離程
      statement.FunctionName; //構文の関数名
    }
...

パース処理に成功した場合、結果は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.

The BSD License (3-clause BSD License)

Copyright (c) 2012 Terence Parr and Sam Harwell

The MIT License (MIT)

Copyright (c) 2017 hnx8

License

The MIT License (MIT)

Copyright(c) 2017-2019 aoisupersix

License.md

TechnicalCommentary

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

Contributors

Thanks goes to these wonderful people (emoji key):

Aoi Tanaka
Aoi Tanaka

💻
s520
s520

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

bve5_parsing's People

Contributors

allcontributors[bot] avatar aoisupersix avatar renovate-bot avatar s520 avatar tim-a-tanaka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bve5_parsing's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm tslint Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency b5g to v0.1.2
  • Update dependency linq to v3.2.4
  • Update dependency mustache to v4.2.0
  • Update dependency typescript to v3.9.10
  • Update xunit-dotnet monorepo (xunit, xunit.runner.visualstudio)
  • Update dependency @types/node to v20
  • Update dependency Microsoft.NET.Test.Sdk to v17
  • Update dependency linq to v4
  • Update dependency tslint to v6
  • Update dependency typescript to v5
  • 🔐 Create all rate-limited PRs at once 🔐

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
gen-old/package.json
  • fs 0.0.2
  • linq ^3.1.1
  • mustache ^4.0.0
  • strip-bom ^4.0.0
gen/package.json
  • b5g 0.0.3
  • fs 0.0.2
  • typescript ^3.5.3
  • @types/node 12.12.28
  • ts-node 8.6.2
  • tslint 5.20.1
  • tslint-config-airbnb 5.11.2
  • tsutils 3.17.1
nuget
Bve5_Parsing/Bve5_Parsing.csproj
  • System.Text.Encoding.CodePages 4.5.1
  • System.Dynamic.Runtime 4.3.0
  • Microsoft.CSharp 4.5.0
  • ReadJEnc 1.3.1.2
  • Antlr4.Runtime 4.6.6
  • Antlr4 4.6.6
Bve5_ParsingDoc/Bve5_ParsingDoc.csproj
  • docfx.console 2.49.0
Bve5_ParsingTests/Bve5_ParsingTests.csproj
  • dotnet-xunit 2.3.1
  • xunit.runner.visualstudio 2.4.1
  • xunit 2.4.1
  • Microsoft.NET.Test.Sdk 16.5.0

  • Check this box to trigger a request for Renovate to run again on this repository

Travis CIのテストが走らなくなってしまった

#82 をマージしたらテストが走らなくなってしまったので修正する

以下エラー:

Starting test execution, please wait...
Unable to find /home/travis/build/aoisupersix/Bve5_Parsing/Bve5_ParsingTests/bin/Debug/netcoreapp2.0/testhost.dll. Please publish your test project and retry.
Test run in progress.Test Run Aborted.

TODO: 例外処理におけるファイル名の取得

構文解析の結果、構文が正しくない場合はScriptExceptionを返すが、現時点では例外の中にファイル名が含まれていないので、どのファイルの例外か判別できない。

改善案

  • ScriptException内のinnerExceptionにファイル名を含む例外を入れておく
  • 独自の例外を追加する

参考

MapGrammar例外処理の追加

MapGrammarのパース処理に関する例外処理やエラーメッセージの追加。

取り敢えず現状の問題点↓

  • MapGrammarの第一ステートメントに予期しない構文が入力された場合、その後のステートメントがパースされない。
  • 数式の項に文字列が含まれていた際の演算で、'+'以外の演算子を利用していた場合に例外が発生する。
  • パーサのエラーメッセージが単純に分かりづらい。

TODO: Readme.mdの改善

もっとわかりやすいドキュメントにする。

追加予定

  • 構文解析の評価(戻り値)の詳細
  • ファイルの構造など
  • もっとそれらしい画像

ASTを構文ごとに分割する

#42 対応のため。
現在引数を辞書形で無理やりやっているところを、クラスのプロパティに改修する。
また、EvaluteするかASTをそのまま返すか、デベロッパーが選択できるようにする(これは #39 で対応)

VariableStoreはstaticじゃない

パースごとにVariableStoreのインスタンスを作る方が正しい気がする。
ついでにVariableStoreをパース間で引き継げるようにする。

細かい構文の修正

  • Legacy構文の引数名startがParserRuleContextとかぶってる
  • Legacy構文のASTノードを作る
  • Include構文でディレクトリの大文字小文字を無視できるようにする

ASTで保持する構文情報を増やす

現在マップ要素と関数しかないので、構文の種類が特定しづらい。

関数名にドットが入る関数(Track[].X.Interpolateみたいな)はSubElement:XとFunction:Interpolateに分解する

Includeディレクティブの対応

Includeディレクティブは、その構文位置に指定されたマップ構文ファイル(ヘッダを除く)を挿入する機能らしい。
つまり、Includeディレクティブの動作としては、

  1. 指定されたマップ構文ファイルを読み込み
  2. ファイルヘッダを削除
  3. Includeディレクティブを読み込んだマップ構文で置き換え
    ということになる。

これを実装するためには、

  1. デベロッパーがBve5_Parsingを利用する前にIncludeディレクティブを構文で置き換え
  2. Bve5_Parsingのパース前にIncludeディレクティブを構文で置き換え
    という2つの方法がいいかな。

デフォルトでは2のBve5_Parsing内で置き換えを行って、オプションとして置き換えを行わずにパース可能にする

ファイルヘッダーの定義変更

どうやら本家ソフトは

  • 空白(スペース)は文字間に必ず一つ
  • ファイルヘッダに空白は不可
  • 大文字小文字は無視でOK
    らしいのでそれ準拠に変更する

SecrityAlertの修正

b5gのbracesが原因。0.0.3で解決させたと思うのでパッケージを更新する

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.