Skip to content

Commit

Permalink
Merge 1da5a82 into 5fddf69
Browse files Browse the repository at this point in the history
  • Loading branch information
renatahodovan committed Mar 13, 2023
2 parents 5fddf69 + 1da5a82 commit 29e04c5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/grammars/Listeners.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Renata Hodovan, Akos Kiss.
*
* Licensed under the BSD 3-Clause License
* <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
* This file may not be copied, modified, or distributed except
* according to those terms.
*/

/*
* This test checks whether DefaultListener and DispatchingListener
* work as expected.
*/

// TEST-PROCESS: {grammar}.g4 -o {tmpdir}
// TEST-GENERATE: {grammar}Generator.{grammar}Generator -r start -j 1 -n 5 --listener grammarinator.runtime.DefaultListener -o {tmpdir}/{grammar}%d.txt
// TEST-GENERATE: {grammar}Generator.{grammar}Generator -r start -j 1 -n 5 --listener ListenersGenerator.CustomListener -o {tmpdir}/{grammar}%d.txt

grammar Listeners;

@header {
from grammarinator.runtime import DispatchingListener
class CustomListener(DispatchingListener):
def __init__(self):
self.enter_cnt = 0
self.exit_cnt = 0
def enter_a(self, node):
self.enter_cnt += 1
def exit_a(self, node):
self.exit_cnt += 1
def enter_b(self, node):
self.enter_cnt += 1
def exit_b(self, node):
self.exit_cnt += 1
def exit_start(self, node):
assert self.enter_cnt == 1, self.enter_cnt
assert self.exit_cnt == 1, self.exit_cnt
}


start : a | b;
a : A ;
b : B ;

A : 'a' ;
B : 'b' ;

0 comments on commit 29e04c5

Please sign in to comment.