Skip to content

Commit

Permalink
Update to the latest kiuatan version
Browse files Browse the repository at this point in the history
  • Loading branch information
chalcolith committed Jan 8, 2025
1 parent f0146f6 commit 517a3b5
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 511 deletions.
2 changes: 1 addition & 1 deletion corral.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"deps": [
{
"locator": "github.com/chalcolith/kiuatan.git",
"version": "1.5.5"
"version": "1.6.0"
},
{
"locator": "github.com/ponylang/appdirs.git",
Expand Down
67 changes: 43 additions & 24 deletions eohippus/analyzer/eohippus_analyzer.pony
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ actor EohippusAnalyzer is Analyzer

let _context: AnalyzerContext
let _notify: AnalyzerNotify
let _include_libs: Bool

let _lint_configs: Map[String, linter.Config val] = _lint_configs.create()

Expand All @@ -41,11 +42,13 @@ actor EohippusAnalyzer is Analyzer
new create(
log: Logger[String],
context: AnalyzerContext,
notify: AnalyzerNotify)
notify: AnalyzerNotify,
include_libs: Bool = true)
=>
_log = log
_context = context
_notify = notify
_include_libs = include_libs

fun ref _get_next_task_id(): USize =>
let result = _analysis_task_id
Expand Down Expand Up @@ -80,23 +83,25 @@ actor EohippusAnalyzer is Analyzer

_analyze_dir(task_id, true, workspace_path, workspace_cache, _schedule(0))

// var schedule = _schedule(250)
// for pony_path in _context.pony_path_dirs.values() do
// try
// let info = FileInfo(pony_path)?
// if info.directory then
// task_id = _get_next_task_id()
// _analyze_dir(task_id, false, pony_path, global_cache, schedule)
// end
// end
// end
if _include_libs then
var schedule = _schedule(250)
for pony_path in _context.pony_path_dirs.values() do
try
let info = FileInfo(pony_path)?
if info.directory then
task_id = _get_next_task_id()
_analyze_dir(task_id, false, pony_path, global_cache, schedule)
end
end
end

// schedule = _schedule(500)
// match _context.pony_packages_path
// | let pony_packages_path: FilePath =>
// task_id = _get_next_task_id()
// _analyze_dir(task_id, false, pony_packages_path, global_cache, schedule)
// end
schedule = _schedule(500)
match _context.pony_packages_path
| let pony_packages_path: FilePath =>
task_id = _get_next_task_id()
_analyze_dir(task_id, false, pony_packages_path, global_cache, schedule)
end
end

be _analyze_dir(
task_id: USize,
Expand Down Expand Up @@ -375,11 +380,25 @@ actor EohippusAnalyzer is Analyzer

fun ref _enqueue_src_item(
src_item: SrcItem,
new_state: (SrcItemState | None) = None)
new_state: (SrcItemState | None) = None,
auto_transition: Bool = false)
=>
match new_state
| let new_state': SrcItemState =>
src_item.set_state(new_state')
else
if auto_transition then
let new_state' =
match src_item.get_state()
| AnalysisStart => AnalysisParse
| AnalysisParse => AnalysisScope
| AnalysisScope => AnalysisLint
| AnalysisLint => AnalysisUpToDate
| AnalysisUpToDate => AnalysisUpToDate
| AnalysisError => AnalysisError
end
src_item.set_state(new_state')
end
end

_src_item_queue.push(src_item)
Expand Down Expand Up @@ -630,9 +649,9 @@ actor EohippusAnalyzer is Analyzer
src_file.canonical_path,
src_file.syntax_tree,
None,
_collect_errors(_parse_errors),
_collect_errors(_lint_errors),
_collect_errors(_analyze_errors))
_collect_errors(_parse_errors, src_file.canonical_path),
_collect_errors(_lint_errors, src_file.canonical_path),
_collect_errors(_analyze_errors, src_file.canonical_path))

// try to free up some memory
if not src_file.is_open then
Expand Down Expand Up @@ -953,7 +972,7 @@ actor EohippusAnalyzer is Analyzer
src_file.task_id.string() + ": " + src_file.canonical_path.path +
" => Scoping")

_enqueue_src_item(src_file, AnalysisScope)
_enqueue_src_item(src_file where auto_transition = true)
else
_log(Error) and _log.log(
task_id.string() + ": parsed untracked source file " +
Expand Down Expand Up @@ -1228,7 +1247,7 @@ actor EohippusAnalyzer is Analyzer
_log(Fine) and _log.log(
task_id.string() + ": " + canonical_path.path + " => Linting")

_enqueue_src_item(src_file, AnalysisLint)
_enqueue_src_item(src_file where auto_transition = true)
else
_log(Error) and _log.log(
task_id.string() + ": scoped unknown file " + canonical_path.path)
Expand Down Expand Up @@ -1486,7 +1505,7 @@ actor EohippusAnalyzer is Analyzer
_log(Fine) and _log.log(
src_file.task_id.string() + ": " + src_file.canonical_path.path +
" => UpToDate")
_enqueue_src_item(src_file, AnalysisUpToDate)
_enqueue_src_item(src_file where auto_transition = true)
else
_log(Error) and _log.log(
task_id.string() + ": linted unknown file " + canonical_path.path)
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/node_with.pony
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,5 @@ class val NodeWith[D: NodeData val] is Node
fun string(): String iso^ =>
this.get_json().string()

type NodeSeqWith[D: NodeData val] is ReadSeq[NodeWith[D]] val
type NodeSeqWith[D: NodeData val] is Array[NodeWith[D]] val
"""A sequence of AST nodes with a given node data type."""
101 changes: 40 additions & 61 deletions eohippus/parser/_build.pony
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,66 @@ primitive _Build
"""Returns source info from a parse result."""
ast.SrcInfo(data.locator, success.start, success.next)

fun result(b: Bindings, v: Variable, r: Success): Success ? =>
fun result(b: Bindings, v: Variable): Success ? =>
"""
Returns the "result", if any, bound to a variable in the scope of the
given result.
Returns the successful "result" bound to a variable.
"""
b.result(v, r)?
b(v)?.success

fun value(b: Bindings, v: Variable, r: Success): ast.Node ? =>
fun value(b: Bindings, v: Variable): ast.Node ? =>
"""
Returns the first computed "value", if any, bound to a variable in the
Returns the computed "value" bound to a variable in the
scope of the given result.
"""
b.values(v, r)?(0)?
b(v)?.values(0)?

fun value_or_none(b: Bindings, v: Variable, r: Success): (ast.Node | None) =>
"""
Returns the first computed "value", if any, bound to a variable in the
scope of the given result.
Returns the computed "value", if any, bound to the variable.
"""
try b.values(v, r)?(0)? end
try
b(v)?.values(0)?
end

fun value_with[D: ast.NodeData val](b: Bindings, v: Variable, r: Success)
fun value_with[D: ast.NodeData val](b: Bindings, v: Variable)
: ast.NodeWith[D] ?
=>
"""
Returns the first computed "value" of the given type, if any, bound to the
variable in the scope of the given result.
Returns the computed "value" of the given type bound to the
variable.
"""
b.values(v, r)?(0)? as ast.NodeWith[D]
b(v)?.values(0)? as ast.NodeWith[D]

fun value_with_or_none[D: ast.NodeData val](
b: Bindings,
v: Variable,
r: Success)
fun value_with_or_none[D: ast.NodeData val](b: Bindings, v: Variable)
: (ast.NodeWith[D] | None)
=>
"""
Returns the first computed "value" of the given type, if any, bound to the
variable in the scope of the given result.
variable.
"""
try b.values(v, r)?(0)? as ast.NodeWith[D] end
try
b(v)?.values(0)? as ast.NodeWith[D]
end

fun values(b: Bindings, v: Variable, r: Success) : ast.NodeSeq =>
fun values(b: Bindings, v: Variable) : ast.NodeSeq =>
"""
Returns the sequence of computed "values" bound to a variable in the scope
of the given result.
Returns the sequence of computed "values" bound to a variable.
"""
try
b.values(v, r)?
b(v)?.values
else
[]
end

fun values_with[D: ast.NodeData val](b: Bindings, v: Variable, r: Success)
fun values_with[D: ast.NodeData val](b: Bindings, v: Variable)
: ast.NodeSeqWith[D]
=>
"""
Returns the sequence of computed "values" of a given type bound to a
variable in the scope of the given result.
variable.
"""
try
nodes_with[D](b.values(v, r)?)
nodes_with[D](b(v)?.values)
else
[]
end
Expand All @@ -84,40 +82,17 @@ primitive _Build
sequence.
"""
recover val
Array[ast.NodeWith[D]](c.size()) .> concat(
Iter[ast.Node](c.values())
.filter_map[ast.NodeWith[D]](
{(n) => try n as ast.NodeWith[D] end }))
Iter[ast.Node](c.values())
.filter_map[ast.NodeWith[D]]({(n) => try n as ast.NodeWith[D] end })
.collect(Array[ast.NodeWith[D]](c.size()))
end

fun values_and_errors[D: ast.NodeData val](
b: Bindings,
v: Variable,
r: Success)
: ast.NodeSeqWith[D]
=>
"""
Returns the computed "values" bound to a variable, as well as collecting
any error sections in the variable's node.
"""
let rvals: Array[ast.NodeWith[D]] trn = Array[ast.NodeWith[D]]()
try
let vvals = b.values(v, r)?
for vval in vvals.values() do
match vval
| let node: ast.NodeWith[D] =>
rvals.push(node)
end
end
end
consume rvals

fun with_post[D: ast.NodeData val](
body: RuleNode box,
post: RuleNode box,
body: RuleNode,
post: RuleNode,
action:
{(Data, Success, ast.NodeSeq, Bindings, ast.NodeSeqWith[D])
: ((ast.Node | None), Bindings)} val)
: (ast.Node | None) } val)
: RuleNode
=>
"""
Expand All @@ -128,7 +103,7 @@ primitive _Build
Conj(
[ body; Bind(p, Ques(post)) ],
{(d, r, c, b) =>
action(d, r, c, b, _Build.values_with[D](b, p, r))
action(d, r, c, b, _Build.values_with[D](b, p))
})

fun span_and_post(si: ast.SrcInfo, c: ast.NodeSeq, p: ast.NodeSeq)
Expand All @@ -147,15 +122,19 @@ primitive _Build
ast.SrcInfo(si.locator, si.start, next), [], ast.Span)
recover val [as ast.Node: span] .> concat(c.values()) end

fun bind_error(d: Data, r: Success, c: ast.NodeSeq, b: Bindings,
message: String): (ast.Node, Bindings)
fun bind_error(
d: Data,
r: Success,
c: ast.NodeSeq,
b: Bindings,
message: String)
: ast.Node
=>
"""
Constructs an error section with an error message relating to the
inability to get the results or values from a variable that should
have been bound but was not. This should never happen.
"""
let message' = ErrorMsg.internal_ast_node_not_bound(message)
let value' = ast.NodeWith[ast.ErrorSection](
ast.NodeWith[ast.ErrorSection](
_Build.info(d, r), c, ast.ErrorSection(message'))
(value', b)
Loading

0 comments on commit 517a3b5

Please sign in to comment.