Skip to content

Commit

Permalink
Allow symbols that begin with keywords. (#236)
Browse files Browse the repository at this point in the history
* Fix opcode bug.

* Remove unnecesary code from test.
  • Loading branch information
emilyaherbert authored Sep 21, 2021
1 parent 20401be commit 6a3c580
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 5 deletions.
14 changes: 9 additions & 5 deletions core_lang/src/hll.pest
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn_returns = {"->"}
path_separator = {"::"}
include_keyword = {"dep"}
abi_keyword = {"abi"}
ref_keyword = {"ref "}
deref_keyword = {"deref "}
true_keyword = {"true"}
false_keyword = {"false"}

// top level
program = {SOI ~ (library|contract|script|predicate)? ~ EOI}
Expand All @@ -34,7 +38,7 @@ file_path = { ident ~ ("/" ~ ident)* }
include_statement = { include_keyword ~ file_path ~ alias? ~ ";"}
alias = { "as" ~ ident }
// expressions
expr_inner = _{literal_value|if_exp|asm_expression|code_block|func_app|struct_expression|method_exp|struct_field_access|delineated_path|unary_op_expr|var_exp|array_exp|abi_cast|parenthesized_expression|match_expression|unit}
expr_inner = _{unary_op_expr|asm_expression|match_expression|abi_cast|if_exp|code_block|func_app|literal_value|struct_expression|method_exp|struct_field_access|delineated_path|var_exp|array_exp|parenthesized_expression|unit}
parenthesized_expression = {"(" ~ expr ~ ")"}
unary_op_expr = { unary_op ~ expr_inner }
// // op exps built in to expr to prevent left recursion
Expand Down Expand Up @@ -64,12 +68,12 @@ abi_name = {ident}
if_exp = {"if" ~ expr ~ code_block ~ ("else" ~ (code_block|if_exp))?}

op = {"+"|"-"|"/"|"*"|"=="|"!="|"<="|">="|"||"|"|"|"&&"|"&"|"^"|"%"|"<"|">"}
unary_op = {"!"|"ref"|"deref"}
unary_op = {"!"|ref_keyword|deref_keyword}

// // note that decimal/float exprs might be removed since vm doesn't support them
literal_value = {integer|byte|string|boolean}

boolean = {"true"|"false"}
boolean = {true_keyword|false_keyword}
string = ${"\"" ~ char* ~ "\""}
integer = {(u8_integer|u16_integer|u32_integer|u64_integer)}
basic_integer = @{!("0b"|"0x") ~ ASCII_DIGIT ~ (ASCII_DIGIT|"_")*}
Expand Down Expand Up @@ -176,6 +180,6 @@ char = @{
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
unit = {"(" ~ ")"}
ident = @{(!(reserved_words) ~ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC|"_")*)}
reserved_words = {abi_keyword|while_keyword|struct_keyword|enum_keyword|match_keyword|use_keyword|var_decl_keyword|fn_decl_keyword|trait_decl_keyword|return_keyword}
ident = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC|"_")* }
reserved_words = @{(true_keyword|false_keyword|asm_keyword|ref_keyword|deref_keyword|abi_keyword|while_keyword|struct_keyword|enum_keyword|match_keyword|use_keyword|var_decl_keyword|fn_decl_keyword|trait_decl_keyword|return_keyword|include_keyword) ~ !(ASCII_ALPHANUMERIC|"_")}

1 change: 1 addition & 0 deletions test/src/e2e_vm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn run() {
("main_returns_unit", ProgramState::Return(0)),
("unary_not_basic", ProgramState::Return(1)), // 1 == true
("unary_not_basic_2", ProgramState::Return(1)), // 1 == true
("fix_opcode_bug", ProgramState::Return(30)),
(
"retd_b256",
ProgramState::ReturnData(Bytes32::from([
Expand Down
11 changes: 11 additions & 0 deletions test/src/e2e_vm_tests/test_programs/fix_opcode_bug/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
author = "Alexander Hansen <[email protected]>"
license = "MIT"
name = "asm_expr_basic"
entry = "main.sw"


[dependencies]
std = { path = "../../../../../stdlib" }


155 changes: 155 additions & 0 deletions test/src/e2e_vm_tests/test_programs/fix_opcode_bug/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
script;

fn abi_x() -> u64 {
return 1;
}

fn enum_x() -> u64 {
return 1;
}

fn fn_x() -> u64 {
return 1;
}

fn let_x() -> u64 {
return 1;
}

fn match_x() -> u64 {
return 1;
}

fn return_x() -> u64 {
return 1;
}

fn struct_x() -> u64 {
return 1;
}

fn trait_x() -> u64 {
return 1;
}

fn use_x() -> u64 {
return 1;
}

fn while_x() -> u64 {
return 1;
}

fn asm_x() -> u64 {
return 1;
}

fn as_x() -> u64 {
return 1;
}

fn contract_x() -> u64 {
return 1;
}

fn dep_x() -> u64 {
return 1;
}

fn deref_x() -> u64 {
return 1;
}

fn false_x() -> u64 {
return 1;
}

fn for_x() -> u64 {
return 1;
}

fn i64_x() -> u64 {
return 1;
}

fn impl_x() -> u64 {
return 1;
}

fn library_x() -> u64 {
return 1;
}

fn mut_x() -> u64 {
return 1;
}

fn predicate_x() -> u64 {
return 1;
}

fn pub_x() -> u64 {
return 1;
}

fn ref_x() -> u64 {
return 1;
}

fn script_x() -> u64 {
return 1;
}

fn self_x() -> u64 {
return 1;
}

fn str_x() -> u64 {
return 1;
}

fn true_x() -> u64 {
return 1;
}

fn u64_x() -> u64 {
return 1;
}

fn where_x() -> u64 {
return 1;
}

fn main() -> u32 {
let where_y = abi_x()
+ enum_x()
+ fn_x()
+ let_x()
+ match_x()
+ return_x()
+ struct_x()
+ trait_x()
+ use_x()
+ while_x()
+ asm_x()
+ as_x()
+ contract_x()
+ dep_x()
+ deref_x()
+ false_x()
+ for_x()
+ i64_x()
+ impl_x()
+ library_x()
+ mut_x()
+ predicate_x()
+ pub_x()
+ ref_x()
+ script_x()
+ self_x()
+ str_x()
+ true_x()
+ u64_x()
+ where_x();
return where_y;
}

0 comments on commit 6a3c580

Please sign in to comment.