Program used to test the NIT parser

Redefined classes

redef class Sys

nitc :: test_parser $ Sys

The main class of the program.

All class definitions

redef class Sys

nitc :: test_parser $ Sys

The main class of the program.
package_diagram nitc::test_parser test_parser nitc::parser_util parser_util nitc::test_parser->nitc::parser_util nitc::astutil astutil nitc::test_parser->nitc::astutil nitc\>parser\> parser nitc::parser_util->nitc\>parser\> nitc::toolcontext toolcontext nitc::parser_util->nitc::toolcontext nitc::astutil->nitc\>parser\> html html nitc::astutil->html ...nitc\>parser\> ... ...nitc\>parser\>->nitc\>parser\> ...nitc::toolcontext ... ...nitc::toolcontext->nitc::toolcontext ...html ... ...html->html a_star-m a_star-m a_star-m->nitc::test_parser

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module html

html :: html

HTML output facilities
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module astutil

nitc :: astutil

Additional features on Nit AST
module parser_util

nitc :: parser_util

Utils and tools related to parsers and AST

Children

module a_star-m

a_star-m

# Program used to test the NIT parser
module test_parser

import parser
import parser_util
import astutil

var no_print = false
var only_lexer = false
var need_help = false
var no_file = false
var interactive = false
var xml = false

while not args.is_empty and args.first.chars.first == '-' do
	if args.first == "-n" then
		no_print = true
	else if args.first == "-l" then
		only_lexer = true
	else if args.first == "-p" then
		only_lexer = false
	else if args.first == "-x" then
		xml = true
	else if args.first == "-e" then
		no_file = true
	else if args.first == "-i" then
		interactive = true
	else if args.first == "-h" or args.first == "-?" then
		need_help = true
	else
		stderr.write("Unknown option {args.first}.\n")
		exit(0)
	end
	args.shift
end

if (args.is_empty and not interactive) or need_help then
	print("usage:")
	print("  test_parser [options]... <filename.nit>...")
	print("  test_parser -e [options]... <text>...")
	print("  test_parser -i [options]...")
	print("options:")
	print("  -n	do not print anything")
	print("  -l	only lexer")
	print("  -p	lexer and parser (default)")
	print("  -x	instead of a ascii tree, output a XML document")
	print("  -e	instead on files, each argument is a content to parse")
	print("  -i	tree to parse are read interactively")
	print("  -h	print this help")
else if interactive then
	if only_lexer then
		print "Error: -l and -i are incompatible"
		exit 1
	else if no_file then
		print "Error: -e and -i are incompatible"
		exit 1
	else if not args.is_empty then
		print "Error: -i works without arguments"
		exit 1
	end

	var tc = new ToolContext

	loop
		var n = tc.interactive_parse("-->")
		if n isa TString then
			var s = n.text
			if s == ":q" then
				break
			else
				print "`:q` to quit"
			end
			continue
		end

		if n isa AError then
			print "{n.location.colored_line("0;31")}: {n.message}"
			continue
		end

		if not no_print then
			n.dump_tree
		end
	end
else
	for a in args do
		var source
		if no_file then
			source = new SourceFile.from_string("", a)
		else
			var f = new FileReader.open(a)
			source = new SourceFile(a, f)
			f.close
		end
		var lexer = new Lexer(source)
		if only_lexer then
			var token = lexer.next
			while not token isa EOF do
				if not no_print then
					print("Read token at {token.location} text='{token.text}'")
				end
				token = lexer.next
			end
		else
			var parser = new Parser(lexer)
			var tree = parser.parse

			var error = tree.n_eof
			if error isa AError then
				print("Error at {error.location}:\n\t{error.message}")
				return
			end

			if xml then
				tree.parentize_tokens
				tree.to_xml.write_to(stdout)
			else if not no_print then
				tree.dump_tree
			end
		end
	end
end
src/test_parser.nit:17,1--138,3