# Main module, used to generate the lexer parser file (parser.yy.jl usually)

include("lexer.jl")
include("slr.jl")
include("lexerparser.inc.jl")
include("lexer_template.jl")

function generate(io, regs, tokens, prods, produce_rules)
    parserdir = dirname(@__FILE__)
    # Header
    src_header = "# This file is generated by the lexer-parser, do not modify"
    println(io, src_header)

    # Includes
    src_include = read("$parserdir/lexerparser.inc.jl", String)
    println(io, src_include)

    # Lexer
    generate_lexer(io, regs)

    # Parser
    generate_parser(io, tokens, prods, produce_rules)

    # Main function
    src_parse = read("$parserdir/lexerparser_template.jl", String)
    print(io, src_parse)
end
