Exemplo n.º 1
0
    def test_holereachability11(self):
        lang = DefineLanguage('Lang', [
            DefineLanguage.NtDefinition(Nt('n', 'n'), [
                BuiltInPat(BuiltInPatKind.Number, 'number', 'number'),
            ]),
            DefineLanguage.NtDefinition(Nt('P', 'P'), [
                PatSequence([Nt('E', 'E_0')]),
            ]),
            DefineLanguage.NtDefinition(Nt('E', 'E'), [
                Nt('P', 'P_1'),
                PatSequence([
                    Repeat(PatSequence([
                        Nt('P', 'P'),
                    ])),
                    PatSequence([]),
                ]),
                BuiltInPat(BuiltInPatKind.Hole, 'hole', 'hole'),
            ]),
        ])

        graph = NtGraphBuilder(lang).run()
        DefineLanguage_HoleReachabilitySolver(lang, graph).run()
        self.assertEqual(result(lang, 'n'),
                         (NumberOfHoles.Zero, NumberOfHoles.Zero))
        self.assertEqual(result(lang, 'E'),
                         (NumberOfHoles.Zero, NumberOfHoles.Many))
        self.assertEqual(result(lang, 'P'),
                         (NumberOfHoles.Zero, NumberOfHoles.Many))
Exemplo n.º 2
0
    def test_holereachability1(self):
        lang = DefineLanguage('Lang', [
            DefineLanguage.NtDefinition(Nt('P', 'P'), [
                PatSequence([Nt('E', 'E_0')]),
            ]),
            DefineLanguage.NtDefinition(Nt('E', 'E'), [
                Nt('P', 'P_1'),
            ]),
        ])

        graph = NtGraphBuilder(lang).run()
        DefineLanguage_HoleReachabilitySolver(lang, graph).run()
        self.assertEqual(result(lang, 'E'),
                         (NumberOfHoles.Zero, NumberOfHoles.Zero))
        self.assertEqual(result(lang, 'P'),
                         (NumberOfHoles.Zero, NumberOfHoles.Zero))
Exemplo n.º 3
0
    def test_holereachability19(self):
        lang = DefineLanguage('Lang', [
            DefineLanguage.NtDefinition(Nt('P', 'P'), [
                PatSequence([Nt('E', 'E_0')]),
            ]),
            DefineLanguage.NtDefinition(Nt('E', 'E'), [
                PatSequence([Lit(44, LitKind.Integer)]),
                BuiltInPat(BuiltInPatKind.Hole, 'hole', 'hole'),
            ]),
        ])

        graph = NtGraphBuilder(lang).run()
        DefineLanguage_HoleReachabilitySolver(lang, graph).run()
        self.assertEqual(result(lang, 'E'),
                         (NumberOfHoles.Zero, NumberOfHoles.One))
        self.assertEqual(result(lang, 'P'),
                         (NumberOfHoles.Zero, NumberOfHoles.One))
Exemplo n.º 4
0
    def test_patternnumholes0(self):
        lang = DefineLanguage('Lang', [
            DefineLanguage.NtDefinition(Nt('n', 'n'), [
                BuiltInPat(BuiltInPatKind.Number, 'number', 'number'),
            ]),
            DefineLanguage.NtDefinition(Nt('P', 'P'), [
                PatSequence([Nt('E', 'E')]),
            ]),
            DefineLanguage.NtDefinition(Nt('E', 'E'), [
                PatSequence([Nt('E', 'E'), Nt('n', 'n')]),
                BuiltInPat(BuiltInPatKind.Hole, 'hole', 'hole'),
            ]),
        ])

        graph = NtGraphBuilder(lang).run()
        DefineLanguage_HoleReachabilitySolver(lang, graph).run()
        pat = PatSequence([Repeat(Nt('E', 'E'))])
        nmin, nmax = PatternNumHolesChecker(lang, pat).run()
        self.assertEqual(nmin, NumberOfHoles.Zero)
        self.assertEqual(nmax, NumberOfHoles.Many)

        pat = PatSequence([Nt('P', 'P'), Repeat(Nt('E', 'E'))])
        nmin, nmax = PatternNumHolesChecker(lang, pat).run()
        self.assertEqual(nmin, NumberOfHoles.One)
        self.assertEqual(nmax, NumberOfHoles.Many)

        pat = PatSequence([Repeat(InHole(Nt('E', 'E'), Nt('n', 'n')))])
        nmin, nmax = PatternNumHolesChecker(lang, pat).run()
        self.assertEqual(nmin, NumberOfHoles.Zero)
        self.assertEqual(nmax, NumberOfHoles.Zero)

        pat = PatSequence([Nt('P', 'P'), Nt('n', 'n'), Nt('E', 'E')])
        nmin, nmax = PatternNumHolesChecker(lang, pat).run()
        self.assertEqual(nmin, NumberOfHoles.Many)
        self.assertEqual(nmax, NumberOfHoles.Many)

        pat = PatSequence([
            Nt('n', 'n'),
            BuiltInPat(BuiltInPatKind.Number, 'number', 'number'),
            BuiltInPat(BuiltInPatKind.Hole, 'hole', 'hole')
        ])
        nmin, nmax = PatternNumHolesChecker(lang, pat).run()
        self.assertEqual(nmin, NumberOfHoles.One)
        self.assertEqual(nmax, NumberOfHoles.One)
Exemplo n.º 5
0
    def test_holereachability12(self):
        lang = DefineLanguage('Lang', [
            DefineLanguage.NtDefinition(Nt('n', 'n'), [
                BuiltInPat(BuiltInPatKind.Number, 'number', 'number'),
            ]),
            DefineLanguage.NtDefinition(Nt('P', 'P'), [
                PatSequence([Nt('E', 'E_0')]),
            ]),
            DefineLanguage.NtDefinition(Nt('E', 'E'), [
                Nt('P', 'P_1'),
                InHole(Nt('P', 'P'), Nt('n', 'n')),
                BuiltInPat(BuiltInPatKind.Hole, 'hole', 'hole'),
            ]),
        ])

        try:
            graph = NtGraphBuilder(lang).run()
            DefineLanguage_HoleReachabilitySolver(lang, graph).run()
            self.fail()
        except CompilationError as ex:
            self.assertEqual(str(ex), 'in-hole pattern in define-language')