當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Op.caseOp函數代碼示例

本文整理匯總了TypeScript中op/Op.caseOp函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript caseOp函數的具體用法?TypeScript caseOp怎麽用?TypeScript caseOp使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了caseOp函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parseClass

/** Parse a [[Class]]. */
export default function parseClass(tokens: Tokens): Class {
	const [before, opBlock] = beforeAndOpBlock(tokens)
	const {opFields, opSuperClass, traits} = parseClassHeader(before)
	type Tuple = [Op<string>, Op<ClassTraitDo>,
		Array<MethodImplLike>, Op<Constructor>, Array<MethodImplLike>]
	const [opComment, opDo, statics, opConstructor, methods] = caseOp<Lines, Tuple>(
		opBlock,
		_ => {
			const [opComment, rest] = tryTakeComment(_)
			if (rest.isEmpty())
				return [opComment, null, [], null, []]
			const [opDo, rest2] = opTakeDo(rest)
			if (rest2.isEmpty())
				return [opComment, opDo, [], null, []]
			const [statics, rest3] = takeStatics(rest2)
			if (rest3.isEmpty())
				return [opComment, opDo, statics, null, []]
			const [opConstructor, rest4] = opTakeConstructor(rest3)
			return [opComment, opDo, statics, opConstructor, parseMethodImpls(rest4)]
		},
		() => [null, null, [], null, []])
	return new Class(
		tokens.loc,
		opFields, opSuperClass, traits, opComment, opDo, statics, opConstructor, methods)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:26,代碼來源:parseClass.ts

示例2: verifyModuleLines

function verifyModuleLines(lines: Array<LineContent>, loc: Loc): void {
	results.moduleKind = caseOp(
		opBlockBuildKind(lines, loc),
		buildKind => {
			if (buildKind === Blocks.Obj) {
				for (const line of lines)
					if (line instanceof ObjEntry)
						results.objEntryExports.add(line)
				verifyLines(lines)
				return Modules.Exports
			} else {
				verifyBuiltLines(lines, loc)
				return buildKind === Blocks.Bag ? Modules.Bag : Modules.Map
			}
		},
		() => {
			if (isEmpty(lines))
				return Modules.Do
			else {
				const l = last(lines)
				const lastSK = getLineSK(l)
				if (lastSK === SK.Do) {
					verifyLines(lines)
					return Modules.Do
				} else {
					const newLocals = verifyLines(rtail(lines))
					plusLocals(newLocals, () => ensureValAndVerify(l))
					return Modules.Val
				}
			}
		})
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:32,代碼來源:verifyModule.ts

示例3: ArrayExpression

		new ArrayExpression(value.args.map((arg: LocalDeclare) => {
			const name = new LiteralString(arg.name)
			return caseOp<Val, Expression>(
				arg.opType,
				_ => new ArrayExpression([name, transpileVal(_)]),
				() => name)
		})) :
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:7,代碼來源:transpilePoly.ts

示例4: transpileFunNoLoc

export function transpileFunNoLoc(_: Fun): Expression {
	if (_ instanceof FunBlock)
		return transpileFunBlockNoLoc(_)

	else if (_ instanceof FunGetter)
		// _ => _.foo
		return focusFun(transpileMember(idFocus, _.name))

	else if (_ instanceof FunMember) {
		const {opObject, name} = _
		const nameAst = transpileMemberName(name)
		return caseOp(
			opObject,
			_ => msCall('methodBound', transpileVal(_), nameAst),
			() => msCall('methodUnbound', nameAst))

	} else if (_ instanceof FunOperator)
		return transpileFunOperatorNoLoc(_)

	else if (_ instanceof FunSimple)
		return focusFun(transpileVal(_.value))

	else if (_ instanceof FunUnary)
		return transpileFunUnaryNoLoc(_)

	else
		throw new Error(_.constructor.name)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:28,代碼來源:transpileFun.ts

示例5: transpileSwitchVDNoLoc

function transpileSwitchVDNoLoc({switched, parts, opElse}: Switch, isDo: boolean): Statement {
	const partAsts = flatMap(parts, _ => transpileSwitchPart(_, isDo))
	partAsts.push(caseOp(
		opElse,
		_ => loc(_, new SwitchCase(null, transpileBlock(_).body)),
		() => switchCaseNoMatch))
	return new SwitchStatement(transpileVal(switched), partAsts)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:8,代碼來源:transpileSwitch.ts

示例6: parseObjSimple

export default function parseObjSimple(tokens: Tokens): Val {
	const pairs = caseOp(
		tokens.opSplitMany(_ => isKeyword(Kw.ObjEntry, _)),
		_ => complexPairs(tokens.loc, _),
		// Parse 'pairs' like in `{a b}` (equivalent to `{a. a b. b}`),
		// where every pair is a single identifier.
		() => tokens.map(simplePair))
	return new ObjSimple(tokens.loc, pairs)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:9,代碼來源:parseObjSimple.ts

示例7: parseIteratee

function parseIteratee(tokens: Tokens): Iteratee {
	const [element, bag]: any = caseOp<{before: Tokens, after: Tokens}, [LocalDeclare, Val]>(
		tokens.opSplitOnce(_ => isKeyword(Kw.Of, _)),
		({before, after}) => {
			check(before.size() === 1, before.loc, _ => _.todoForPattern)
			return [parseLocalDeclaresJustNames(before)[0], parseExpr(after)]
		},
		() => [LocalDeclare.focus(tokens.loc), parseExpr(tokens)])
	return new Iteratee(tokens.loc, element, bag)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:10,代碼來源:parseFor.ts

示例8: transpileTraitNoLoc

export function transpileTraitNoLoc(_: Trait): Expression {
	const {superTraits, opDo, statics, methods} = _
	const name = new LiteralString(verifyResults.name(_))
	const supers = new ArrayExpression(superTraits.map(transpileVal))
	const trait = msCall('trait', name, supers, methodsObject(statics), methodsObject(methods))
	return caseOp(
		opDo,
		_ => transpileBlockVal(_.block, {lead: plainLet(idFocus, trait), follow: returnFocus}),
		() => trait)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:10,代碼來源:transpileTrait.ts

示例9: verifyLoop

export default function verifyLoop(_: For | ForBag, sk: SK): void {
	const {opIteratee, block} = _
	function verifyBlock(): void {
		withLoop({loop: _, sk}, () => verifyBlockDo(block))
	}
	caseOp(
		opIteratee,
		_ => withVerifyIteratee(_, verifyBlock),
		verifyBlock)
}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:10,代碼來源:verifyLoop.ts

示例10: accessBuiltin

	accessBuiltin(name: string, path: string): void {
		caseOp(
			this.builtinPathToNames.get(path),
			_ => {
				_.add(name)
			},
			() => {
				this.builtinPathToNames.set(path, new Set([name]))
			})
	}
開發者ID:mason-lang,項目名稱:mason-lang.github.io,代碼行數:10,代碼來源:VerifyResults.ts


注:本文中的op/Op.caseOp函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。