# Path: pymake.py
# def comment(vchar_scanner):
# def depth_reset():
# def depth_checker(func):
# 	def check_depth(*args):
# def tokenize_statement(vchar_scanner):
# def tokenize_statement_LHS(vchar_scanner, separators=""):
# def tokenize_rule_prereq_or_assign(vchar_scanner):
# def tokenize_rule_RHS(vchar_scanner):
# 	def save_prereq(token_list):
# def tokenize_assign_RHS(vchar_scanner):
# def tokenize_variable_ref(vchar_scanner):
# def tokenize_recipe(vchar_scanner):
# def parse_recipes(line_scanner, semicolon_vline=None): 
# def seek_directive(s):
# 	def get_directive(s):
# def seek_elseif(virt_line):
# def handle_conditional_directive(directive_inst, vline_iter, line_scanner):
# 	def save_block(line_list):
# def tokenize_define_directive(vchar_scanner):
# def handle_define_directive(define_inst, vline_iter, vchar_scanner):
# def tokenize_directive(directive_str, virt_line, vline_iter, line_scanner):
# def tokenize(virt_line, vline_iter, line_scanner): 
# def parse_makefile_from_src(src):
# def parse_makefile(infilename) : 
# def round_trip(makefile):
# def find_pos(tok):
# def execute(makefile):
# def usage():
# 
# Path: scanner.py
# class ScannerIterator(object):
# 	# string iterator that allows look ahead and push back
# 	# can also push/pop state (for deep lookaheads)
# 	def __init__(self, data):
# 		logger.debug("ScannerIterator datalen=%d", len(data))
# 		self.data = data
# 		self.idx = 0
# 		self.max_idx = len(self.data)
# 		self.state_stack = []
# 
# 	def __iter__(self):
# 		return self
# 
# 	def next(self):
# 		return self.__next__()
# 
# 	def __next__(self):
# 		if self.idx >= self.max_idx:
# 			raise StopIteration
# 		self.idx += 1
# 		return self.data[self.idx-1]
# 
# 	def lookahead(self):
# 		if self.idx >= self.max_idx:
# 			return None
# #		print("lookahead={0}".format(self.data[self.idx]))
# 		return self.data[self.idx]
# 
# 	def pushback(self):
# 		if self.idx <= 0 :
# 			raise StopIteration
# 		self.idx -= 1
# 
# 	def push_state(self):
# 		self.state_stack.append(self.idx)
# #		print( "push stack=", self.state_stack )
# 
# 	def pop_state(self):
# #		print( "pop stack=", self.state_stack )
# 		self.idx = self.state_stack.pop()
# 
# 	def remain(self):
# 		# Test/debug method. Return what remains of the data.
# 		return self.data[self.idx:]
# 
# #	def stop(self):
# #		# truncate the iterator at the current position
# #		assert self.idx < self.max_idx, self.idx
# #
# #		# kill anything after the current position
# #		self.data = self.data[:self.idx]
# #		self.max_idx = len(self.data)
# 
# 	def lstrip(self):
# 		# strip left leading whitespace (like "".strip)
# 		try : 
# 			while str(self.data[self.idx]) in string.whitespace :
# 				self.next()
# 		except IndexError:
# 			raise StopIteration
# 
# 		# allow chaining
# 		return self
# 
# 	def eat(self, s):
# 		# consume a string from the leading part of the data
# 		# for example:  eat("hello") from "hello, world" will result in 
# 		# ", world"
# 		#
# 		# Requires the string be found in the data, like string's index method.
# 		# Requires the string start exactly at the current position.
# 
# 		errmsg = "\"{0}\" not found in {1}".format(s, self)
# 		for c in s :
# 			if self.idx >= self.max_idx:
# 				# full substring not found so error!
# 				raise ValueError(errmsg)
# 
# 			if str(self.data[self.idx]) == c :
# 				self.next()
# 			else :
# 				# full substring not found so error!
# 				raise ValueError(errmsg)
# 
# 		# allow chaining
# 		return self


import sys
import random
from pymake import get_vline
from scanner import ScannerIterator
#!/usr/bin/env python3

# test vline_iter and line_iter stay in sync


def iter_test(file_lines):
	line_iter = ScannerIterator(file_lines)
	vline_iter = get_vline(line_iter)

	while 1: 
		if random.choice((0,1)):
			s = next(line_iter)
		else : 
			s = next(vline_iter)
		yield s


# Path: pymake.py
# def comment(vchar_scanner):
# def depth_reset():
# def depth_checker(func):
# 	def check_depth(*args):
# def tokenize_statement(vchar_scanner):
# def tokenize_statement_LHS(vchar_scanner, separators=""):
# def tokenize_rule_prereq_or_assign(vchar_scanner):
# def tokenize_rule_RHS(vchar_scanner):
# 	def save_prereq(token_list):
# def tokenize_assign_RHS(vchar_scanner):
# def tokenize_variable_ref(vchar_scanner):
# def tokenize_recipe(vchar_scanner):
# def parse_recipes(line_scanner, semicolon_vline=None): 
# def seek_directive(s):
# 	def get_directive(s):
# def seek_elseif(virt_line):
# def handle_conditional_directive(directive_inst, vline_iter, line_scanner):
# 	def save_block(line_list):
# def tokenize_define_directive(vchar_scanner):
# def handle_define_directive(define_inst, vline_iter, vchar_scanner):
# def tokenize_directive(directive_str, virt_line, vline_iter, line_scanner):
# def tokenize(virt_line, vline_iter, line_scanner): 
# def parse_makefile_from_src(src):
# def parse_makefile(infilename) : 
# def round_trip(makefile):
# def find_pos(tok):
# def execute(makefile):
# def usage():
# 
# Path: scanner.py
# class ScannerIterator(object):
# 	# string iterator that allows look ahead and push back
# 	# can also push/pop state (for deep lookaheads)
# 	def __init__(self, data):
# 		logger.debug("ScannerIterator datalen=%d", len(data))
# 		self.data = data
# 		self.idx = 0
# 		self.max_idx = len(self.data)
# 		self.state_stack = []
# 
# 	def __iter__(self):
# 		return self
# 
# 	def next(self):
# 		return self.__next__()
# 
# 	def __next__(self):
# 		if self.idx >= self.max_idx:
# 			raise StopIteration
# 		self.idx += 1
# 		return self.data[self.idx-1]
# 
# 	def lookahead(self):
# 		if self.idx >= self.max_idx:
# 			return None
# #		print("lookahead={0}".format(self.data[self.idx]))
# 		return self.data[self.idx]
# 
# 	def pushback(self):
# 		if self.idx <= 0 :
# 			raise StopIteration
# 		self.idx -= 1
# 
# 	def push_state(self):
# 		self.state_stack.append(self.idx)
# #		print( "push stack=", self.state_stack )
# 
# 	def pop_state(self):
# #		print( "pop stack=", self.state_stack )
# 		self.idx = self.state_stack.pop()
# 
# 	def remain(self):
# 		# Test/debug method. Return what remains of the data.
# 		return self.data[self.idx:]
# 
# #	def stop(self):
# #		# truncate the iterator at the current position
# #		assert self.idx < self.max_idx, self.idx
# #
# #		# kill anything after the current position
# #		self.data = self.data[:self.idx]
# #		self.max_idx = len(self.data)
# 
# 	def lstrip(self):
# 		# strip left leading whitespace (like "".strip)
# 		try : 
# 			while str(self.data[self.idx]) in string.whitespace :
# 				self.next()
# 		except IndexError:
# 			raise StopIteration
# 
# 		# allow chaining
# 		return self
# 
# 	def eat(self, s):
# 		# consume a string from the leading part of the data
# 		# for example:  eat("hello") from "hello, world" will result in 
# 		# ", world"
# 		#
# 		# Requires the string be found in the data, like string's index method.
# 		# Requires the string start exactly at the current position.
# 
# 		errmsg = "\"{0}\" not found in {1}".format(s, self)
# 		for c in s :
# 			if self.idx >= self.max_idx:
# 				# full substring not found so error!
# 				raise ValueError(errmsg)
# 
# 			if str(self.data[self.idx]) == c :
# 				self.next()
# 			else :
# 				# full substring not found so error!
# 				raise ValueError(errmsg)
# 
# 		# allow chaining
# 		return self


# Path: test_iter.py
import sys
import random
from pymake import get_vline
from scanner import ScannerIterator

#!/usr/bin/env python3

# test vline_iter and line_iter stay in sync


def iter_test(file_lines):
	line_iter = ScannerIterator(file_lines)
	vline_iter = get_vline(line_iter)

	while 1: 
		if random.choice((0,1)):
			s = next(line_iter)
		else : 
			s = next(vline_iter)
		yield s


def iter_test_filename(infilename):