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

Grammar conflicts #4

Open
inafact opened this issue Jan 6, 2021 · 3 comments
Open

Grammar conflicts #4

inafact opened this issue Jan 6, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@inafact
Copy link
Member

inafact commented Jan 6, 2021

一部のP-Codeの文法とJavaScriptの正規表現のトークンが重複しているので、\ を入れないと展開・実行できない場合がある

@inafact inafact added enhancement New feature or request help wanted Extra attention is needed labels Jan 6, 2021
@hemokosa
Copy link
Member

hemokosa commented Jan 7, 2021

確かにそうですね。具体的には「^」と「*」でしょうか。「v」と「x」でも大丈夫なように、P-Codeの方を拡張するだとか?(エイリアス的に)

@inafact
Copy link
Member Author

inafact commented Jan 7, 2021

実は地味に結構ぶつかっていて、P-Code的にクリティカルなのは既に挙げてもらっている ^* 以外にも

  • [-+、(矩形波、加算減算。/[a-z]+/などの表現とぶつかる)
  • .*0.5などの演算。全ての文字を表すドットシンタックスとぶつかる)

などがあります。

https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Regular_Expressions

厳密にはまだありそうですが、randexp.js の使い方的に、JavaScriptでサポートしてる全ての文法をサポートしなくても良いかなとは思っています。
現状だと何だかんだで \ でエスケープするのが明示的に書き分けが出来て手っ取り早そうかなと。

エイリアス作ってしまうのもありかなとは思いますが、あとは、

  • 以前から話にでているようなP-Codeの文法自体を書き換えることができる仕組みを先に実装する
  • P-Codeにおけるコメント、行頭の # のような感じで、何かしらのプレフィックスなどを付けることで、正規表現の文法を優先するかP-Codeの文法を優先するかのモードを切り替えれるようにする

とかですかね。パッと思いつくものだと..

@hemokosa
Copy link
Member

hemokosa commented Jan 7, 2021

なるほど、確かに演算子や小数点もすべてアウトですね(汗)。となると、ここはへたにエイリアスでしのぐのではなく、稲福さんのいうように、
・エスケープする
・文法自体の書き換えができるようにする
の二本立てでいくのはよさそうですね。あと、モードも面白いアイデアですね!このあたり、考えること自体がけっこう楽しいかも:-P

@inafact inafact changed the title Ggrammer conflicts Grammar conflicts Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants