diff --git a/corral.json b/corral.json index 0939864..0abae3c 100644 --- a/corral.json +++ b/corral.json @@ -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", diff --git a/eohippus/analyzer/eohippus_analyzer.pony b/eohippus/analyzer/eohippus_analyzer.pony index 0956e6b..a46d96a 100644 --- a/eohippus/analyzer/eohippus_analyzer.pony +++ b/eohippus/analyzer/eohippus_analyzer.pony @@ -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() @@ -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 @@ -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, @@ -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) @@ -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 @@ -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 " + @@ -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) @@ -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) diff --git a/eohippus/ast/node_with.pony b/eohippus/ast/node_with.pony index 9fb388a..b4c2e3d 100644 --- a/eohippus/ast/node_with.pony +++ b/eohippus/ast/node_with.pony @@ -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.""" diff --git a/eohippus/parser/_build.pony b/eohippus/parser/_build.pony index 4145865..0fa019a 100644 --- a/eohippus/parser/_build.pony +++ b/eohippus/parser/_build.pony @@ -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 @@ -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 => """ @@ -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) @@ -147,8 +122,13 @@ 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 @@ -156,6 +136,5 @@ primitive _Build 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) diff --git a/eohippus/parser/_exp_actions.pony b/eohippus/parser/_exp_actions.pony index c65e5e5..f8d3642 100644 --- a/eohippus/parser/_exp_actions.pony +++ b/eohippus/parser/_exp_actions.pony @@ -9,13 +9,10 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let ids = _Build.nodes_with[ast.Identifier](c) - - let value = ast.NodeWith[ast.Annotation]( - _Build.info(d, r), c, ast.Annotation(ids)) - (value, b) + ast.NodeWith[ast.Annotation](_Build.info(d, r), c, ast.Annotation(ids)) fun tag _seq( ann: Variable, @@ -24,23 +21,22 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let ann' = _Build.value_with_or_none[ast.Annotation](b, ann, r) - let expressions = _Build.values_with[ast.Expression](b, body, r) + let ann' = _Build.value_with_or_none[ast.Annotation](b, ann) + let expressions = _Build.values_with[ast.Expression](b, body) if expressions.size() == 1 then try let value = ast.NodeWith[ast.Expression].from(expressions(0)? where annotation' = ann') - return (value, b) + return value end end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpSequence(expressions) where annotation' = ann') - (value, b) fun tag _binop( lhs: Variable, @@ -51,36 +47,41 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let lhs' = try - _Build.value(b, lhs, r)? as + _Build.value(b, lhs)? as ( ast.NodeWith[ast.TypeType] | ast.NodeWith[ast.Expression] | ast.NodeWith[ast.Identifier] ) end let op' = try - _Build.value(b, op, r)? as + _Build.value(b, op)? as (ast.NodeWith[ast.Keyword] | ast.NodeWith[ast.Token]) else return _Build.bind_error(d, r, c, b, "Expression/Binop/Op") end let rhs' = try - _Build.value(b, rhs, r)? as + _Build.value(b, rhs)? as ( ast.NodeWith[ast.TypeType] | ast.NodeWith[ast.Expression] | ast.NodeWith[ast.Identifier] ) else return _Build.bind_error(d, r, c, b, "Expression/Binop/RHS") end - let partial' = b.contains(partial, r) + let partial' = + match partial + | let pv: Variable => + b.contains(pv) + else + false + end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpOperation(lhs', op', rhs', partial')) - (value, b) fun tag _lambda( bare: Variable, @@ -98,29 +99,29 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let bare' = b.contains(bare, r) + let bare' = b.contains(bare) let annotation' = - _Build.value_with_or_none[ast.Annotation](b, annotation, r) - let this_cap' = _Build.value_with_or_none[ast.Keyword](b, this_cap, r) + _Build.value_with_or_none[ast.Annotation](b, annotation) + let this_cap' = _Build.value_with_or_none[ast.Keyword](b, this_cap) let identifier' = - _Build.value_with_or_none[ast.Identifier](b, identifier, r) + _Build.value_with_or_none[ast.Identifier](b, identifier) let type_params' = - _Build.value_with_or_none[ast.TypeParams](b, type_params, r) - let params' = _Build.value_with_or_none[ast.MethodParams](b, params, r) - let captures' = _Build.value_with_or_none[ast.MethodParams](b, captures, r) - let ret_type' = _Build.value_with_or_none[ast.TypeType](b, ret_type, r) - let partial' = b.contains(partial, r) + _Build.value_with_or_none[ast.TypeParams](b, type_params) + let params' = _Build.value_with_or_none[ast.MethodParams](b, params) + let captures' = _Build.value_with_or_none[ast.MethodParams](b, captures) + let ret_type' = _Build.value_with_or_none[ast.TypeType](b, ret_type) + let partial' = b.contains(partial) let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/Lambda/Body") end - let ref_cap' = _Build.value_with_or_none[ast.Keyword](b, ref_cap, r) + let ref_cap' = _Build.value_with_or_none[ast.Keyword](b, ref_cap) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpLambda( bare', this_cap', @@ -133,7 +134,6 @@ primitive _ExpActions body', ref_cap') where annotation' = annotation') - (value, b) fun tag _jump( keyword: Variable, @@ -142,19 +142,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let keyword' = try - _Build.value_with[ast.Keyword](b, keyword, r)? + _Build.value_with[ast.Keyword](b, keyword)? else return _Build.bind_error(d, r, c, b, "Expression/Jump/Keyword") end - let rhs' = _Build.value_with_or_none[ast.Expression](b, rhs, r) + let rhs' = _Build.value_with_or_none[ast.Expression](b, rhs) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpJump(keyword', rhs')) - (value, b) fun tag _if( firstif: Variable, @@ -164,15 +163,15 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let firstif' = try - _Build.value_with[ast.IfCondition](b, firstif, r)? + _Build.value_with[ast.IfCondition](b, firstif)? else return _Build.bind_error(d, r, c, b, "Expression/If/FirstIf") end - let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs, r) + let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs) let conditions = recover val Array[ast.NodeWith[ast.IfCondition]](1 + elseifs'.size()) @@ -180,11 +179,10 @@ primitive _ExpActions .> append(elseifs') end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpIf(ast.IfExp, conditions, else_block')) - (value, b) fun tag _ifcond( if_true: Variable, @@ -193,24 +191,23 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let if_true' = try - _Build.value_with[ast.Expression](b, if_true, r)? + _Build.value_with[ast.Expression](b, if_true)? else return _Build.bind_error(d, r, c, b, "Expression/IfCond/Condition") end let then_block' = try - _Build.value_with[ast.Expression](b, then_block, r)? + _Build.value_with[ast.Expression](b, then_block)? else return _Build.bind_error(d, r, c, b, "Expression/IfCond/TrueSeq") end - let value = ast.NodeWith[ast.IfCondition]( + ast.NodeWith[ast.IfCondition]( _Build.info(d, r), c, ast.IfCondition(if_true', then_block')) - (value, b) fun tag _ifdef( firstif: Variable, @@ -220,15 +217,15 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let firstif' = try - _Build.value_with[ast.IfCondition](b, firstif, r)? + _Build.value_with[ast.IfCondition](b, firstif)? else return _Build.bind_error(d, r, c, b, "Expression/If/Firstif") end - let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs, r) + let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs) let conditions = recover val Array[ast.NodeWith[ast.IfCondition]](1 + elseifs'.size()) @@ -236,11 +233,10 @@ primitive _ExpActions .> append(elseifs') end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpIf(ast.IfDef, conditions, else_block')) - (value, b) fun tag _iftype( firstif: Variable, @@ -250,15 +246,15 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let firstif' = try - _Build.value_with[ast.IfCondition](b, firstif, r)? + _Build.value_with[ast.IfCondition](b, firstif)? else return _Build.bind_error(d, r, c, b, "Expression/IfType/Firstif") end - let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs, r) + let elseifs' = _Build.values_with[ast.IfCondition](b, elseifs) let conditions = recover val Array[ast.NodeWith[ast.IfCondition]](1 + elseifs'.size()) @@ -266,11 +262,10 @@ primitive _ExpActions .> append(elseifs') end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpIf(ast.IfType, conditions, else_block')) - (value, b) fun tag _iftype_cond( if_true: Variable, @@ -282,30 +277,30 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let cond_children = _Build.values(b, if_true, r) + let cond_children = _Build.values(b, if_true) let lhs' = try - _Build.value_with[ast.TypeType](b, lhs, r)? + _Build.value_with[ast.TypeType](b, lhs)? else return _Build.bind_error(d, r, c, b, "Expression/IfTypeCond/LHS") end let op' = try - _Build.value_with[ast.Token](b, op, r)? + _Build.value_with[ast.Token](b, op)? else return _Build.bind_error(d, r, c, b, "Expression/IfTypeCond/Op") end let rhs' = try - _Build.value_with[ast.TypeType](b, rhs, r)? + _Build.value_with[ast.TypeType](b, rhs)? else return _Build.bind_error(d, r, c, b, "Expression/IfTypeCond/RHS") end let then_block' = try - _Build.value_with[ast.Expression](b, then_block, r)? + _Build.value_with[ast.Expression](b, then_block)? else return _Build.bind_error(d, r, c, b, "Expression/IfTypeCond/Then") end @@ -315,9 +310,8 @@ primitive _ExpActions let cond = ast.NodeWith[ast.Expression]( cond_info, cond_children, ast.ExpOperation(lhs', op', rhs')) - let value = ast.NodeWith[ast.IfCondition]( + ast.NodeWith[ast.IfCondition]( _Build.info(d, r), c, ast.IfCondition(cond, then_block')) - (value, b) fun tag _match( exp: Variable, @@ -327,21 +321,20 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let exp' = try - _Build.value_with[ast.Expression](b, exp, r)? + _Build.value_with[ast.Expression](b, exp)? else return _Build.bind_error(d, r, c, b, "Expression/Match/Exp") end - let cases' = _Build.values_with[ast.MatchCase](b, cases, r) + let cases' = _Build.values_with[ast.MatchCase](b, cases) let else_block' = - _Build.value_with_or_none[ast.Expression](b, else_block, r) + _Build.value_with_or_none[ast.Expression](b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpMatch(exp', cases', else_block')) - (value, b) fun tag _match_pattern( pattern: Variable, @@ -350,19 +343,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let pattern' = try - _Build.value_with[ast.Expression](b, pattern, r)? + _Build.value_with[ast.Expression](b, pattern)? else 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 condition' = _Build.value_with_or_none[ast.Expression](b, condition) - let value = ast.NodeWith[ast.MatchPattern]( + ast.NodeWith[ast.MatchPattern]( _Build.info(d, r), c, ast.MatchPattern(pattern', condition')) - (value, b) fun tag _match_case( patterns: Variable, @@ -371,19 +363,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let patterns' = _Build.values_with[ast.MatchPattern](b, patterns, r) + let patterns' = _Build.values_with[ast.MatchPattern](b, patterns) let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/MatchCase/Body") end - let value = ast.NodeWith[ast.MatchCase]( + ast.NodeWith[ast.MatchCase]( _Build.info(d, r), c, ast.MatchCase(patterns', body')) - (value, b) fun tag _while( condition: Variable, @@ -393,26 +384,25 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let condition' = try - _Build.value_with[ast.Expression](b, condition, r)? + _Build.value_with[ast.Expression](b, condition)? else return _Build.bind_error(d, r, c, b, "Expression/While/Condition") end let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/While/Body") end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpWhile(condition', body', else_block')) - (value, b) fun tag _repeat( body: Variable, @@ -422,26 +412,25 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/Repeat/Body") end let condition' = try - _Build.value_with[ast.Expression](b, condition, r)? + _Build.value_with[ast.Expression](b, condition)? else return _Build.bind_error(d, r, c, b, "Expression/Repeat/Condition") end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpRepeat(body', condition', else_block')) - (value, b) fun tag _for( ids: Variable, @@ -452,39 +441,38 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let ids' = try - _Build.value_with[ast.TuplePattern](b, ids, r)? + _Build.value_with[ast.TuplePattern](b, ids)? else return _Build.bind_error(d, r, c, b, "Expression/For/Ids") end let seq' = try - _Build.value_with[ast.Expression](b, seq, r)? + _Build.value_with[ast.Expression](b, seq)? else return _Build.bind_error(d, r, c, b, "Expression/For/Sequence") end let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/For/Body") end let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpFor(ids', seq', body', else_block')) - (value, b) fun tag _tuple_pattern( d: Data, r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let elements = recover val @@ -504,9 +492,8 @@ primitive _ExpActions })) end - let value = ast.NodeWith[ast.TuplePattern]( + ast.NodeWith[ast.TuplePattern]( _Build.info(d, r), c, ast.TuplePattern(elements)) - (value, b) fun tag _with( elems: Variable, @@ -515,19 +502,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let elems' = _Build.values_with[ast.WithElement](b, elems, r) + let elems' = _Build.values_with[ast.WithElement](b, elems) let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/With/Body") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpWith(elems', body')) - (value, b) fun tag _with_elem( pattern: Variable, @@ -536,24 +522,23 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let pattern' = try - _Build.value_with[ast.TuplePattern](b, pattern, r)? + _Build.value_with[ast.TuplePattern](b, pattern)? else return _Build.bind_error(d, r, c, b, "Expression/WithElem/Pattern") end let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/WithElem/Body") end - let value = ast.NodeWith[ast.WithElement]( + ast.NodeWith[ast.WithElement]( _Build.info(d, r), c, ast.WithElement(pattern', body')) - (value, b) fun tag _try( body: Variable, @@ -562,11 +547,11 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let body' = _Build.value_with_or_none[ast.Expression](b, body, r) + let body' = _Build.value_with_or_none[ast.Expression](b, body) let else_block' = _Build.value_with_or_none[ast.Expression]( - b, else_block, r) + b, else_block) let children = match body' @@ -597,9 +582,8 @@ primitive _ExpActions c end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), children, ast.ExpTry(body', else_block')) - (value, b) fun tag _recover( cap: Variable, @@ -608,19 +592,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/Recover/Body") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpRecover(cap', body')) - (value, b) fun tag _consume( cap: Variable, @@ -629,19 +612,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) let body' = try - _Build.value_with[ast.Expression](b, body, r)? + _Build.value_with[ast.Expression](b, body)? else return _Build.bind_error(d, r, c, b, "Expression/Consume/Body") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpConsume(cap', body')) - (value, b) fun tag _decl( kind: Variable, @@ -651,25 +633,24 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind' = try - _Build.value_with[ast.Keyword](b, kind, r)? + _Build.value_with[ast.Keyword](b, kind)? else return _Build.bind_error(d, r, c, b, "Expression/Decl/Kind") end let identifier' = try - _Build.value_with[ast.Identifier](b, identifier, r)? + _Build.value_with[ast.Identifier](b, identifier)? else return _Build.bind_error(d, r, c, b, "Expression/Decl/Identifier") end - let decl_type' = _Build.value_with_or_none[ast.TypeType](b, decl_type, r) + let decl_type' = _Build.value_with_or_none[ast.TypeType](b, decl_type) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpDecl(kind', identifier', decl_type')) - (value, b) fun tag _prefix( op: Variable, @@ -678,25 +659,24 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let op' = try - _Build.value(b, op, r)? as + _Build.value(b, op)? as (ast.NodeWith[ast.Keyword] | ast.NodeWith[ast.Token]) else return _Build.bind_error(d, r, c, b, "Expression/Prefix/Op") end let rhs' = try - _Build.value_with[ast.Expression](b, rhs, r)? + _Build.value_with[ast.Expression](b, rhs)? else return _Build.bind_error(d, r, c, b, "Expression/Prefix/RHS") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpOperation(None, op', rhs')) - (value, b) fun tag _hash( rhs: Variable, @@ -704,18 +684,17 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let rhs' = try - _Build.value_with[ast.Expression](b, rhs, r)? + _Build.value_with[ast.Expression](b, rhs)? else return _Build.bind_error(d, r, c, b, "Expression/Hash/RHS") end - let value = ast.NodeWith[ast.ExpHash]( + ast.NodeWith[ast.ExpHash]( _Build.info(d, r), c, ast.ExpHash(rhs')) - (value, b) fun tag _postfix_type_args( lhs: Variable, @@ -724,24 +703,23 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let lhs' = try - _Build.value_with[ast.Expression](b, lhs, r)? + _Build.value_with[ast.Expression](b, lhs)? else return _Build.bind_error(d, r, c, b, "Expression/Postfix/Generic/LHS") end let args' = try - _Build.value_with[ast.TypeArgs](b, args, r)? + _Build.value_with[ast.TypeArgs](b, args)? else return _Build.bind_error(d, r, c, b, "Expression/Postfix/Generic/TypeArgs") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpGeneric(lhs', args')) - (value, b) fun tag _postfix_call_args( lhs: Variable, @@ -751,25 +729,24 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let lhs' = try - _Build.value_with[ast.Expression](b, lhs, r)? + _Build.value_with[ast.Expression](b, lhs)? else return _Build.bind_error(d, r, c, b, "Expression/Postfix/Call/LHS") end let args' = try - _Build.value_with[ast.CallArgs](b, args, r)? + _Build.value_with[ast.CallArgs](b, args)? else return _Build.bind_error(d, r, c, b, "Expression/PostFix/Call/CallArgs") end - let partial' = b.contains(partial, r) + let partial' = b.contains(partial) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpCall(lhs', args', partial')) - (value, b) fun tag _call_args( pos: Variable, @@ -778,14 +755,13 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let pos' = _Build.values_with[ast.Expression](b, pos, r) - let named' = _Build.values_with[ast.Expression](b, named, r) + let pos' = _Build.values_with[ast.Expression](b, pos) + let named' = _Build.values_with[ast.Expression](b, named) - let value = ast.NodeWith[ast.CallArgs]( + ast.NodeWith[ast.CallArgs]( _Build.info(d, r), c, ast.CallArgs(pos', named')) - (value, b) fun tag _atom( body: Variable, @@ -793,18 +769,17 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let body' = try - _Build.value(b, body, r)? + _Build.value(b, body)? else return _Build.bind_error(d, r, c, b, "Expression/Atom/Body") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpAtom(body')) - (value, b) fun tag _tuple( seqs: Variable, @@ -812,13 +787,12 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let seqs' = _Build.values_with[ast.Expression](b, seqs, r) + let seqs' = _Build.values_with[ast.Expression](b, seqs) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpTuple(seqs')) - (value, b) fun tag _array( array_type: Variable, @@ -827,14 +801,13 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let array_type' = _Build.value_with_or_none[ast.TypeType](b, array_type, r) - let body' = _Build.value_with_or_none[ast.Expression](b, body, r) + let array_type' = _Build.value_with_or_none[ast.TypeType](b, array_type) + let body' = _Build.value_with_or_none[ast.Expression](b, body) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpArray(array_type', body')) - (value, b) fun tag _ffi( identifier: Variable, @@ -845,29 +818,28 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let identifier' = try - _Build.value(b, identifier, r)? as + _Build.value(b, identifier)? as (ast.NodeWith[ast.Identifier] | ast.NodeWith[ast.LiteralString]) else return _Build.bind_error(d, r, c, b, "Expression/FFI/Identifier") end - let type_args' = _Build.value_with_or_none[ast.TypeArgs](b, type_args, r) + let type_args' = _Build.value_with_or_none[ast.TypeArgs](b, type_args) let call_args' = try - _Build.value_with[ast.CallArgs](b, call_args, r)? + _Build.value_with[ast.CallArgs](b, call_args)? else return _Build.bind_error(d, r, c, b, "Expression/FFI/CallArgs") end - let partial' = b.contains(partial, r) + let partial' = b.contains(partial) - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpFfi(identifier', type_args', call_args', partial')) - (value, b) fun tag _object( ann: Variable, @@ -878,19 +850,18 @@ primitive _ExpActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let ann' = _Build.value_with_or_none[ast.Annotation](b, ann, r) - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) - let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint, r) + let ann' = _Build.value_with_or_none[ast.Annotation](b, ann) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) + let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint) let members' = try - _Build.value_with[ast.TypedefMembers](b, members, r)? + _Build.value_with[ast.TypedefMembers](b, members)? else return _Build.bind_error(d, r, c, b, "Expression/Object/Members") end - let value = ast.NodeWith[ast.Expression]( + ast.NodeWith[ast.Expression]( _Build.info(d, r), c, ast.ExpObject(cap', constraint', members') where annotation' = ann') - (value, b) diff --git a/eohippus/parser/_literal_actions.pony b/eohippus/parser/_literal_actions.pony index d21af02..8533b22 100644 --- a/eohippus/parser/_literal_actions.pony +++ b/eohippus/parser/_literal_actions.pony @@ -10,16 +10,15 @@ primitive _LiteralActions c: ast.NodeSeq, b: Bindings, p: ast.NodeSeqWith[ast.Trivia]) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let src_info = _Build.info(d, r) let string = src_info.literal_source() let true_str = ast.Keywords.kwd_true() let is_true = string.compare_sub(true_str, true_str.size()) == Equal - let value = ast.NodeWith[ast.LiteralBool]( + ast.NodeWith[ast.LiteralBool]( src_info, _Build.span_and_post(src_info, c, p), ast.LiteralBool(is_true)) - (value, b) fun tag _integer( hex: Variable, @@ -30,12 +29,12 @@ primitive _LiteralActions c: ast.NodeSeq, b: Bindings, p: ast.NodeSeqWith[ast.Trivia]) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind = - if try _Build.result(b, hex, r)? end isnt None then + if try _Build.result(b, hex)? end isnt None then ast.HexadecimalInteger - elseif try _Build.result(b, bin, r)? end isnt None then + elseif try _Build.result(b, bin)? end isnt None then ast.BinaryInteger else ast.DecimalInteger @@ -54,12 +53,11 @@ primitive _LiteralActions 2 end let num: U128 = try str.u128(base)? else 0 end - let value = ast.NodeWith[ast.LiteralInteger]( + ast.NodeWith[ast.LiteralInteger]( src_info, _Build.span_and_post(src_info, c, p), ast.LiteralInteger(num, kind) where post_trivia' = p) - (value, b) fun tag _float( int_part: Variable, @@ -71,14 +69,14 @@ primitive _LiteralActions c: ast.NodeSeq, b: Bindings, p: ast.NodeSeqWith[ast.Trivia]) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let src_info = _Build.info(d, r) let str = src_info.literal_source(p) - let int_result' = try _Build.result(b, int_part, r)? end - let frac_result' = try _Build.result(b, frac_part, r)? end - let exp_result' = try _Build.result(b, exponent, r)? end + let int_result' = try _Build.result(b, int_part)? end + let frac_result' = try _Build.result(b, frac_part)? end + let exp_result' = try _Build.result(b, exponent)? end if (int_result' isnt None) and (frac_result' is None) and @@ -90,16 +88,15 @@ primitive _LiteralActions _Build.span_and_post(src_info, c, p), ast.LiteralInteger(int_num, ast.DecimalInteger) where post_trivia' = p) - return (int_value, b) + return int_value end let num: F64 = try str.f64()? else 0.0 end - let value = ast.NodeWith[ast.LiteralFloat]( + ast.NodeWith[ast.LiteralFloat]( src_info, _Build.span_and_post(src_info, c, p), ast.LiteralFloat(num) where post_trivia' = p) - (value, b) fun tag _char( bod: Variable, @@ -110,11 +107,11 @@ primitive _LiteralActions c: ast.NodeSeq, b: Bindings, p: ast.NodeSeqWith[ast.Trivia]) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let br = try - _Build.result(b, bod, r)? + _Build.result(b, bod)? else r end @@ -122,10 +119,10 @@ primitive _LiteralActions var num: U32 = 0 let str = recover val String .> concat(br.start.values(br.next)) end - if try _Build.result(b, esc, r)? end isnt None then - (_char_esc(d, r, br, c, p), b) - elseif try _Build.result(b, uni, r)? end isnt None then - (_char_uni(d, r, br, c, p), b) + if try _Build.result(b, esc)? end isnt None then + _char_esc(d, r, br, c, p) + elseif try _Build.result(b, uni)? end isnt None then + _char_uni(d, r, br, c, p) else for ch in br.start.values(br.next) do if (ch and 0b11111000) == 0b11110000 then @@ -141,12 +138,11 @@ primitive _LiteralActions end end let src_info = _Build.info(d, r) - let value = ast.NodeWith[ast.LiteralChar]( + ast.NodeWith[ast.LiteralChar]( src_info, _Build.span_and_post(src_info, c, p), ast.LiteralChar(ast.CharLiteral, num) where post_trivia' = p) - (value, b) end fun tag _char_esc( @@ -247,10 +243,10 @@ primitive _LiteralActions c: ast.NodeSeq, b: Bindings, p: ast.NodeSeqWith[ast.Trivia]) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind = - if try _Build.result(b, tri, r)? end isnt None then + if try _Build.result(b, tri)? end isnt None then ast.StringTripleQuote else ast.StringLiteral @@ -342,12 +338,11 @@ primitive _LiteralActions indented end - let value = ast.NodeWith[ast.LiteralString]( + ast.NodeWith[ast.LiteralString]( _Build.info(d, r), c, ast.LiteralString(outdented, kind) where post_trivia' = p) - (value, b) fun tag _string_lines(str: String box): Array[(USize, USize)] val => let result: Array[(USize, USize)] trn = Array[(USize, USize)] diff --git a/eohippus/parser/_type_actions.pony b/eohippus/parser/_type_actions.pony index 9dc9ae1..63d7b00 100644 --- a/eohippus/parser/_type_actions.pony +++ b/eohippus/parser/_type_actions.pony @@ -8,26 +8,24 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let args = _Build.nodes_with[ast.TypeType](c) - let value = ast.NodeWith[ast.TypeArgs]( + ast.NodeWith[ast.TypeArgs]( _Build.info(d, r), c, ast.TypeArgs(args)) - (value, b) fun tag _type_params( d: Data, r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let params = _Build.nodes_with[ast.TypeParam](c) - let value = ast.NodeWith[ast.TypeParams]( + ast.NodeWith[ast.TypeParams]( _Build.info(d, r), c, ast.TypeParams(params)) - (value, b) fun tag _type_param( name: Variable, @@ -37,15 +35,14 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let name' = _Build.value_with_or_none[ast.Identifier](b, name, r) - let ctype' = _Build.value_with_or_none[ast.TypeType](b, ctype, r) - let tinit' = _Build.value_with_or_none[ast.TypeType](b, tinit, r) + let name' = _Build.value_with_or_none[ast.Identifier](b, name) + let ctype' = _Build.value_with_or_none[ast.TypeType](b, ctype) + let tinit' = _Build.value_with_or_none[ast.TypeType](b, tinit) - let value = ast.NodeWith[ast.TypeParam]( + ast.NodeWith[ast.TypeParam]( _Build.info(d, r), c, ast.TypeParam(name', ctype', tinit')) - (value, b) fun tag _type_arrow( lhs: Variable, @@ -54,11 +51,11 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let lhs' = try - _Build.value_with[ast.TypeType](b, lhs, r)? + _Build.value_with[ast.TypeType](b, lhs)? else return _Build.bind_error(d, r, c, b, "Type/Arrow/LHS") end @@ -71,7 +68,7 @@ primitive _TypeActions "lhs?" end - match _Build.value_with_or_none[ast.TypeType](b, rhs, r) + match _Build.value_with_or_none[ast.TypeType](b, rhs) | let rhs': ast.NodeWith[ast.TypeType] => let rhs_string = match rhs'.data() @@ -81,11 +78,10 @@ primitive _TypeActions "rhs?" end - let value = ast.NodeWith[ast.TypeType]( + ast.NodeWith[ast.TypeType]( _Build.info(d, r), c, ast.TypeArrow(lhs', rhs')) - (value, b) else - (lhs', b) + lhs' end fun tag _type_atom( @@ -94,16 +90,15 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => try - match _Build.value(b, body, r)? + match _Build.value(b, body)? | let t': ast.NodeWith[ast.TypeType] => - (t', b) + t' | let node: ast.Node => - let value = ast.NodeWith[ast.TypeType]( + ast.NodeWith[ast.TypeType]( _Build.info(d, r), c, ast.TypeAtom(node)) - (value, b) end else return _Build.bind_error(d, r, c, b, "Type/Atom/Body") @@ -114,13 +109,12 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let types = _Build.nodes_with[ast.TypeType](c) - let value = ast.NodeWith[ast.TypeType]( + ast.NodeWith[ast.TypeType]( _Build.info(d, r), c, ast.TypeTuple(types)) - (value, b) fun tag _type_infix( types: Variable, @@ -129,20 +123,19 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let types' = _Build.values_with[ast.TypeType](b, types, r) - let op' = _Build.value_with_or_none[ast.Token](b, op, r) + let types' = _Build.values_with[ast.TypeType](b, types) + let op' = _Build.value_with_or_none[ast.Token](b, op) if types'.size() == 1 then try - return (types'(0)?, b) + return types'(0)? end end - let value = ast.NodeWith[ast.TypeType]( + ast.NodeWith[ast.TypeType]( _Build.info(d, r), c, ast.TypeInfix(types', op')) - (value, b) fun tag _type_nominal( lhs: Variable, @@ -154,18 +147,18 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let lhs' = try - _Build.value_with[ast.Identifier](b, lhs, r)? + _Build.value_with[ast.Identifier](b, lhs)? else return _Build.bind_error(d, r, c, b, "Type/Nominal/LHS") end - var rhs' = _Build.value_with_or_none[ast.Identifier](b, rhs, r) - let params' = _Build.value_with_or_none[ast.TypeParams](b, params, r) - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) - let eph' = _Build.value_with_or_none[ast.Token](b, eph, r) + var rhs' = _Build.value_with_or_none[ast.Identifier](b, rhs) + let params' = _Build.value_with_or_none[ast.TypeParams](b, params) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) + let eph' = _Build.value_with_or_none[ast.Token](b, eph) let nominal = match rhs' @@ -174,8 +167,7 @@ primitive _TypeActions else ast.TypeNominal(None, lhs', params', cap', eph') end - let value = ast.NodeWith[ast.TypeType](_Build.info(d, r), c, nominal) - (value, b) + ast.NodeWith[ast.TypeType](_Build.info(d, r), c, nominal) fun tag _type_lambda( bare: Variable, @@ -191,21 +183,20 @@ primitive _TypeActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let bare' = _Build.value_with_or_none[ast.Token](b, bare, r) isnt None - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) - let name' = _Build.value_with_or_none[ast.Identifier](b, name, r) - let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams, r) - let ptypes' = _Build.values_with[ast.TypeType](b, ptypes, r) - let rtype' = _Build.value_with_or_none[ast.TypeType](b, rtype, r) - let partial' = _Build.value_with_or_none[ast.Token](b, partial, r) isnt None - let rcap' = _Build.value_with_or_none[ast.Keyword](b, rcap, r) - let reph' = _Build.value_with_or_none[ast.Token](b, reph, r) - - let value = ast.NodeWith[ast.TypeType]( + let bare' = _Build.value_with_or_none[ast.Token](b, bare) isnt None + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) + let name' = _Build.value_with_or_none[ast.Identifier](b, name) + let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams) + let ptypes' = _Build.values_with[ast.TypeType](b, ptypes) + let rtype' = _Build.value_with_or_none[ast.TypeType](b, rtype) + let partial' = _Build.value_with_or_none[ast.Token](b, partial) isnt None + let rcap' = _Build.value_with_or_none[ast.Keyword](b, rcap) + let reph' = _Build.value_with_or_none[ast.Token](b, reph) + + ast.NodeWith[ast.TypeType]( _Build.info(d, r), c, ast.TypeLambda( bare', cap', name', tparams', ptypes', rtype', partial', rcap', reph')) - (value, b) diff --git a/eohippus/parser/_typedef_actions.pony b/eohippus/parser/_typedef_actions.pony index b9ef803..0deef05 100644 --- a/eohippus/parser/_typedef_actions.pony +++ b/eohippus/parser/_typedef_actions.pony @@ -7,31 +7,29 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let s' = try - _Build.value_with[ast.LiteralString](b, s, r)? + _Build.value_with[ast.LiteralString](b, s)? else return _Build.bind_error(d, r, c, b, "DocString/LiteralString") end - let value = ast.NodeWith[ast.DocString]( + ast.NodeWith[ast.DocString]( _Build.info(d, r), c, ast.DocString(s')) - (value, b) fun tag _method_params( d: Data, r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let params' = _Build.nodes_with[ast.MethodParam](c) - let value = ast.NodeWith[ast.MethodParams]( + ast.NodeWith[ast.MethodParams]( _Build.info(d, r), c, ast.MethodParams(params')) - (value, b) fun tag _method_param( identifier: Variable, @@ -41,21 +39,20 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let identifier' = try - _Build.value_with[ast.Identifier](b, identifier, r)? + _Build.value_with[ast.Identifier](b, identifier)? else return _Build.bind_error(d, r, c, b, "Typedef/MethodParam/Identifier") end - let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint, r) + let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint) let initializer' = - _Build.value_with_or_none[ast.Expression](b, initializer, r) + _Build.value_with_or_none[ast.Expression](b, initializer) - let value = ast.NodeWith[ast.MethodParam]( + ast.NodeWith[ast.MethodParam]( _Build.info(d, r), c, ast.MethodParam(identifier', constraint', initializer')) - (value, b) fun tag _field( kind: Variable, @@ -67,30 +64,29 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind' = try - _Build.value_with[ast.Keyword](b, kind, r)? + _Build.value_with[ast.Keyword](b, kind)? else return _Build.bind_error(d, r, c, b, "Typedef/Field/Kind") end let identifier' = try - _Build.value_with[ast.Identifier](b, identifier, r)? + _Build.value_with[ast.Identifier](b, identifier)? else return _Build.bind_error(d, r, c, b, "Typedef/Field/Identifier") end - let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint, r) - let initializer' = _Build.value_with_or_none[ast.Expression](b, initializer, r) - let doc_strings' = _Build.values_with[ast.DocString](b, doc_string, r) + let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint) + let initializer' = _Build.value_with_or_none[ast.Expression](b, initializer) + let doc_strings' = _Build.values_with[ast.DocString](b, doc_string) - let value = ast.NodeWith[ast.TypedefField]( + ast.NodeWith[ast.TypedefField]( _Build.info(d, r), c, ast.TypedefField(kind', identifier', constraint', initializer') where doc_strings' = doc_strings') - (value, b) fun tag _method( kind: Variable, @@ -108,37 +104,36 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind' = try - _Build.value_with[ast.Keyword](b, kind, r)? + _Build.value_with[ast.Keyword](b, kind)? else return _Build.bind_error(d, r, c, b, "Typedef/Method/Kind") end - let ann' = _Build.value_with_or_none[ast.Annotation](b, ann, r) - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) - let raw' = b.contains(raw, r) + let ann' = _Build.value_with_or_none[ast.Annotation](b, ann) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) + let raw' = b.contains(raw) let id' = try - _Build.value_with[ast.Identifier](b, id, r)? + _Build.value_with[ast.Identifier](b, id)? else return _Build.bind_error(d, r, c, b, "Typedef/Method/Id") end - let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams, r) - let params' = _Build.value_with_or_none[ast.MethodParams](b, params, r) - let rtype' = _Build.value_with_or_none[ast.TypeType](b, rtype, r) - let partial' = b.contains(partial, r) - let doc_strings' = _Build.values_with[ast.DocString](b, doc_string, r) - let body' = _Build.value_with_or_none[ast.Expression](b, body, r) + let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams) + let params' = _Build.value_with_or_none[ast.MethodParams](b, params) + let rtype' = _Build.value_with_or_none[ast.TypeType](b, rtype) + let partial' = b.contains(partial) + let doc_strings' = _Build.values_with[ast.DocString](b, doc_string) + let body' = _Build.value_with_or_none[ast.Expression](b, body) - let value = ast.NodeWith[ast.TypedefMethod]( + ast.NodeWith[ast.TypedefMethod]( _Build.info(d, r), c, ast.TypedefMethod( kind', cap', raw', id', tparams', params', rtype', partial', body') where doc_strings' = doc_strings', annotation' = ann') - (value, b) fun tag _members( fields: Variable, @@ -147,16 +142,16 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let fields' = _Build.values_with[ast.TypedefField](b, fields, r) - let methods' = _Build.values_with[ast.TypedefMethod](b, methods, r) + let fields' = _Build.values_with[ast.TypedefField](b, fields) + let methods' = _Build.values_with[ast.TypedefMethod](b, methods) - let value = ast.NodeWith[ast.TypedefMembers]( + ast.NodeWith[ast.TypedefMembers]( _Build.info(d, r), c, ast.TypedefMembers(fields', methods')) - (value, b) fun tag _primitive( + an: Variable, id: Variable, tp: Variable, cs: Variable, @@ -166,25 +161,26 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => + let an' = _Build.value_with_or_none[ast.Annotation](b, an) let id': ast.NodeWith[ast.Identifier] = try - _Build.value_with[ast.Identifier](b, id, r)? + _Build.value_with[ast.Identifier](b, id)? else return _Build.bind_error(d, r, c, b, "Typedef/Primitive/Identifier") end - let tp' = _Build.value_with_or_none[ast.TypeParams](b, tp, r) - let cs' = _Build.value_with_or_none[ast.TypeType](b, cs, r) - let ds' = _Build.values_with[ast.DocString](b, ds, r) - let mm' = _Build.value_with_or_none[ast.TypedefMembers](b, mm, r) + let tp' = _Build.value_with_or_none[ast.TypeParams](b, tp) + let cs' = _Build.value_with_or_none[ast.TypeType](b, cs) + let ds' = _Build.values_with[ast.DocString](b, ds) + let mm' = _Build.value_with_or_none[ast.TypedefMembers](b, mm) - let value = ast.NodeWith[ast.Typedef]( + ast.NodeWith[ast.Typedef]( _Build.info(d, r), c, ast.TypedefPrimitive(id', tp', cs', mm') - where doc_strings' = ds') - (value, b) + where annotation' = an', doc_strings' = ds') fun tag _alias( + ann: Variable, id: Variable, tparams: Variable, type_type: Variable, @@ -193,27 +189,27 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => + let ann' = _Build.value_with_or_none[ast.Annotation](b, ann) let id' = try - _Build.value_with[ast.Identifier](b, id, r)? + _Build.value_with[ast.Identifier](b, id)? else return _Build.bind_error(d, r, c, b, "Typedef/Alias/Identifier") end - let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams, r) + let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams) let type_type' = try - _Build.value_with[ast.TypeType](b, type_type, r)? + _Build.value_with[ast.TypeType](b, type_type)? else return _Build.bind_error(d, r, c, b, "Typedef/Alias/Type") end - let doc_strings' = _Build.values_with[ast.DocString](b, doc_string, r) + let doc_strings' = _Build.values_with[ast.DocString](b, doc_string) - let value = ast.NodeWith[ast.Typedef]( + ast.NodeWith[ast.Typedef]( _Build.info(d, r), c, ast.TypedefAlias(id', tparams', type_type') - where doc_strings' = doc_strings') - (value, b) + where annotation' = ann', doc_strings' = doc_strings') fun tag _class( kind: Variable, @@ -229,29 +225,29 @@ primitive _TypedefActions r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => let kind' = try - _Build.value_with[ast.Keyword](b, kind, r)? + _Build.value_with[ast.Keyword](b, kind)? else return _Build.bind_error(d, r, c, b, "Typedef/Class/Kind") end - let ann' = _Build.value_with_or_none[ast.Annotation](b, ann, r) - let raw' = b.contains(raw, r) - let cap' = _Build.value_with_or_none[ast.Keyword](b, cap, r) + let ann' = _Build.value_with_or_none[ast.Annotation](b, ann) + let raw' = b.contains(raw) + let cap' = _Build.value_with_or_none[ast.Keyword](b, cap) let id' = try - _Build.value_with[ast.Identifier](b, id, r)? + _Build.value_with[ast.Identifier](b, id)? else return _Build.bind_error(d, r, c, b, "Typedef/Class/Identifier") end - let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams, r) - let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint, r) - let doc_strings' = _Build.values_with[ast.DocString](b, doc_string, r) - let members' = _Build.value_with_or_none[ast.TypedefMembers](b, members, r) + let tparams' = _Build.value_with_or_none[ast.TypeParams](b, tparams) + let constraint' = _Build.value_with_or_none[ast.TypeType](b, constraint) + let doc_strings' = _Build.values_with[ast.DocString](b, doc_string) + let members' = _Build.value_with_or_none[ast.TypedefMembers](b, members) - let value = ast.NodeWith[ast.Typedef]( + ast.NodeWith[ast.Typedef]( _Build.info(d, r), c, ast.TypedefClass( @@ -263,4 +259,3 @@ primitive _TypedefActions constraint', members') where annotation' = ann', doc_strings' = doc_strings') - (value, b) diff --git a/eohippus/parser/keyword_builder.pony b/eohippus/parser/keyword_builder.pony index 5a2d058..5efc710 100644 --- a/eohippus/parser/keyword_builder.pony +++ b/eohippus/parser/keyword_builder.pony @@ -111,26 +111,28 @@ class KeywordBuilder t, {(d, r, c, b, p) => let src_info = _Build.info(d, r) - let value = ast.NodeWith[ast.Keyword]( + ast.NodeWith[ast.Keyword]( src_info, _Build.span_and_post(src_info, c, p), ast.Keyword(str) where post_trivia' = p) - (value, b) })) + })) m.insert(str, rule) - fun apply(str: String): NamedRule box => + fun apply(str: String): this->NamedRule => try _keywords(str)? else - let msg = - recover val - "INVALID KEYWORD '" + StringUtil.escape(str) + - "'; add it to the list in KeywordBuilder" - end - NamedRule(msg, Error(msg)) + recover + let msg = + recover val + "INVALID KEYWORD '" + StringUtil.escape(str) + + "'; add it to the list in KeywordBuilder if necessary" + end + NamedRule(msg, Error(msg)) + end end fun ref _build_kwd() => - let literals = Array[Literal box](_kwd_strings.size()) + let literals = Array[RuleNode](_kwd_strings.size()) for str in _kwd_strings.values() do literals.push(Literal(str)) end @@ -154,10 +156,10 @@ class KeywordBuilder else "" end - let value = ast.NodeWith[ast.Keyword]( + ast.NodeWith[ast.Keyword]( src_info, _Build.span_and_post(src_info, c, p), ast.Keyword(str) where post_trivia' = p) - (value, b) })) + })) fun ref _build_not_kwd() => not_kwd.set_body(Neg(kwd)) diff --git a/eohippus/parser/literal_builder.pony b/eohippus/parser/literal_builder.pony index 5ee28d6..be74c3e 100644 --- a/eohippus/parser/literal_builder.pony +++ b/eohippus/parser/literal_builder.pony @@ -225,9 +225,8 @@ class LiteralBuilder String .> concat(r.start.values(r.next)) end let span = ast.NodeWith[ast.Span](_Build.info(d, r), [], ast.Span) - let value = ast.NodeWith[ast.Token]( + ast.NodeWith[ast.Token]( _Build.info(d, r), [ span ], ast.Token(string)) - (value, b) }))) fun ref _build_string_triple() => @@ -242,12 +241,11 @@ class LiteralBuilder String .> concat(r.start.values(r.next)) end let span = ast.NodeWith[ast.Span](_Build.info(d, r), [], ast.Span) - let value = ast.NodeWith[ast.Token]( + ast.NodeWith[ast.Token]( _Build.info(d, r), [ span ], ast.Token(string)) - (value, b) }))) - fun _string_delim(delim: RuleNode): RuleNode => + fun ref _string_delim(delim: RuleNode): RuleNode => Conj( [ delim Star( @@ -266,9 +264,8 @@ class LiteralBuilder ]), 1, {(d, r, c, b) => - ( ast.NodeWith[ast.Span]( + ast.NodeWith[ast.Span]( _Build.info(d, r), c, ast.Span) - , b ) }) ]) ])) @@ -278,12 +275,12 @@ class LiteralBuilder ]) ]) - fun _string_char_uni(): RuleNode => + fun ref _string_char_uni(): RuleNode => Conj( [ char_unicode ], - {(d, r, c, b) => (_LiteralActions._char_uni(d, r, r, c, []), b) }) + {(d, r, c, b) => _LiteralActions._char_uni(d, r, r, c, []) }) - fun _string_char_esc(): RuleNode => + fun ref _string_char_esc(): RuleNode => Conj( [ char_escape ], - {(d, r, c, b) => (_LiteralActions._char_esc(d, r, r, c, []), b) }) + {(d, r, c, b) => _LiteralActions._char_esc(d, r, r, c, []) }) diff --git a/eohippus/parser/operator_builder.pony b/eohippus/parser/operator_builder.pony index 3df536d..8fbf307 100644 --- a/eohippus/parser/operator_builder.pony +++ b/eohippus/parser/operator_builder.pony @@ -96,15 +96,13 @@ class OperatorBuilder let str = recover val String .> concat(r.start.values(next)) end if (str == kwd_and) or (str == kwd_or) or (str == kwd_xor) then - let value = ast.NodeWith[ast.Keyword]( + ast.NodeWith[ast.Keyword]( src_info, _Build.span_and_post(src_info, c, p), ast.Keyword(str) where post_trivia' = p) - (value, b) else - let value = ast.NodeWith[ast.Token]( + ast.NodeWith[ast.Token]( src_info, _Build.span_and_post(src_info, c, p), ast.Token(str) where post_trivia' = p) - (value, b) end } )) diff --git a/eohippus/parser/rules.pony b/eohippus/parser/rules.pony index c248b61..59b5cf9 100644 --- a/eohippus/parser/rules.pony +++ b/eohippus/parser/rules.pony @@ -28,9 +28,9 @@ type Action is k.Action[U8, Data, ast.Node] type Bindings is k.Bindings[U8, Data, ast.Node] primitive Ques - fun apply(body: RuleNode box, action: (Action | None) = None): RuleNode ref => + fun apply(body: RuleNode, action: (Action | None) = None): RuleNode => Star(body, 0, action, 1) primitive Plus - fun apply(body: RuleNode box, action: (Action | None) = None): RuleNode ref => + fun apply(body: RuleNode, action: (Action | None) = None): RuleNode => Star(body, 1, action) diff --git a/eohippus/parser/src_file_builder.pony b/eohippus/parser/src_file_builder.pony index af603df..525d278 100644 --- a/eohippus/parser/src_file_builder.pony +++ b/eohippus/parser/src_file_builder.pony @@ -38,7 +38,7 @@ class SrcFileBuilder _build_using_pony() _build_using_ffi() - fun ref err_sec(allowed: ReadSeq[NamedRule], message: String): RuleNode => + fun ref err_sec(allowed: Array[RuleNode], message: String): RuleNode => _typedef.error_section(allowed, message) fun ref _build_src_file() => @@ -100,29 +100,26 @@ class SrcFileBuilder r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => ( let t1': ast.NodeSeqWith[ast.Trivia], let ds': ast.NodeSeqWith[ast.DocString], let us': ast.NodeSeqWith[ast.Using], let td': ast.NodeSeqWith[ast.Typedef] ) = - recover val - ( _Build.values_and_errors[ast.Trivia](b, t1, r), - _Build.values_and_errors[ast.DocString](b, ds, r), - _Build.values_and_errors[ast.Using](b, us, r), - _Build.values_and_errors[ast.Typedef](b, td, r) ) - end + ( _Build.values_with[ast.Trivia](b, t1), + _Build.values_with[ast.DocString](b, ds), + _Build.values_with[ast.Using](b, us), + _Build.values_with[ast.Typedef](b, td) ) - let pt' = _Build.values_with[ast.Trivia](b, pt, r) + let pt' = _Build.values_with[ast.Trivia](b, pt) - let value = ast.NodeWith[ast.SrcFile]( + ast.NodeWith[ast.SrcFile]( _Build.info(d, r), c, ast.SrcFile(d.locator, us', td') where pre_trivia' = t1', doc_strings' = ds', post_trivia' = pt') - (value, b) fun ref _build_using() => using.set_body( @@ -164,23 +161,22 @@ class SrcFileBuilder r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let id' = _Build.value_with_or_none[ast.Identifier](b, id, r) + let id' = _Build.value_with_or_none[ast.Identifier](b, id) let pt' = try - _Build.value_with[ast.LiteralString](b, pt, r)? + _Build.value_with[ast.LiteralString](b, pt)? else return _Build.bind_error(d, r, c, b, "SrcFile/UsingPony/LiteralString") end - let def_true = try _Build.result(b, fl, r)? end is None - let df' = _Build.value_with_or_none[ast.Identifier](b, df, r) + let def_true = try _Build.result(b, fl)? end is None + let df' = _Build.value_with_or_none[ast.Identifier](b, df) - let value = ast.NodeWith[ast.Using]( + ast.NodeWith[ast.Using]( _Build.info(d, r), c, ast.UsingPony(id', pt', def_true, df')) - (value, b) fun ref _build_using_ffi() => let at = _token(ast.Tokens.at()) @@ -253,32 +249,32 @@ class SrcFileBuilder r: Success, c: ast.NodeSeq, b: Bindings) - : ((ast.Node | None), Bindings) + : (ast.Node | None) => - let id' = _Build.value_with_or_none[ast.Identifier](b, id, r) + let id' = _Build.value_with_or_none[ast.Identifier](b, id) let name' = try - _Build.value_with[ast.Identifier](b, name, r)? + _Build.value_with[ast.Identifier](b, name)? else try - _Build.value_with[ast.LiteralString](b, name, r)? + _Build.value_with[ast.LiteralString](b, name)? else return _Build.bind_error(d, r, c, b, "SrcFile/UsingFfi/Name") end end let targs' = try - _Build.value_with[ast.TypeArgs](b, targs, r)? + _Build.value_with[ast.TypeArgs](b, targs)? else return _Build.bind_error(d, r, c, b, "SrcFile/UsingFfi/TypeArgs") end - let params' = _Build.value_with_or_none[ast.MethodParams](b, params, r) - let ellipsis' = b.contains(ellipsis, r) - let partial' = b.contains(partial, r) - let def_not' = b.contains(def_not, r) - let define' = _Build.value_with_or_none[ast.Identifier](b, define, r) + let params' = _Build.value_with_or_none[ast.MethodParams](b, params) + let ellipsis' = b.contains(ellipsis) + let partial' = b.contains(partial) + let def_not' = b.contains(def_not) + let define' = _Build.value_with_or_none[ast.Identifier](b, define) - let value = ast.NodeWith[ast.Using]( + ast.NodeWith[ast.Using]( _Build.info(d, r), c, ast.UsingFFI( @@ -290,4 +286,3 @@ class SrcFileBuilder partial', not def_not', define')) - (value, b) diff --git a/eohippus/parser/token_builder.pony b/eohippus/parser/token_builder.pony index 89c3540..e6dd962 100644 --- a/eohippus/parser/token_builder.pony +++ b/eohippus/parser/token_builder.pony @@ -132,13 +132,13 @@ class TokenBuilder String .> concat(r.start.values(next)) end - let value = ast.NodeWith[ast.Token]( + ast.NodeWith[ast.Token]( src_info, _Build.span_and_post(src_info, c, p), ast.Token(string) where post_trivia' = p) - (value, b) })) + })) m.insert(str, rule) - fun apply(str: String): NamedRule box => + fun ref apply(str: String): NamedRule => try _tokens(str)? else @@ -168,9 +168,9 @@ class TokenBuilder end let string = recover val String .> concat(r.start.values(next)) end - let value = ast.NodeWith[ast.Identifier]( + ast.NodeWith[ast.Identifier]( src_info, _Build.span_and_post(src_info, c, p), ast.Identifier(string) where post_trivia' = p) - (value, b) })) + })) diff --git a/eohippus/parser/trivia_builder.pony b/eohippus/parser/trivia_builder.pony index c4a6fc4..a76416e 100644 --- a/eohippus/parser/trivia_builder.pony +++ b/eohippus/parser/trivia_builder.pony @@ -40,9 +40,9 @@ class TriviaBuilder Look(Disj([ eol; eof ])) ]), {(d, r, c, b) => let str = recover val String .> concat(r.start.values(r.next)) end - let value = ast.NodeWith[ast.Trivia]( + ast.NodeWith[ast.Trivia]( _Build.info(d, r), c, ast.Trivia(ast.LineCommentTrivia, str)) - (value, b) }) + }) fun ref _build_comment_nested() => // '/*' (!'*/' .)* '*/' @@ -53,18 +53,18 @@ class TriviaBuilder Literal("*/") ]), {(d, r, c, b) => let str = recover val String .> concat(r.start.values(r.next)) end - let value = ast.NodeWith[ast.Trivia]( + ast.NodeWith[ast.Trivia]( _Build.info(d, r), c, ast.Trivia(ast.NestedCommentTrivia, str)) - (value, b) }) + }) fun ref _build_ws() => ws.set_body( Plus(Single(" \t")), {(d, r, c, b) => let str = recover val String .> concat(r.start.values(r.next)) end - let value = ast.NodeWith[ast.Trivia]( + ast.NodeWith[ast.Trivia]( _Build.info(d, r), c, ast.Trivia(ast.WhiteSpaceTrivia, str)) - (value, b) }) + }) fun ref _build_eol() => eol.set_body( @@ -74,9 +74,9 @@ class TriviaBuilder Literal("\r") ]), {(d, r, c, b) => let str = recover val String .> concat(r.start.values(r.next)) end - let value = ast.NodeWith[ast.Trivia]( + ast.NodeWith[ast.Trivia]( _Build.info(d, r), c, ast.Trivia(ast.EndOfLineTrivia, str)) - (value, b) }) + }) fun ref _build_dol() => dol.set_body(Star(Conj([ eol; Ques(ws) ]), 2)) @@ -85,6 +85,6 @@ class TriviaBuilder eof.set_body( Neg(Single), {(d, r, c, b) => - let value = ast.NodeWith[ast.Trivia]( + ast.NodeWith[ast.Trivia]( _Build.info(d, r), c, ast.Trivia(ast.EndOfFileTrivia, "")) - (value, b) }) + }) diff --git a/eohippus/parser/typedef_builder.pony b/eohippus/parser/typedef_builder.pony index d5c3333..a43cb1c 100644 --- a/eohippus/parser/typedef_builder.pony +++ b/eohippus/parser/typedef_builder.pony @@ -46,7 +46,7 @@ class TypedefBuilder _build_typedef_alias() _build_typedef_class() - fun error_section(allowed: ReadSeq[NamedRule box], message: String) + fun ref error_section(allowed: Array[RuleNode], message: String) : RuleNode => let eol = _trivia.eol @@ -63,12 +63,13 @@ class TypedefBuilder [ eol Single( [], - {(d, r, c, b) => - let value = ast.NodeWith[ast.Span]( - _Build.info(d, r), c, ast.Span) - (value, b) - }) ]) ])) - Disj([ dol; Look(eof) ]) ], + {(d, r, c, _) => + ast.NodeWith[ast.Span](_Build.info(d, r), c, ast.Span) + }) + ]) + ])) + Disj([ dol; Look(eof) ]) + ], {(d, r, c, b) => let new_children: Array[ast.Node] trn = Array[ast.Node] var in_span = false @@ -100,9 +101,8 @@ class TypedefBuilder ast.SrcInfo(d.locator, span_start, span_next), [], ast.Span)) end - let value = ast.NodeWith[ast.ErrorSection]( + ast.NodeWith[ast.ErrorSection]( _Build.info(d, r), consume new_children, ast.ErrorSection(message)) - (value, b) })) fun ref _build_doc_string() => @@ -265,6 +265,7 @@ class TypedefBuilder ])) fun ref _build_typedef_primitive() => + let an = Variable("an") let id = Variable("id") let tp = Variable("tp") let cs = Variable("cs") @@ -274,6 +275,7 @@ class TypedefBuilder typedef_primitive.set_body( Conj( [ _keyword(ast.Keywords.kwd_primitive()) + Ques(Bind(an, _expression.annotation)) Bind(id, _token.identifier) Ques(Bind(tp, _type_type.params)) Ques(Conj( @@ -282,12 +284,13 @@ class TypedefBuilder Ques(Bind(ds, doc_string)) Ques(Bind(mm, members)) ]), - _TypedefActions~_primitive(id, tp, cs, ds, mm)) + _TypedefActions~_primitive(an, id, tp, cs, ds, mm)) fun ref _build_typedef_alias() => let kwd_type = _keyword(ast.Keywords.kwd_type()) let kwd_is = _keyword(ast.Keywords.kwd_is()) + let alias_ann = Variable("alias_ann") let alias_id = Variable("alias_id") let alias_tparams = Variable("alias_tparams") let alias_type = Variable("alias_type") @@ -295,6 +298,7 @@ class TypedefBuilder typedef_alias.set_body( Conj( [ kwd_type + Ques(Bind(alias_ann, _expression.annotation)) Bind(alias_id, _token.identifier) Ques(Bind(alias_tparams, _type_type.params)) kwd_is @@ -302,7 +306,7 @@ class TypedefBuilder Ques(Bind(alias_doc_string, doc_string)) ]), _TypedefActions~_alias( - alias_id, alias_tparams, alias_type, alias_doc_string)) + alias_ann, alias_id, alias_tparams, alias_type, alias_doc_string)) fun ref _build_typedef_class() => let at = _token(ast.Tokens.at()) diff --git a/eohippus/test/_test_setup.pony b/eohippus/test/_test_setup.pony index 977783f..bc7ac81 100644 --- a/eohippus/test/_test_setup.pony +++ b/eohippus/test/_test_setup.pony @@ -9,7 +9,7 @@ class _TestSetup let builder: parser.Builder val let data: parser.Data - new create(name: String) => + new iso create(name: String) => context = parser.Context(recover Array[types.AstPackage val] end) builder = recover val parser.Builder(context) end data = parser.Data(name)