File: Structure.pm

package info (click to toggle)
libppi-perl 0.903-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 840 kB
  • ctags: 429
  • sloc: perl: 5,551; makefile: 45
file content (45 lines) | stat: -rwxr-xr-x 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package PPI::Token::Structure;

# Characters used to create heirachal structure

use strict;
use UNIVERSAL 'isa';
use base 'PPI::Token';

use vars qw{$VERSION @MATCH};
BEGIN {
	$VERSION = '0.903';

	# Populate the matches
	$MATCH[ord '{'] = '}';
	$MATCH[ord '}'] = '{';
	$MATCH[ord '['] = ']';
	$MATCH[ord ']'] = '[';
	$MATCH[ord '('] = ')';
	$MATCH[ord ')'] = '(';
}





#####################################################################
# Tokenizer Methods

sub _on_char {
	# Structures are one character long, always.
	# Finalize and process again.
	$_[1]->_finalize_token->_on_char( $_[1] );
}

sub _commit {
	my $t = $_[1];
	$t->_new_token( 'Structure', substr( $t->{line}, $t->{line_cursor}, 1 ) );
	$t->_finalize_token;
	0;
}

# For a given brace, find its opposing pair
sub _opposite { $MATCH[ord $_[0]->{content} ] }

1;