aiscript icon indicating copy to clipboard operation
aiscript copied to clipboard

ブロックをカッコではなくインデントで表現するようにしたい

Open syuilo opened this issue 5 years ago • 19 comments

オブジェクトリテラルとカッコが一緒で紛らわしいし、その方が簡潔 ただ破壊的変更になる

syuilo avatar Jun 28 '20 01:06 syuilo

やりたいけどパーサが面倒そう

syuilo avatar Jul 31 '20 14:07 syuilo

やっぱ曖昧性が生じそう

syuilo avatar Aug 01 '20 09:08 syuilo

やっぱやりたい

syuilo avatar Feb 27 '21 01:02 syuilo

構文例

@fn(x)
  ? (x = 42) << yes

  ? (x = 21)
    no
  .
    yes
for #i, 100
  <: ? ((i % 15) = 0) "FizzBuzz"
    .? ((i % 3) = 0) "Fizz"
    .? ((i % 5) = 0) "Buzz"
    . i
#foo = do
	#a = 1
	#b = 2
	(a + b)

<: foo // 3
@foo(x)
  ? (x = 42)
    << "foo"
  "bar"

syuilo avatar Mar 13 '21 15:03 syuilo

YAMLのパーサとか参考になりそう https://github.com/nodeca/js-yaml/blob/master/lib/loader.js

syuilo avatar May 30 '21 03:05 syuilo

YAMLのPEGらしきものあった https://github.com/cierelabs/yaml_spirit/blob/master/doc/specs/yaml-peg.txt

syuilo avatar Jun 13 '21 06:06 syuilo

メモ

The off-side rule can be implemented in the lexical analysis phase, as in Python, where increasing the indenting results in the lexer outputting an INDENT token, and decreasing the indenting results in the lexer outputting a DEDENT token.[5] These tokens correspond to the opening brace { and closing brace } in languages that use braces for blocks, and means that the phrase grammar does not depend on whether braces or indentation are used. This requires that the lexer hold state, namely the current indent level, and thus can detect changes in indentation when this changes, and thus the lexical grammar is not context-free: INDENT and DEDENT depend on the contextual information of the prior indent level.

https://en.wikipedia.org/wiki/Off-side_rule

syuilo avatar Jun 13 '21 06:06 syuilo

👀 https://gist.github.com/biogeo/586d660a74d1f59d667763a1cdd7309b

syuilo avatar Jun 13 '21 07:06 syuilo

コロン要るかなあ

syuilo avatar Jun 13 '21 10:06 syuilo

コロン無しにするか

syuilo avatar Jun 13 '21 10:06 syuilo

オフサイドルールだと関数に複数のコールバック関数渡す時とか曖昧性生じそう

syuilo avatar Jun 13 '21 11:06 syuilo

こう?

@max3(x, y, z)
  @max(a, b)
    ? (a > b)
      a
    .
      b
  max(max(x, y), z)
<: max3(1, 2, 3)

marihachi avatar Jul 23 '21 08:07 marihachi

だね

syuilo avatar Jul 23 '21 08:07 syuilo

無名関数が書けなさそう?

marihachi avatar Jul 23 '21 08:07 marihachi

Arr:filter(arr, @(item)
  Str:incl(item, "ai")
)

でいける

syuilo avatar Jul 23 '21 08:07 syuilo

これだと、インデント数を見て後から構造化するって方法が取れないな

marihachi avatar Jul 23 '21 09:07 marihachi

字句解析でブロックの開始終了を検出するならPEGじゃないほうが良いかも

marihachi avatar Jul 23 '21 09:07 marihachi

オフサイドルールだと関数に複数のコールバック関数渡す時とか曖昧性生じそう

Pythonとかはこういうのどう対処するんだろう

syuilo avatar Dec 24 '21 13:12 syuilo

これ今更だけど実装も仕様もとんでもなく複雑になるのであまりやりたくないかなあ

marihachi avatar Dec 29 '21 09:12 marihachi

この案まだ生きてる?

marihachi avatar Oct 14 '23 10:10 marihachi

うーむ

syuilo avatar Oct 14 '23 10:10 syuilo

いろいろとめんどくさそう(構文解析的にも変更の影響の大きさ的にも)だからやめるか やるにしてもいっそ別言語かaltAiScriptみたいな感じにするとか

syuilo avatar Oct 14 '23 10:10 syuilo

インデントで意味変えるとかは、構文もその前提で設計したいところかも

marihachi avatar Oct 14 '23 10:10 marihachi

閉じます

marihachi avatar Oct 14 '23 10:10 marihachi