Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 37 more #43

Merged
merged 3 commits into from
Dec 6, 2024
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
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
"environment": [],
"console": "internalConsole",
},
{
"name": "Debug Parser Perf (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/debug/parser-perf.exe",
"args": [
"${workspaceFolder}/eohippus-vscode/test_folder/main.pony"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "internalConsole",
},
{
"name": "Debug CLI (Windows)",
"type": "cppvsdbg",
Expand Down
8 changes: 4 additions & 4 deletions corral.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
],
"deps": [
{
"locator": "github.com/ponylang/appdirs.git",
"version": "0.1.5"
"locator": "github.com/chalcolith/kiuatan.git",
"version": "1.5.5"
},
{
"locator": "github.com/chalcolith/kiuatan.git",
"version": "1.5.2"
"locator": "github.com/ponylang/appdirs.git",
"version": "0.1.5"
},
{
"locator": "github.com/ponylang/logger.git",
Expand Down
147 changes: 0 additions & 147 deletions eohippus-vscode/test_folder/builtin_test/ini.pony

This file was deleted.

70 changes: 52 additions & 18 deletions eohippus/ast/exp_match.pony
Original file line number Diff line number Diff line change
Expand Up @@ -73,64 +73,98 @@ primitive ParseExpMatch
end
ExpMatch(expression, cases, else_block)

class val MatchCase is NodeData
"""A case in a `match` expression."""
class val MatchPattern is NodeData
let pattern: NodeWith[Expression]
let condition: (NodeWith[Expression] | None)
let body: NodeWith[Expression]

new val create(
pattern': NodeWith[Expression],
condition': (NodeWith[Expression] | None),
body': NodeWith[Expression])
condition': (NodeWith[Expression] | None))
=>
pattern = pattern'
condition = condition'
body = body'

fun name(): String => "MatchCase"
fun name(): String => "MatchPattern"

fun val clone(updates: ChildUpdateMap): NodeData =>
MatchCase(
MatchPattern(
_map_with[Expression](pattern, updates),
_map_or_none[Expression](condition, updates),
_map_with[Expression](body, updates))
_map_or_none[Expression](condition, updates))

fun add_json_props(node: Node box, props: Array[(String, json.Item)]) =>
props.push(("pattern", node.child_ref(pattern)))
match condition
| let condition': NodeWith[Expression] =>
props.push(("condition", node.child_ref(condition')))
end
props.push(("body", node.child_ref(body)))

primitive ParseMatchCase
fun apply(obj: json.Object, children: NodeSeq): (MatchCase | String) =>
primitive ParseMatchPattern
fun apply(obj: json.Object, children: NodeSeq): (MatchPattern | String) =>
let pattern =
match ParseNode._get_child_with[Expression](
obj,
children,
"pattern",
"MatchCase.pattern must be an Expression")
"MatchPattern.pattern must be an Expression")
| let node: NodeWith[Expression] =>
node
| let err: String =>
return err
else
return "MatchCase.pattern must be an Expression"
return "MatchPattern.pattern must be an Expression"
end
let condition =
match ParseNode._get_child_with[Expression](
obj,
children,
"condition",
"MatchCase.condition must be an Expression",
false)
"MatchPattern.condition must be an Expression")
| let node: NodeWith[Expression] =>
node
| let err: String =>
return err
end
MatchPattern(pattern, condition)

class val MatchCase is NodeData
"""A case in a `match` expression."""
let patterns: NodeSeqWith[MatchPattern]
let body: NodeWith[Expression]

new val create(
patterns': NodeSeqWith[MatchPattern],
body': NodeWith[Expression])
=>
patterns = patterns'
body = body'

fun name(): String => "MatchCase"

fun val clone(updates: ChildUpdateMap): NodeData =>
MatchCase(
_map[MatchPattern](patterns, updates),
_map_with[Expression](body, updates))

fun add_json_props(node: Node box, props: Array[(String, json.Item)]) =>
if patterns.size() > 0 then
props.push(("patterns", node.child_refs(patterns)))
end
props.push(("body", node.child_ref(body)))

primitive ParseMatchCase
fun apply(obj: json.Object, children: NodeSeq): (MatchCase | String) =>
let patterns =
match ParseNode._get_seq_with[MatchPattern](
obj,
children,
"patterns",
"MatchCase.patterns must refer to MatchCasePatterns",
false)
| let seq: NodeSeqWith[MatchPattern] =>
seq
| let err: String =>
return err
end
let body =
match ParseNode._get_child_with[Expression](
obj,
Expand All @@ -144,4 +178,4 @@ primitive ParseMatchCase
else
return "MatchCase.body must be an Expression"
end
MatchCase(pattern, condition, body)
MatchCase(patterns, body)
2 changes: 2 additions & 0 deletions eohippus/ast/parse_node.pony
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ primitive ParseNode
ParseNode~_ctor[Expression](ParseExpLambda~apply(obj, children))
| "ExpMatch" =>
ParseNode~_ctor[Expression](ParseExpMatch~apply(obj, children))
| "MatchPattern" =>
ParseNode~_ctor[MatchPattern](ParseMatchPattern~apply(obj, children))
| "MatchCase" =>
ParseNode~_ctor[MatchCase](ParseMatchCase~apply(obj, children))
| "ExpObject" =>
Expand Down
22 changes: 18 additions & 4 deletions eohippus/parser/_exp_actions.pony
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,9 @@ primitive _ExpActions
_Build.info(d, r), c, ast.ExpMatch(exp', cases', else_block'))
(value, b)

fun tag _match_case(
fun tag _match_pattern(
pattern: Variable,
condition: Variable,
body: Variable,
d: Data,
r: Success,
c: ast.NodeSeq,
Expand All @@ -357,9 +356,24 @@ primitive _ExpActions
try
_Build.value_with[ast.Expression](b, pattern, r)?
else
return _Build.bind_error(d, r, c, b, "Expression/MatchCase/Pattern")
return _Build.bind_error(d, r, c, b, "Expression/MatchPattern/Pattern")
end
let condition' = _Build.value_with_or_none[ast.Expression](b, condition, r)

let value = ast.NodeWith[ast.MatchPattern](
_Build.info(d, r), c, ast.MatchPattern(pattern', condition'))
(value, b)

fun tag _match_case(
patterns: Variable,
body: Variable,
d: Data,
r: Success,
c: ast.NodeSeq,
b: Bindings)
: ((ast.Node | None), Bindings)
=>
let patterns' = _Build.values_with[ast.MatchPattern](b, patterns, r)
let body' =
try
_Build.value_with[ast.Expression](b, body, r)?
Expand All @@ -368,7 +382,7 @@ primitive _ExpActions
end

let value = ast.NodeWith[ast.MatchCase](
_Build.info(d, r), c, ast.MatchCase(pattern', condition', body'))
_Build.info(d, r), c, ast.MatchCase(patterns', body'))
(value, b)

fun tag _while(
Expand Down
Loading