本文整理匯總了TypeScript中@masala/parser.C類的典型用法代碼示例。如果您正苦於以下問題:TypeScript C類的具體用法?TypeScript C怎麽用?TypeScript C使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了C類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: combinator
function combinator() {
return C.letters()
.then(C.char(' '))
.then(C.lowerCase().rep())
.then(C.char(' '))
.then(C.notString('romane').rep())
.then(F.eos());
}
示例2: blank
function blank(){
return C.char(' ').rep().thenReturns(' ');
}
示例3: optAlternative
function optAlternative() {
return C.string('xyz').opt()
}
示例4: emptyTry
function emptyTry() {
return F.try(C.string('xyz'));
}
示例5:
const separator = () => C.string('---');
示例6: assertEquals
import {Streams, F, C, N} from '@masala/parser'
import {assertEquals, assertFalse, assertTrue} from '../../assert';
let response = C.char('a').rep().parse(Streams.ofString('aaaa'));
assertEquals(response.value.join(''), 'aaaa' );
assertEquals(response.offset, 4 )
assertTrue(response.isAccepted());
assertTrue(response.isConsumed());
// Partially accepted
response = C.char('a').rep().parse(Streams.ofString('aabb'));
assertEquals(response.value.join(''), 'aa' );
assertEquals(response.offset, 2 )
assertTrue(response.isAccepted());
assertFalse(response.isConsumed());
示例7: anyOperation
function anyOperation() {
return C.string('*').thenReturns(MULT)
.or(C.string('+').thenReturns(PLUS));
}
示例8: day
function day() {
return C.stringIn(['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY']);
}
示例9:
import {assertEquals, assertTrue} from '../../assert';
import {Streams, F, C, N} from '@masala/parser'
let stream= Streams.ofString('|4.6|');
const floorCombinator = C.char('|').drop()
.then(N.numberLiteral()) // we have ['|',4.6], we keep 4.6
.then(C.char('|').drop()) // we have [4.6, '|'], we keep 4.6
.map(x =>Math.floor(x));
// Parsec needs a stream of characters
let parsing = floorCombinator.parse(stream);
assertEquals( 4, parsing.value, 'Floor parsing');
示例10: B
/**
* There is recursion, and we call A with lazy. We send PARAMETERS to A
* within an array
*/
function B(aVal) {
return C.char('B').map(bVal=> aVal.join('')+'-'+bVal).or(F.lazy(A, ['a']));
}