1Parse::LexEvent(3) User Contributed Perl Documentation Parse::LexEvent(3)
2
3
4
6 "Parse::LexEvent" - Generator of event-oriented lexical analyzers (1.00
7 ALPHA)
8
10 use Parse::LexEvent;
11
12 sub string {
13 print $_[0]->name, ": $_[1]\n";
14 }
15 sub comment {
16 print $_[0]->name, ": $_[1]\n";
17 }
18 sub remainder {
19 print $_[0]->name, ": $_[1]\n";
20 }
21
22 $lexer = Parse::LexEvent->new()->configure(
23 From => \*DATA,
24 Tokens =>
25 [
26 Type => 'Simple', Name => 'ccomment', Handler => 'comment',
27 Regex => '//.*\n',
28 Type => 'Delimited', Name => 'comment', Handler => 'comment',
29 Start => '/[*]', End => '[*]/',
30 Type => 'Quoted', Name => 'squotes', Handler => 'string', Quote => qq!\'!,
31 Type => 'Quoted', Name => 'dquotes', Handler => 'string', Quote => qq!\"!,
32 Type => 'Simple', Name => 'remainder',
33 Regex => '(?s:[^/\'\"]+)', ReadMore => 1,
34 ]
35 )->parse();
36 __END__
37 /*
38 C comment
39 */
40 // C++ comment
41 var d = "string in double quotes";
42 var s = 'string in single quotes';
43 var i = 10;
44 var y = 100;
45
47 "Parse::LexEvent" generates lexical analyzers in the fashion of
48 "Parse::Lex", but the generated analyzers emit an event at the finish
49 of recognition of each token. This event corresponds to the call of a
50 procedure whose name is that of the token. It is possible to give a
51 different name to this procedure by making use of the "Handler"
52 parameter when defining a token.
53
54 An application using "Parse::LexEvent" must define the required
55 procedures. These procedures take the token object as first argument
56 and the recognized character string as the second.
57
58 "Parse::LexEvent" inherits from "Parse::ALex" and possesses all the
59 methods described in the documentation of the "Parse::Lex" class,
60 except for the methods "analyze()", "every()" "next()", and "nextis()".
61
62 Methods
63 parse()
64 This method runs the analysis of data specified by "from()".
65
67 cparser.pl - This analyzer recognizes three types of structures: C ou
68 C++ comments, strings within quotation marks, and the rest. It emits
69 an event specific to each. You can use it, for example, to analyze C,
70 C++ or Javascript programs.
71
73 "Parse::Lex", "Parse::Token".
74
76 Philippe Verdret.
77
79 Copyright (c) 1999 Philippe Verdret. All rights reserved. This module
80 is free software; you can redistribute it and/or modify it under the
81 same terms as Perl itself.
82
83
84
85perl v5.28.0 2011-12-31 Parse::LexEvent(3)