当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript C.char方法代码示例

本文整理汇总了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());
}
开发者ID:d-plaindoux,项目名称:parsec,代码行数:8,代码来源:letter-letterAs.ts

示例2: a

function a(){
    return C.char('a');
}
开发者ID:d-plaindoux,项目名称:parsec,代码行数:3,代码来源:nop-any-eos.ts

示例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");

开发者ID:d-plaindoux,项目名称:parsec,代码行数:24,代码来源:hello-something.ts

示例4: blank

function blank(){
    return C.char(' ').rep().thenReturns(' ');
}
开发者ID:d-plaindoux,项目名称:parsec,代码行数:3,代码来源:try-with-no-or.ts

示例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());
开发者ID:d-plaindoux,项目名称:parsec,代码行数:16,代码来源:response.ts

示例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
开发者ID:d-plaindoux,项目名称:parsec,代码行数:27,代码来源:test.ts

示例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');

开发者ID:d-plaindoux,项目名称:parsec,代码行数:14,代码来源:chars.ts

示例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');

开发者ID:d-plaindoux,项目名称:parsec,代码行数:16,代码来源:floor.ts

示例9: A

/**
 * A gives its VALUE to B using flatMap
 */
function A(char){
    return C.char(char.toUpperCase()).rep().flatMap(B);
}
开发者ID:d-plaindoux,项目名称:parsec,代码行数:6,代码来源:transmission.ts

示例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']));
}
开发者ID:d-plaindoux,项目名称:parsec,代码行数:7,代码来源:transmission.ts


注:本文中的@masala/parser.C.char方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。