Skip to content

Commit

Permalink
20400: Support [] and {} in Amalgam to represent lists and assocs res…
Browse files Browse the repository at this point in the history
…pectively, MINOR (#14)

- Added support for `[]` and `{}` characters in Amalgam for `(list)` and
`(assoc)` opcodes
- Updated snippets
- Support `(return)` opcode
- Make variable values more readable in variable list
  • Loading branch information
fulpm authored Jun 10, 2024
1 parent ba2743b commit d66ad95
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
6 changes: 4 additions & 2 deletions configuration/amalgam.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
},
"brackets": [
["(", ")"],
["[", "]"]

["[", "]"],
["{", "}"]
],
"autoClosingPairs": [
["[", "]"],
["(", ")"],
["{", "}"],
["\"", "\""]
],
"surroundingPairs": [
["[", "]"],
["(", ")"],
["{", "}"],
["\"", "\""]
]
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amalgam-lang",
"version": "1.2.1",
"version": "1.3.0",
"type": "commonjs",
"publisher": "howso",
"displayName": "Amalgam Language",
Expand Down
33 changes: 20 additions & 13 deletions snippets/amalgam.snippets.json

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/debugger/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class AmalgamRuntime extends EventEmitter {
private matchers = {
end: /\r\r(?:(?<thread>[xa-fA-F0-9]+) )?>$/m,
stackFrameComment: /^ {2}comment:src: (?<line>\d+) (?<column>\d+) (?<file>.+)$/gm,
stackFrameOpcode: /^ {2}opcode: (?<opcode>.+?)(?: ;src: (?<line>\d+) (?<column>\d+) (?<file>.+))?$/gm,
stackFrameOpcode: /^ {2}opcode: (?<opcode>.+?)(?: ?;src: (?<line>\d+) (?<column>\d+) (?<file>.+))?$/gm,
breakpointAction: /^(?<action>Added|Removed) breakpoint for (?:.+)?$/gm,
breakpointLine: /^ {2}(?<line>\d+)(?: (?<file>.+))?$/gm,
// Breakpoints and stack are matched via the header line and existing subsequent nested lines
Expand Down Expand Up @@ -396,7 +396,18 @@ export class AmalgamRuntime extends EventEmitter {

return await Promise.all(
values.map(async (v) => {
const { value } = await this.sendCommand("pp", signal, v);
let { value } = await this.sendCommand("pp", signal, v);
if (value != null) {
// Get rid of excess whitespace and newlines
value = value.split("\n").reduce((accumulator, line) => {
const trimmedLine = line.trim();
if (trimmedLine) {
if (accumulator) accumulator += " ";
accumulator += trimmedLine;
}
return accumulator;
}, "");
}
return new RuntimeVariable(v, value);
})
);
Expand Down
4 changes: 4 additions & 0 deletions src/language/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ export class AmalgamDocumentSymbolProvider implements vscode.DocumentSymbolProvi
return vscode.SymbolKind.Boolean;
} else if (/^\(list(?:\s.*)?$/i.test(text)) {
return vscode.SymbolKind.Array;
} else if (/^\[.*/i.test(text)) {
return vscode.SymbolKind.Array;
} else if (/^\(assoc(?:\s.*)?$/i.test(text)) {
return vscode.SymbolKind.Object;
} else if (/^{.*/i.test(text)) {
return vscode.SymbolKind.Object;
} else if (/^\(null\)(?:\s*;.*)?$/i.test(text)) {
return vscode.SymbolKind.Variable;
}
Expand Down
4 changes: 2 additions & 2 deletions syntaxes/amalgam.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"name": "variable.other.global.amalgam"
},
{
"match": "(?<=\\()(abs|accum|accum_entity_roots|accum_to_entities|acos|acosh|and|append|apply|args|asin|asinh|assign|assign_entity_roots|assign_to_entities|assoc|atan|atanh|call|call_container|call_entity|call_entity_get_changes|call_sandboxed|ceil|round|clone_entities|commonality|commonality_entities|compute_on_contained_entities|weighted_rand|compute_entity_group_kl_divergence|compute_entity_distance_contributions|compute_entity_kl_divergences|compute_entity_convictions|concat|conclude|contained_entities|contains_entity|contains_index|contains_label|contains_value|cos|cosh|create_entities|declare|dot_product|deep_set_entity_rand_seed|remove|keep|destroy_entities|difference|difference_entities|direct_assign_to_entities|direct_retrieve_from_entity|edit_distance|edit_distance_entities|entropy|erf|exp|explode|first|flatten_entity|floor|format|generalized_distance|get|get_all_labels|get_comments|get_concurrency|get_defaults|get_entity_comments|get_entity_rand_seed|get_entity_root_permission|get_labels|get_rand_seed|get_type|get_type_string|get_value|if|indices|intersect|intersect_entities|last|let|lgamma|load|load_entity|load_persistent_entity|log|max|min|mix|mix_entities|mix_labels|mod|move_entities|mutate|mutate_entity|not|or|parallel|parse|pow|crypto_sign|crypto_sign_verify|encrypt|decrypt|print|query_among|query_not_among|query_between|query_count|query_equals|query_exists|query_greater_or_equal_to|query_in_entity_list|query_min_difference|query_max_difference|query_value_masses|query_mode|query_median|query_sum|query_less_or_equal_to|query_max|query_min|query_nearest_distance|query_nearest_generalized_distance|query_not_between|query_not_equals|query_not_exists|query_not_in_entity_list|query_sample|query_weighted_sample|query_select|query_within_distance|query_within_generalized_distance|query_generalized_mean|rand|range|retrieve|retrieve_entity_root|retrieve_from_entity|reverse|seq|set|set_comments|set_concurrency|set_entity_rand_seed|set_entity_root_permission|set_labels|set_rand_seed|set_type|set_value|sin|sinh|size|sqrt|split|stack|store|store_entity|substr|system|system_time|tail|tan|tanh|tgamma|total_entity_size|total_size|trunc|union|union_entities|unparse|unzip|values|associate|while|xor|zip_labels|filter|list|map|reduce|replace|rewrite|sort|weave|zip|lambda|null|target|\\+|\\-|\\*|\\/|=|\\<=|\\>=|\\!=|~|\\!~| \\S+)(?=\\s+)",
"match": "(?<=\\()(abs|accum|accum_entity_roots|accum_to_entities|acos|acosh|and|append|apply|args|asin|asinh|assign|assign_entity_roots|assign_to_entities|assoc|atan|atanh|call|call_container|call_entity|call_entity_get_changes|call_sandboxed|ceil|round|clone_entities|commonality|commonality_entities|compute_on_contained_entities|weighted_rand|compute_entity_group_kl_divergence|compute_entity_distance_contributions|compute_entity_kl_divergences|compute_entity_convictions|concat|conclude|contained_entities|contains_entity|contains_index|contains_label|contains_value|cos|cosh|create_entities|declare|dot_product|deep_set_entity_rand_seed|remove|keep|destroy_entities|difference|difference_entities|direct_assign_to_entities|direct_retrieve_from_entity|edit_distance|edit_distance_entities|entropy|erf|exp|explode|first|flatten_entity|floor|format|generalized_distance|get|get_all_labels|get_comments|get_concurrency|get_defaults|get_entity_comments|get_entity_rand_seed|get_entity_root_permission|get_labels|get_rand_seed|get_type|get_type_string|get_value|if|indices|intersect|intersect_entities|last|let|lgamma|load|load_entity|load_persistent_entity|log|max|min|mix|mix_entities|mix_labels|mod|move_entities|mutate|mutate_entity|not|or|parallel|parse|pow|crypto_sign|crypto_sign_verify|encrypt|decrypt|print|query_among|query_not_among|query_between|query_count|query_equals|query_exists|query_greater_or_equal_to|query_in_entity_list|query_min_difference|query_max_difference|query_value_masses|query_mode|query_median|query_sum|query_less_or_equal_to|query_max|query_min|query_nearest_distance|query_nearest_generalized_distance|query_not_between|query_not_equals|query_not_exists|query_not_in_entity_list|query_sample|query_weighted_sample|query_select|query_within_distance|query_within_generalized_distance|query_generalized_mean|rand|range|retrieve|retrieve_entity_root|retrieve_from_entity|return|reverse|seq|set|set_comments|set_concurrency|set_entity_rand_seed|set_entity_root_permission|set_labels|set_rand_seed|set_type|set_value|sin|sinh|size|sqrt|split|stack|store|store_entity|substr|system|system_time|tail|tan|tanh|tgamma|total_entity_size|total_size|trunc|union|union_entities|unparse|unzip|values|associate|while|xor|zip_labels|filter|list|map|reduce|replace|rewrite|sort|weave|zip|lambda|null|target|\\+|\\-|\\*|\\/|=|\\<=|\\>=|\\!=|~|\\!~| \\S+)(?=\\s+)",
"name": "keyword.control.amalgam"
},
{
"match": "(\\(assoc\\)|\\(list\\)|\\(conclude\\)|\\(system_time\\)|\\(target\\)|\\(stack\\)|\\(opcode_stack\\)|\\(args\\)|\\(contained_entities\\)|\\(retrieve_entity_root\\))",
"match": "(\\(assoc\\)|\\(list\\)|\\(conclude\\)|\\(return\\)|\\(system_time\\)|\\(target\\)|\\(stack\\)|\\(opcode_stack\\)|\\(args\\)|\\(contained_entities\\)|\\(retrieve_entity_root\\))",
"name": "keyword.control.amalgam"
},
{
Expand Down

0 comments on commit d66ad95

Please sign in to comment.