Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions pdl-live-react/src/pdl_ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2917,9 +2917,8 @@ export interface Defs3 {
*
* Example:
* ```PDL
* - def: N
* lang: python
* code: |
* lang: python
* code: |
* import random
* # (In PDL, set `result` to the output you wish for your code block.)
* result = random.randint(1, 20)
Expand Down Expand Up @@ -3201,11 +3200,12 @@ export interface Defs7 {
*
* Example:
* ```PDL
* - if: ${ eval == 'no' }
* then:
* text:
* - read:
* message: "Why not?\n"
* defs:
* answer:
* read:
* message: "Enter a number? "
* if: ${ (answer | int) == 42 }
* then: You won!
* ```
*/
export interface IfBlock {
Expand Down Expand Up @@ -3270,6 +3270,23 @@ export interface Defs8 {
}
/**
* Match control structure.
*
* Example:
* ```PDL
* defs:
* answer:
* read:
* message: "Enter a number? "
* match: ${ (answer | int) }
* with:
* - case: 42
* then: You won!
* - case:
* any:
* def: x
* if: ${ x > 42 }
* then: Too high
* - then: Too low
*/
export interface MatchBlock {
description?: Description9
Expand Down Expand Up @@ -3706,6 +3723,18 @@ export interface Defs15 {
}
/**
* Read from a file or standard input.
*
* Example. Read from the standard input with a prompt starting with `> `.
* ```PDL
* read:
* message: "> "
* ```
*
* Example. Read the file `./data.yaml` in the same directory of the PDL file containing the block and parse it into YAML.
* ```PDL
* read: ./data.yaml
* parser: yaml
* ```
*/
export interface ReadBlock {
description?: Description16
Expand Down
8 changes: 4 additions & 4 deletions src/pdl/pdl-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@
},
"CodeBlock": {
"additionalProperties": false,
"description": "Execute a piece of code.\n\nExample:\n```PDL\n- def: N\n lang: python\n code: |\n import random\n # (In PDL, set `result` to the output you wish for your code block.)\n result = random.randint(1, 20)\n```",
"description": "Execute a piece of code.\n\nExample:\n```PDL\nlang: python\ncode: |\n import random\n # (In PDL, set `result` to the output you wish for your code block.)\n result = random.randint(1, 20)\n```",
"properties": {
"description": {
"anyOf": [
Expand Down Expand Up @@ -4318,7 +4318,7 @@
},
"IfBlock": {
"additionalProperties": false,
"description": "Conditional control structure.\n\nExample:\n```PDL\n- if: ${ eval == 'no' }\n then:\n text:\n - read:\n message: \"Why not?\\n\"\n```",
"description": "Conditional control structure.\n\nExample:\n```PDL\ndefs:\n answer:\n read:\n message: \"Enter a number? \"\nif: ${ (answer | int) == 42 }\nthen: You won!\n```",
"properties": {
"description": {
"anyOf": [
Expand Down Expand Up @@ -7186,7 +7186,7 @@
},
"MatchBlock": {
"additionalProperties": false,
"description": "Match control structure.",
"description": "Match control structure.\n\nExample:\n```PDL\ndefs:\n answer:\n read:\n message: \"Enter a number? \"\nmatch: ${ (answer | int) }\nwith:\n- case: 42\n then: You won!\n- case:\n any:\n def: x\n if: ${ x > 42 }\n then: Too high\n- then: Too low",
"properties": {
"description": {
"anyOf": [
Expand Down Expand Up @@ -9208,7 +9208,7 @@
},
"ReadBlock": {
"additionalProperties": false,
"description": "Read from a file or standard input.",
"description": "Read from a file or standard input.\n\nExample. Read from the standard input with a prompt starting with `> `.\n```PDL\nread:\nmessage: \"> \"\n```\n\nExample. Read the file `./data.yaml` in the same directory of the PDL file containing the block and parse it into YAML.\n```PDL\nread: ./data.yaml\nparser: yaml\n```",
"properties": {
"description": {
"anyOf": [
Expand Down
51 changes: 41 additions & 10 deletions src/pdl/pdl_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ class CodeBlock(BaseCodeBlock):

Example:
```PDL
- def: N
lang: python
code: |
lang: python
code: |
import random
# (In PDL, set `result` to the output you wish for your code block.)
result = random.randint(1, 20)
Expand Down Expand Up @@ -600,11 +599,12 @@ class IfBlock(StructuredBlock):

Example:
```PDL
- if: ${ eval == 'no' }
then:
text:
- read:
message: "Why not?\\n"
defs:
answer:
read:
message: "Enter a number? "
if: ${ (answer | int) == 42 }
then: You won!
```
"""

Expand Down Expand Up @@ -642,7 +642,25 @@ class MatchCase(BaseModel):


class MatchBlock(StructuredBlock):
"""Match control structure."""
"""Match control structure.

Example:
```PDL
defs:
answer:
read:
message: "Enter a number? "
match: ${ (answer | int) }
with:
- case: 42
then: You won!
- case:
any:
def: x
if: ${ x > 42 }
then: Too high
- then: Too low
"""

kind: Literal[BlockKind.MATCH] = BlockKind.MATCH
match_: ExpressionType[Any] = Field(alias="match")
Expand Down Expand Up @@ -735,7 +753,20 @@ class RepeatBlock(StructuredBlock):


class ReadBlock(LeafBlock):
"""Read from a file or standard input."""
"""Read from a file or standard input.

Example. Read from the standard input with a prompt starting with `> `.
```PDL
read:
message: "> "
```

Example. Read the file `./data.yaml` in the same directory of the PDL file containing the block and parse it into YAML.
```PDL
read: ./data.yaml
parser: yaml
```
"""

kind: Literal[BlockKind.READ] = BlockKind.READ
read: ExpressionType[str] | None
Expand Down