def AaParse.expand

bend-osdev-apparmor@0.1.0.0 · parse.bend:424

import bend-osdev-apparmor@0.1.0.0/parse.bend as Parse
import Base

424# the items with every include replaced by the included file's items;
425# scopes: the files included so far in each open block, innermost first
426def AaParse.expand(+fuel: Nat, items: List<&2, AaItem>, +files: List<&2, AaSrcFile>, +scopes: List<&2, List<&2, List<&2, U32>>>, +acc: List<&2, AaItem>) -> AaExpOut:
427  match fuel:
428    case 0n:
429      AaParse.expand0(items, scopes, acc)
430    case 1n+f:
431      match items:
432        case Nil{}:
433          AaExpOut{AaItem.rev_onto(acc, Nil{}), scopes}
434        case Con{it, +rest}:
435          match it:
436            case AaIOpen{ts, src}:
437              AaParse.expand(fuel, rest, files, Con{Nil{}, scopes}, Con{AaIOpen{ts, src}, acc})
438            case AaIClose{src}:
439              AaParse.expand(fuel, rest, files, AaParse.pop(scopes), Con{AaIClose{src}, acc})
440            case AaIInclude{+name, opt, +src}:
441              # Bend evaluates both arms of a Bool.pick, so the recursion is
442              # one call whose arguments depend on whether the file is seen
443              +seen = AaParse.seen(scopes, name)
444              +sub = AaParse.expand(f, AaParse.inc_items(Bool.pick(Maybe<&2, AaSrcFile>, seen, None{}, AaParse.find_file(files, name)), Bool.or(seen, opt), src), files, AaParse.mark(scopes, name), Nil{})
445              AaParse.expand(fuel, rest, files, Bool.pick(List<&2, List<&2, List<&2, U32>>>, seen, scopes, AaExpOut.scopes(sub)), Bool.pick(List<&2, AaItem>, seen, acc, AaItem.rev_onto(AaExpOut.items(sub), acc)))
446            case AaIStmt{ts, src}:
447              AaParse.expand(fuel, rest, files, scopes, Con{AaIStmt{ts, src}, acc})
448            case AaIVar{ts, src}:
449              AaParse.expand(fuel, rest, files, scopes, Con{AaIVar{ts, src}, acc})
450            case AaIError{e}:
451              AaParse.expand(fuel, rest, files, scopes, Con{AaIError{e}, acc})

Uses (18)

Used by (1)