Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass StandardError instead of Exception. #8

Merged
merged 1 commit into from Mar 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README
Expand Up @@ -271,8 +271,8 @@ If the input (including the +ERROR+ token) can be reduced immediately the associ


The example below for the unit tests shows a very basic usage of error productions: The example below for the unit tests shows a very basic usage of error productions:


class AfterPlsError < Exception; end class AfterPlsError < StandardError; end
class AfterSubError < Exception; end class AfterSubError < StandardError; end


class ErrorCalc < RLTK::Parser class ErrorCalc < RLTK::Parser
production(:e) do production(:e) do
Expand Down
16 changes: 8 additions & 8 deletions lib/rltk/ast.rb
Expand Up @@ -6,7 +6,7 @@
module RLTK # :nodoc: module RLTK # :nodoc:
# A TypeMismatch is thrown when an object being set as a child or value of # A TypeMismatch is thrown when an object being set as a child or value of
# an ASTNode is of the wrong type. # an ASTNode is of the wrong type.
class TypeMismatch < Exception class TypeMismatch < StandardError


# Instantiates a new TypeMismatch object. The first argument is the # Instantiates a new TypeMismatch object. The first argument is the
# expected type and the second argument is the actual type of the # expected type and the second argument is the actual type of the
Expand Down Expand Up @@ -62,13 +62,13 @@ def self.child(name, type)
t = type t = type


else else
raise Exception, 'Child and Value types must be a class name or an array with a single class name element.' raise 'Child and Value types must be a class name or an array with a single class name element.'
end end


# Check to make sure that type is a subclass of # Check to make sure that type is a subclass of
# ASTNode. # ASTNode.
if not RLTK::subclass_of?(t, ASTNode) if not RLTK::subclass_of?(t, ASTNode)
raise Exception, "A child's type specification must be a subclass of ASTNode." raise "A child's type specification must be a subclass of ASTNode."
end end


@child_names << name @child_names << name
Expand Down Expand Up @@ -152,13 +152,13 @@ def self.value(name, type)
t = type t = type


else else
raise Exception, 'Child and Value types must be a class name or an array with a single class name element.' raise 'Child and Value types must be a class name or an array with a single class name element.'
end end


# Check to make sure that type is NOT a subclass of # Check to make sure that type is NOT a subclass of
# ASTNode. # ASTNode.
if RLTK::subclass_of?(t, ASTNode) if RLTK::subclass_of?(t, ASTNode)
raise Exception, "A value's type specification must NOT be a subclass of ASTNode." raise "A value's type specification must NOT be a subclass of ASTNode."
end end


@value_names << name @value_names << name
Expand Down Expand Up @@ -201,7 +201,7 @@ def children
# Assigns an array of AST nodes as the children of this node. # Assigns an array of AST nodes as the children of this node.
def children=(children) def children=(children)
if children.length != self.class.child_names.length if children.length != self.class.child_names.length
raise Exception, 'Wrong number of children specified.' raise 'Wrong number of children specified.'
end end


self.class.child_names.each_with_index do |name, i| self.class.child_names.each_with_index do |name, i|
Expand Down Expand Up @@ -247,7 +247,7 @@ def has_note?(key)
# the order they were declared). # the order they were declared).
def initialize(*objects) def initialize(*objects)
if self.class == RLTK::ASTNode if self.class == RLTK::ASTNode
raise Exception, 'Attempting to instantiate the RLTK::ASTNode class.' raise 'Attempting to instantiate the RLTK::ASTNode class.'
else else
@notes = Hash.new() @notes = Hash.new()
@parent = nil @parent = nil
Expand Down Expand Up @@ -277,7 +277,7 @@ def values
# Assigns an array of objects as the values of this node. # Assigns an array of objects as the values of this node.
def values=(values) def values=(values)
if values.length != self.class.value_names.length if values.length != self.class.value_names.length
raise Exception, 'Wrong number of values specified.' raise 'Wrong number of values specified.'
end end


self.class.value_names.each_with_index do |name, i| self.class.value_names.each_with_index do |name, i|
Expand Down
2 changes: 1 addition & 1 deletion lib/rltk/cfg.rb
Expand Up @@ -21,7 +21,7 @@ module RLTK # :nodoc:


# An exception class that represents a problem with a context-free # An exception class that represents a problem with a context-free
# grammar's definition. # grammar's definition.
class GrammarError < Exception; end class GrammarError < StandardError; end


# The CFG class is used to represent context-free grammars. It is used by # The CFG class is used to represent context-free grammars. It is used by
# the RLTK::Parser class to represent the parser's grammar, but can also be # the RLTK::Parser class to represent the parser's grammar, but can also be
Expand Down
2 changes: 1 addition & 1 deletion lib/rltk/lexer.rb
Expand Up @@ -21,7 +21,7 @@ module RLTK # :nodoc:


# A LexingError exception is raised when an input stream contains a # A LexingError exception is raised when an input stream contains a
# substring that isn't matched by any of a lexer's rules. # substring that isn't matched by any of a lexer's rules.
class LexingError < Exception class LexingError < StandardError
def initialize(stream_offset, line_number, line_offset, remainder) def initialize(stream_offset, line_number, line_offset, remainder)
@stream_offset = stream_offset @stream_offset = stream_offset
@line_number = line_number @line_number = line_number
Expand Down
10 changes: 5 additions & 5 deletions lib/rltk/parser.rb
Expand Up @@ -18,7 +18,7 @@ module RLTK # :nodoc:


# A BadToken exception indicates that a token was observed in the input # A BadToken exception indicates that a token was observed in the input
# stream that wasn't used in the grammar's definition. # stream that wasn't used in the grammar's definition.
class BadToken < Exception class BadToken < StandardError
def to_s def to_s
'Unexpected token. Token not present in grammar definition.' 'Unexpected token. Token not present in grammar definition.'
end end
Expand All @@ -27,15 +27,15 @@ def to_s
# A NotInLanguage exception is raised whenever there is no valid parse tree # A NotInLanguage exception is raised whenever there is no valid parse tree
# for a given token stream. In other words, the input string is not in the # for a given token stream. In other words, the input string is not in the
# defined language. # defined language.
class NotInLanguage < Exception class NotInLanguage < StandardError
def to_s def to_s
'String not in language.' 'String not in language.'
end end
end end


# An exception of this type is raised when the parser encountered a error # An exception of this type is raised when the parser encountered a error
# that was handled by an error production. # that was handled by an error production.
class HandledError < Exception class HandledError < StandardError


# The errors as reported by the parser. # The errors as reported by the parser.
attr_reader :errors attr_reader :errors
Expand All @@ -51,11 +51,11 @@ def initialize(errors, result)
end end


# Used for errors that occure during parser construction. # Used for errors that occure during parser construction.
class ParserConstructionError < Exception; end class ParserConstructionError < StandardError; end


# Used for runtime errors that are the parsers fault. These should never # Used for runtime errors that are the parsers fault. These should never
# be observed in the wild. # be observed in the wild.
class InternalParserError < Exception; end class InternalParserError < StandardError; end


# The Parser class may be sub-classed to produce new parsers. These # The Parser class may be sub-classed to produce new parsers. These
# parsers have a lot of features, and are described in the main # parsers have a lot of features, and are described in the main
Expand Down
4 changes: 2 additions & 2 deletions test/tc_ast.rb
Expand Up @@ -63,8 +63,8 @@ def test_equal
end end


def test_initialize def test_initialize
assert_raise(Exception) { RLTK::ASTNode.new } assert_raise(RuntimeError) { RLTK::ASTNode.new }
assert_nothing_raised(Exception) { ANode.new(nil, nil) } assert_nothing_raised(RuntimeError) { ANode.new(nil, nil) }
end end


def test_notes def test_notes
Expand Down
4 changes: 2 additions & 2 deletions test/tc_parser.rb
Expand Up @@ -76,8 +76,8 @@ class ArrayCalc < RLTK::Parser
finalize finalize
end end


class DummyError1 < Exception; end class DummyError1 < StandardError; end
class DummyError2 < Exception; end class DummyError2 < StandardError; end


class ErrorCalc < RLTK::Parser class ErrorCalc < RLTK::Parser
production(:e) do production(:e) do
Expand Down