Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Zr v1.0.0 Refactor #14

Open
Vorlias opened this issue Oct 12, 2020 · 16 comments
Open

Zr v1.0.0 Refactor #14

Vorlias opened this issue Oct 12, 2020 · 16 comments
Assignees
Labels
TODO todo
Milestone

Comments

@Vorlias
Copy link
Member

Vorlias commented Oct 12, 2020

At the moment the Parser for Zirconium is a bit of... a mess. Makes a lot of assumptions in places and isn't really easily extended.

Ideally would want to separate it into:

  • TextStream (to handle the string reading)
  • Lexer (to handle the tokenization + would be good for the syntax highlighter)
  • Parser (to handle the tokens -> nodes)
  • Validator? (to handle validation, possibly)
@Vorlias Vorlias added the TODO todo label Oct 12, 2020
@Vorlias Vorlias self-assigned this Oct 12, 2020
@Vorlias
Copy link
Member Author

Vorlias commented Oct 12, 2020

Looking at implementing also:

  • Arrays [a, b, ...]
  • ArrayIndexExpression $x.0 or $x[0]
  • Objects (possibly) { x: y, a: b, ... }
  • IndexExpression $x.y
  • For-In for i in $arr { ... } where $i would be the value of each item
  • If/Else if (cond) { ... } else { ... }
  • Options (cmd --option value and cmd(option: value) in strict.

@Vorlias Vorlias added this to the 1.0.0-beta milestone Oct 12, 2020
@Vorlias Vorlias pinned this issue Oct 12, 2020
@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Array Syntax:

[ item, item2, ... ]
# or
[ item item2 item3 ... ]

Commas are optional list separator items.

Can even nest arrays 👍

[ "Nested Array Example" [ "Oh yes :-)" ] ]

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Added explicit call mode

command hello 10 true
command("hello", 10, true)

The latter will (soon) allow doing

command(othercommand("Argument"))

Where othercommand returns a result to the first argument of command.

The other option would be something like

command $(othercommand argument)

Not sure if I would want the latter in this case. We'll see.

@Vorlias Vorlias changed the title Cleanup Zirconium parser code Zr v1.0.0 Refactor Oct 13, 2020
@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Can now access properties via $var.value, can go as deep as required - $x.y.z.

This does not work with InterpolatedString. $x.y.z - it will assume that it's the variable $x followed by the string ".y.z". There'll be a work-around for that in the form of {$x.y.z} (possibly) - although I don't think that's required in all honesty and just complicates things.

If that's required, you can always use

$playerName = $player.Name
echo "Hello, $playerName!"

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

ArrayIndexExpression added via $x.0 where 0 is the index.

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Implemented IfStatement

if <expr> {
    <body>
}

if <expr> {
    <body>
} else {
    <body>
}

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

ElseIf now a thing.

if <expr> {
    <body>
} else if <expr> {
    <body>
} else {
    <body>
}

Same structure as how TS does it. https://ts-ast-viewer.com/#code/MYewdgzgLgBAHjAvDKAnArgUwNwChcCWAZjABRwCUMA3vgL4yYA2EmMxZlN9jLbtMQTFx0gA

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Short-form if:

if $value: <expr>

syntactically equivalent to

if $value {
    <expr>
}

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Functions

function print($x) {
    echo $x
}

with parameter types:

function print($x: string) {
    echo $x
}

Eventually the type parsing will allow things like union types.

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Added ForIn

# Array or Object iteration
for $value in $array {
    # do stuff with $value
}

# Command result iteration
for $value in <command> {
    # do stuff with value, expects command returns array
}

Plan with the second one is to have inbuilts like select

@Vorlias
Copy link
Member Author

Vorlias commented Oct 13, 2020

Cleaned up block code handling - for-in also now supports inline block:

for $value in <expression>: <statement>

@Vorlias
Copy link
Member Author

Vorlias commented Oct 14, 2020

Multi-line support for:

arrays

$test = [
    "Hello"
    "There"
]

explicit calls

command(
    "Test",
    "Test2",
    [
        "Test Array Value",
    ]
)

@Vorlias
Copy link
Member Author

Vorlias commented Oct 14, 2020

#14 (comment)

Now supporting

command(innerCommand("Example"))

@Vorlias
Copy link
Member Author

Vorlias commented Oct 14, 2020

    for $value in example(
        1, 
        [
            "Test", 
            "Test2"
        ]
    ) {

    }

I've created a monster.

@Vorlias
Copy link
Member Author

Vorlias commented Oct 14, 2020

Support multiline for command call

command \
    "Hello, World!" \
    10 \
    true

which is the same as

command(
    "Hello, World!",
    10,
    true
)

@Vorlias
Copy link
Member Author

Vorlias commented Oct 14, 2020

Implemented ObjectLiteralExpression

$x = {
    a: 10,
    b: command,
    c: [
        "Hello there",
        10
    ]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TODO todo
Projects
None yet
Development

No branches or pull requests

1 participant