本文整理汇总了TypeScript中@masala/parser.C.char方法的典型用法代码示例。如果您正苦于以下问题:TypeScript C.char方法的具体用法?TypeScript C.char怎么用?TypeScript C.char使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@masala/parser.C
的用法示例。
在下文中一共展示了C.char方法的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());
}
示例3:
import {Streams, F, C, N} from '@masala/parser'
import {assertEquals, assertArrayEquals, assertTrue} from '../../assert';
const helloParser = C.string("Hello")
.then(C.char(' ').rep())
.then(C.char("'")).drop()
.then(C.letter().rep()) // keeping repeated ascii letters
.then(C.char("'").drop()); // keeping previous letters
const parsing = helloParser.parse(Streams.ofString("Hello 'World'"));
// C.letter.rep() will giv a array of letters
let x = parsing.value.array();
assertArrayEquals(['W','o','r','l','d'], parsing.value.array(), "Hello World joined");
// Note that helloParser will not reach the end of the stream; it will stop at the space after People
const peopleParsing = helloParser.parse(Streams.ofString("Hello 'People' in 2017"));
assertEquals("People", peopleParsing.value.join(''), "Hello People joined");
assertTrue(peopleParsing.offset < "Hello People in 2017".length, "Bad Offset for Hello People");
示例4: blank
function blank(){
return C.char(' ').rep().thenReturns(' ');
}
示例5: 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());
示例6: assertArrayEquals
import {C, F, Streams} from '@masala/parser'
import{assertArrayEquals, assertEquals, assertTrue} from './assert';
let stream = Streams.ofString('ab');
let parser = C.char('a');
let arrayParser = parser.then(C.char('b'));
let parsing = arrayParser.parse(stream);
assertArrayEquals(['a', 'b'], parsing.value) ; //compiling, types are almost OK
parser = C.char('a');
let charParsing = parser.parse(Streams.ofString('a'));
let charParsingValue = charParsing.value;
assertTrue(charParsingValue === 'a');
let singleParsing = parser.parse(stream);
assertTrue( 'a' === singleParsing.value); //compiling, types are almost OK
parser = C.char('a');
singleParsing = parser.parse(stream);
assertEquals( 'a' , singleParsing.value); //compiling, types are almost OK
示例7: assertEquals
import {Streams, F, C, N} from '@masala/parser'
import {assertEquals} from '../../assert';
/**
* Created by Nicolas Zozol on 05/11/2017.
*/
const stream = Streams.ofString('abc');
const charsParser = C.char('a')
.then(C.char('b'))
.then(C.char('c'))
.then(F.eos().drop()); // End Of Stream ; droping its value, just checking it's here
let charsParsing = charsParser.parse(stream);
assertEquals('abc', charsParsing.value.join(''), 'Chars parsing');
示例8:
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');
示例9: A
/**
* A gives its VALUE to B using flatMap
*/
function A(char){
return C.char(char.toUpperCase()).rep().flatMap(B);
}
示例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']));
}