tdenniston / bish

Bish is a language that compiles to Bash. It's designed to give shell scripting a more comfortable and modern feel.
MIT License
1.48k stars 36 forks source link

Call the standard commands #23

Closed egorsmkv closed 9 years ago

egorsmkv commented 9 years ago

For example, the following code will not be translated:

var = "335f";
@($var =~ ^-?[0-9]+$);

Will be displayed parse error: Parsing error: Expected variable to be a symbol near character ')', line 5

How best to do these teams? Maybe they wrap in quotes `?

tdenniston commented 9 years ago

Hmm. I'll have to figure out a good way to handle that. After the regex line-end symbol '$', bish expects there to be a variable name. That's because interpolations in strings are currently handled by prefixing '$' as well. I will need to think on this one a bit.

egorsmkv commented 9 years ago

Yes, I also realized that there must be a variable.

Ok, I'll wait.

egorsmkv commented 9 years ago

@tdenniston Why not use these quotes `?

tdenniston commented 9 years ago

@eg0r This should work now, for example:

text = "335";
@([[ $text =~ ^[0-9]+\$ ]]);
assert(success());

Seems to work as expected.

egorsmkv commented 9 years ago

Wonderful commit. Now you can make functions for type checking:

def is_integer(v) {
    @([[ $v =~ ^[0-9]+\$ ]]);
    return success();
}

if (is_integer("100")) {
    println("Yes!");
} else {
    println("No!");
}

# => "Yes!"