Beispiel #1
0
import os.path
import sys

import libfoolang

print('main.py: Running...')

ctx = libfoolang.AnalysisContext()


def parse_unit(filename, src_buffer):
    u = ctx.get_from_buffer(filename, src_buffer)
    if u.diagnostics:
        for d in u.diagnostics:
            print('{}: {}'.format(filename, d))
        sys.exit(1)
    return u


u1 = parse_unit('src1.txt', b'example\nexample')
u2 = parse_unit('src2.txt', b'example')

root = u1.root
u1_ex1, u1_ex2 = u1.root
u2_ex = u2.root


def fmt_node(n):
    return ('None' if n is None else '<{} {}:{}>'.format(
        n.kind_name, os.path.basename(n.unit.filename),
        n.sloc_range.start.line))
Beispiel #2
0
from collections import namedtuple

import libfoolang

print('main.py: Running...')

ctx = libfoolang.AnalysisContext('iso-8859-1')
u = ctx.get_from_buffer('foo.txt', b'')


def get_from_buffer(buffer, charset):
    ctx.get_from_buffer('foo.txt', buffer, charset)


def reparse(buffer, charset):
    u.reparse(buffer, charset)


# Check that get_from_buffer/reparse correctly process buffer/charset
# arguments:
#
# * either buffer is a bytes string, then the charset argument (if provided) or
#   the context-wide charset (iso-8859-1, see above) is used to decode it.
#
# * either buffer is a Unicode string, then the charset argument must be null
#   (None or empty string).

Testcase = namedtuple('Testcase', 'buffer charset')

testcases = [
    Testcase(u'example # H\xe9llo', None),
Beispiel #3
0
from __future__ import absolute_import, division, print_function

print('main.py: Running...')

import sys

import libfoolang

u = libfoolang.AnalysisContext().get_from_buffer('main.txt', 'example')
if u.diagnostics:
    for d in u.diagnostics:
        print(d)
    sys.exit(1)

e = u.root[0]
s1 = e.p_get_struct
s2 = e.p_struct_identity(
    libfoolang.MyStruct(entity_field=s1.entity_field,
                        array_field=[],
                        bigint_field=2))

for name, s in [('First struct', s1), ('Second struct', s2)]:
    print('{}:'.format(name))
    print('s.entity_field = {}'.format(s.entity_field))
    print('s.array_field = {}'.format(s.array_field))
    print('s.bigint_field = {}'.format(s.bigint_field))
    print('')

print('main.py: Done.')
print('')
Beispiel #4
0
import libfoolang as lfl

ctx = lfl.AnalysisContext()
u = ctx.get_from_buffer("test", "example")
print(u.root.p_example_holders)