Skip to content

Conversation

@takejohn
Copy link
Member

What

#859 から一部コミットをcherry-pickしてPRを新規作成しました。
#840 (comment) に基づいて、ラベル構文を追加します。

Why

Additional info (optional)

これまでに出た問題の解決策:

  • ブロックにラベルを付けて指定したブロックから脱出できるようにする #840 (comment)
    for 1 break + 1
    • 値を返せるif, match, evalからbreakするにはラベルが指定されている必要があるから、break文に値を指定するにはラベルも指定されている必要がある。そのため、ラベルが指定されずに値が指定されたbreak文は文法エラーとしている。
    • 次のようにラベルを付けたとき、
      #l: for 1 break #l + 1
      ループ文から値を返すことはできないため、「break corresponding to statement cannot include value」の文法エラーとなる。
  • ブロックにラベルを付けて指定したブロックから脱出できるようにする #840 (comment)
    do break while false break while false // (2)
    • 上と同様に、break文にラベルが指定されていないため、break文に値が指定されていないものとしてパースする。従来の挙動と同様に「Multiple statements cannot be placed on a single line.」の文法エラーとなる。
    • 次のようにラベルを付けたとき、
      #l: do break #l while false break while false
      break #lの後は、文の終わりでない場合にbreak文に指定された式としてパースされる。EOF, 改行, while, elif, else, ,, ;, }を文の終わりとしている。#l: do break #l while falseが文としてパースされるため、「Multiple statements cannot be placed on a single line.」の文法エラーとなる。
  • 制御構文の変更 #859 (comment)
    #label1: loop {
        break #label2: loop {break #label1 0}
    }
    • 「cannot omit label from break if expression is given」の文法エラーとなる。

@codecov-commenter
Copy link

codecov-commenter commented Dec 24, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 96.69118% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/interpreter/index.ts 90.90% 4 Missing ⚠️
src/parser/plugins/validate-keyword.ts 83.33% 4 Missing ⚠️
src/parser/syntaxes/statements.ts 98.48% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Files with missing lines Coverage Δ
src/interpreter/control.ts 92.06% <100.00%> (ø)
src/node.ts 85.71% <ø> (-12.66%) ⬇️
src/parser/plugins/validate-jump-statements.ts 100.00% <100.00%> (ø)
src/parser/scanner.ts 95.25% <100.00%> (+6.48%) ⬆️
src/parser/syntaxes/common.ts 96.74% <100.00%> (+7.21%) ⬆️
src/parser/syntaxes/expressions.ts 94.98% <100.00%> (+5.79%) ⬆️
src/parser/token.ts 100.00% <100.00%> (ø)
src/parser/syntaxes/statements.ts 97.53% <98.48%> (+4.27%) ⬆️
src/interpreter/index.ts 94.54% <90.90%> (+8.74%) ⬆️
src/parser/plugins/validate-keyword.ts 95.67% <83.33%> (+7.06%) ⬆️

... and 22 files with indirect coverage changes

@takejohn takejohn changed the title ラベル構文の追加 feat: ラベル構文の追加 Dec 25, 2024
takejohn and others added 2 commits December 31, 2024 15:11
Co-authored-by: FineArchs <133759614+FineArchs@users.noreply.github.com>
@takejohn takejohn merged commit c3d71b5 into aiscript-dev:master Jan 12, 2025
4 checks passed
@takejohn takejohn deleted the feat/loop-label_2 branch January 12, 2025 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants