summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-08-19 19:37:22 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-08-19 19:37:22 (GMT)
commit868a1f983d57fcd3d938991275c1fcc229ef80b0 (patch) (side-by-side diff)
treeba182ca02ea44e3c39a1527afab945d4e4277540
parent117bbc65e5b9554d81c75b543dcd66a6b1bed751 (diff)
downloadconfig-ast-868a1f983d57fcd3d938991275c1fcc229ef80b0.tar.gz
config-ast-868a1f983d57fcd3d938991275c1fcc229ef80b0.tar.bz2
New method: lexicon.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Config/AST.pm38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/Config/AST.pm b/lib/Config/AST.pm
index 4fd97af..c357cdc 100644
--- a/lib/Config/AST.pm
+++ b/lib/Config/AST.pm
@@ -40,6 +40,7 @@ Config::AST - abstract syntax tree for configuration files
my $cfg = new Config::AST($filename, %opts);
$cfg->parse() or die;
+ $cfg->commit() or die;
if ($cfg->is_set('core', 'variable')) {
...
@@ -60,7 +61,7 @@ parsers to build internal representation for the particular configuration file
format.
A configuration file in general is supposed to consist of statements of two
-kinds: simple statements, and sections. A simple statement declares or sets
+kinds: simple statements and sections. A simple statement declares or sets
a configuration parameter. Examples of simple statements are:
# Bind configuration file:
@@ -90,10 +91,10 @@ are (with subordinate statements replaced with ellipsis):
[core]
...
-Syntax of Git configuration file being one of the simplest, we will use
+The syntax of Git configuration file being one of the simplest, we will use
it in the discussion below to illustrate various concepts.
-The abstract syntax tree (AST) for configuration file consists of nodes.
+The abstract syntax tree (AST) for a configuration file consists of nodes.
Each node represents a single statement and carries detailed information
about that statement, in particular:
@@ -161,11 +162,11 @@ i.e. the keywords are case-sensitive.
=item B<lexicon> => \%hash
-Defines the keywords lexicon. See below for a description of B<%hash>.
+Defines the I<keyword lexicon>.
=back
-=head3 Keywords lexicon
+=head3 Keyword lexicon
The hash reference passed via the B<lexicon> keyword defines the keywords
and sections allowed within a configuration file. In a simplest case, a
@@ -174,7 +175,7 @@ keyword is described as
name => 1
This means that B<name> is a valid keyword, but does not imply anything
-more about it or its value. A more complex declaration is possible, in
+about its properties. A more complex declaration is possible, in
which the value is a hash reference, containing one or more of the following
keywords:
@@ -320,6 +321,25 @@ sub new {
return $self;
}
+=head2 $cfg->lexicon($hashref)
+
+Returns current lexicon. If B<$hashref> is supplied, installs it as a
+new lexicon.
+
+=cut
+
+sub lexicon {
+ my $self = shift;
+ if (@_) {
+ my $lexicon = shift;
+ carp "too many arguments" if @_;
+ carp "lexicon must refer to a HASH" unless ref($lexicon) eq 'HASH';
+ $self->reset;
+ $self->{_lexicon} = $lexicon;
+ }
+ return $self->{_lexicon};
+}
+
=head1 PARSING
This module provides a framework for parsing, but does not implement parsers
@@ -335,9 +355,9 @@ The caller must then perform the following operations
=item B<1.> Create an instance of the derived class B<$cfg>.
-=item B<2.> Call the B<$cfg->parse> method.
+=item B<2.> Call the B<$cfg-E<gt>parse> method.
-=item B<3.> On success, call the B<$cfg->commit> method.
+=item B<3.> On success, call the B<$cfg-E<gt>commit> method.
=back
@@ -462,7 +482,7 @@ sub fixup_tree {
}
}
-=head2 $cfg->reset;
+=head2 $cfg->reset
Destroys the parse tree and clears error count, thereby preparing the object
for parsing another file.

Return to:

Send suggestions and report system problems to the System administrator.