コード例 #1
0
def invalidIdentTest():
    src = '0xef'
    try:
        tokenize(src)
    except ParserException:
        return
    assert 0 == 1
コード例 #2
0
def parse(src):
    tokens = tokenize(src)
    success, unparsed, declarations = parseDeclarations(tokens)
    if not success:
        raise ParserException(
            'not a declaration: invalid token {} in line {}'.format(
                unparsed[0], unparsed[0].getLineNumber()))
    return declarations
コード例 #3
0
def exampleDeclarationTest():
    src = '''
    # This is an example declaration
    ({q0, q1}, "a") -> (q1, "b", R)
    '''
    tokens = tokenize(src)
    assert len([t for t in tokens if isinstance(t, ControlToken)]) == 11
    assert len([t for t in tokens if isinstance(t, IdentToken)]) == 4
    assert len([t for t in tokens if isinstance(t, StringToken)]) == 2
コード例 #4
0
def whitespaceTest():
    src = '   \n \n\n    \t   \n\t   '
    tokens = tokenize(src)
    assert len(tokens) == 0
コード例 #5
0
def controlTest():
    src = '( } , -> ) {'
    tokens = tokenize(src)
    assert len(tokens) == 6
    for token in tokens:
        assert isinstance(token, ControlToken)
コード例 #6
0
def stringTest():
    src = '"hello" "\\" my" "world ###"'
    tokens = tokenize(src)
    assert len(tokens) == 3
    for token in tokens:
        assert isinstance(token, StringToken)
コード例 #7
0
def identTest():
    src = 'q0 q1q2 q'
    tokens = tokenize(src)
    assert len(tokens) == 3
    for token in tokens:
        assert isinstance(token, IdentToken)
コード例 #8
0
def blockCommentTest():
    src = '### (}{) stuff\n more "stuff"\n\n () ###'
    tokens = tokenize(src)
    assert len(tokens) == 0
コード例 #9
0
def lineCommentTest():
    src = '# ## # ## (hello, "W") -> (o, ' r', L), d\n'
    tokens = tokenize(src)
    assert len(tokens) == 0