• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package ANTLR::Runtime::RecognitionException;
2
3use Carp;
4use Readonly;
5
6use Moose;
7use Moose::Util::TypeConstraints;
8
9extends 'ANTLR::Runtime::Exception';
10
11has 'input' => (
12    is   => 'ro',
13    does => 'ANTLR::Runtime::IntStream',
14    required => 1,
15);
16
17has 'index' => (
18    is  => 'ro',
19    isa => 'Int',
20    default => 0,
21);
22
23has 'token' => (
24    is   => 'ro',
25    does => 'ANTLR::Runtime::Token',
26);
27
28has 'node' => (
29    is  => 'ro',
30    isa => 'Any',
31);
32
33subtype 'Char'
34    => as 'Str'
35    => where { $_ eq '-1' || length == 1 };
36
37has 'c' => (
38    is  => 'ro',
39    isa => 'Maybe[Char]',
40);
41
42has 'line' => (
43    is  => 'ro',
44    isa => 'Int',
45    default => 0,
46);
47
48has 'char_position_in_line' => (
49    is  => 'ro',
50    isa => 'Int',
51    default => 0,
52);
53
54has 'approximate_line_info' => (
55    is  => 'rw',
56    isa => 'Bool',
57);
58
59sub BUILDARGS {
60    my ($class, @args) = @_;
61    my $args = $class->SUPER::BUILDARGS(@args);
62
63    my $new_args = { %$args };
64    my $input = $args->{input};
65    $new_args->{input} = $input;
66    $new_args->{index} = $input->index();
67
68    if ($input->does('ANTLR::Runtime::TokenStream')) {
69        my $token = $input->LT(1);
70        $new_args->{token} = $token;
71        $new_args->{line} = $token->get_line();
72        $new_args->{char_position_in_line} = $token->get_char_position_in_line();
73    }
74
75    if ($input->does('ANTLR::Runtime::TreeNodeStream')) {
76        # extract_information_from_tree_node_stream($input);
77    }
78    elsif ($input->does('ANTLR::Runtime::CharStream')) {
79        $new_args->{c} = $input->LA(1);
80        $new_args->{line} = $input->get_line();
81        $new_args->{char_position_in_line} = $input->get_char_position_in_line();
82    }
83    else {
84        $new_args->{c} = $input->LA(1);
85    }
86
87    return $new_args;
88}
89
90sub get_unexpected_type {
91    my ($self) = @_;
92
93    if ($self->input->isa('ANTLR::Runtime::TokenStream')) {
94        return $self->token->get_type();
95    } else {
96        return $self->c;
97    }
98}
99
100sub get_c {
101    my ($self) = @_;
102    return $self->c;
103}
104
105sub get_line {
106    my ($self) = @_;
107    return $self->line;
108}
109
110sub get_char_position_in_line {
111    my ($self) = @_;
112    return $self->char_position_in_line;
113}
114
115sub get_token {
116    my ($self) = @_;
117    return $self->token;
118}
119
120no Moose;
121__PACKAGE__->meta->make_immutable();
1221;
123