public static Node?GetInitializer( this NeuInitClause initClause) { var puncReached = false; /// foreach (var c in initClause.Children) { switch (c) { case NeuPunc _ when !puncReached: // only toggle on a single punc puncReached = true; break; /// case Node _ when puncReached: return(c); /// default: continue; } } /// return(null); }
/// public static NeuOperation Execute( this NeuInterpreter interpreter, bool inGlobalScope, NeuKeyword kindKeyword, NeuIdentifierPattern idPattern, NeuInitClause initClause) { var id = idPattern.GetIdentifier(); if (id == null) { throw new Exception(); } /// var name = id.Source; if (IsNullOrWhiteSpace(name)) { throw new Exception(); } /// var initializer = initClause.GetInitializer(); if (initializer == null) { throw new Exception(); } /// var initValue = interpreter.Execute(initializer); /// switch (true) { case var _ when inGlobalScope && kindKeyword.KeywordType == NeuKeywordType.Let: var globalScopedLet = interpreter.CreateVar(name, null, null, null, initValue); if (globalScopedLet == null) { throw new Exception(); } return(globalScopedLet); /// case var _ when inGlobalScope && kindKeyword.KeywordType == NeuKeywordType.Var: var globalScopedVar = interpreter.CreateVar(name, null, null, null, initValue); if (globalScopedVar == null) { throw new Exception(); } return(globalScopedVar); /// case var _ when kindKeyword.KeywordType == NeuKeywordType.Let: var hoistedLet = interpreter.HoistVar(kindKeyword.KeywordType, name, initValue); if (hoistedLet == null) { throw new Exception(); } return(hoistedLet); /// case var _ when kindKeyword.KeywordType == NeuKeywordType.Var: var hoistedVar = interpreter.HoistVar(kindKeyword.KeywordType, name, initValue); if (hoistedVar == null) { throw new Exception(); } return(hoistedVar); /// default: throw new Exception(); } }