summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
Commit message (Collapse)AuthorAgeFilesLines
...
* Removing any mentions of :casesensitive settingLuke Kanies2010-04-093-9/+7
| | | | | | | | | | | | | | | | | It is a setting that was added years ago as a backward compatibility option and even if it still works, which is questionable, it has no purpose any longer. It just complicated the code and didn't do much, so it's gone now. Also simplified the interface of Leaf#evaluate_match, since it was now using none of the passed-in options. Finally, removed/migrated the last of the Selector/CaseStatement test/unit tests. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* Moving the string interpolation parsing to the parser/lexerMarkus Roberts2010-02-171-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch moves the syntactic aspects of string interpolation up into the lexer/parser phase, preparatory to moving the semantic portions down to the as yet unnamed futures resolution phase. This is an enabling move, designed to allow: * Futures resolution in and between interpolated strings * Interpolation of hash elements into strings * Removal of certain order-dependent paths * Further modularization of the lexer/parser The key change is switching from viewing strings with interpolation as single lexical entities (which await later special case processing) to viewing them as formulas for constructing strings, with the internal structure of the string exposed by the parser. Thus a string like: "Hello $name, are you enjoying ${language_feature}?" internally becomes something like: concat("Hello ",$name,", are you enjoying ",$language_feature,"?") where "concat" is an internal string concatenation function. A few test cases to show the user observable effects of this change: notice("string with ${'a nested single quoted string'} inside it.") $v2 = 3+4 notice("string with ${['an array ',3,'+',4,'=',$v2]} in it.") notice("string with ${(3+5)/4} nested math ops in it.") ...and so forth. The key changes in the internals are: * Unification of SQTEXT and DQTEXT into a new token type STRING (since nothing past the lexer cares about the distinction. * Creation of several new token types to represent the components of an interpolated string: DQPRE The initial portion of an interpolated string DQMID The portion of a string betwixt two interpolations DQPOST The final portion of an interpolated string DQCONT The as-yet-unlexed portion after an interpolation Thus, in the example above (phantom curly braces added for clarity), DQPRE "Hello ${ DQMID }, are you enjoying ${ DQPOST }?" DQCONT is a bookkeeping token and is never generated. * Creation of a DOLLAR_VAR token to strip the "$" off of variables with explicit dollar signs, so that the VARIABLEs produced from things like "Test ${x}" (where the "$" has already been consumed) do not fail for want of a "$" * Reworking the grammar rules in the obvious way * Introduction of a "concatenation" AST node type (which will be going away in a subsequent refactor). Note finally that this is a component of a set of interrelated refactors, and some of the changes around the edges of the above will only makes sense in context of the other parts.
* Finishing renaming :params to :parameters internallyLuke Kanies2010-02-174-12/+12
| | | | | | | | | | | | I had only done this partway, because it seemed easier, but not surprisingly, it ended up being more complex. In addition to those renames, this commit includes fixes to whatever tests I needed to fix to confirm that things were again working. I think most of these broken tests have been broken for a while. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Converging the Resource classes furtherLuke Kanies2010-02-171-1/+1
| | | | | | | | | | | I was using 'params' and 'parameters', so I fixed that and extracted the differences in how they handle parameters into a stubbable method. This allowed me to almost entirely remove the subclass's 'initialize' method. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Adding strictness checking to resourcesLuke Kanies2010-02-171-1/+2
| | | | | | | This is used for AST resources (and fixed the last of the tests I broke in spec/). Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Removing Resource::Reference classesLuke Kanies2010-02-174-79/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Fix #3229 - use original value in case/selector regex matchingBrice Figureau2010-02-173-9/+5
| | | | | | | | | | | | | | | | | | | | | | | The issue is that case/selectors are downcasing the value before it is compared to the options. Unfortunately regex are matching in a case sensitive way, which would make the following manifest fail: $var = "CaseSensitive" case $var { /CaseSensitive/: { notice("worked") } default: { fail "miserably" } } This patch fixes the issue by making sure the regexp match is done one the original (not downcased) value, but still doing a case sensitive match. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Allow adding single key to hashesBrice Figureau2010-02-172-8/+31
| | | | | | | | | | This patch allow this syntax: $hash[mykey] = 12 If the key already exist an error is raised. Hashes are essentially write only, like puppet variables. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2389 - Enhance Puppet DSL with HashesBrice Figureau2010-02-172-0/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bring a new container syntax to the Puppet DSL: hashes. Hashes are defined like Ruby Hash: { key1 => val1, ... } Hash keys are strings, but hash values can be any possible right values admitted in Puppet DSL (ie function call, variables access...) Currently it is possible: 1) to assign hashes to variable $myhash = { key1 => "myval", key2 => $b } 2) to access hash members (recursively) from a variable containing a hash (works for array too): $myhash = { key => { subkey => "b" }} notice($myhash[key][subjey]] 3) to use hash member access as resource title 4) to use hash in default definition parameter or resource parameter if the type supports it (known for the moment). It is not possible to string interpolate an hash access. If it proves to be an issue it can be added or work-arounded with a string concatenation operator easily. It is not possible to use an hash as a resource title. This might be possible once we support compound resource title. Unlike the proposed syntax in the ticket it is not possible to assign individual hash member (mostly to respect write once nature of variable in puppet). Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2818 - scope variable assigned with undef are not "undef"Brice Figureau2009-12-291-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following manifest doesn't work: $foo = undef case $foo { undef: { notice("undef") } default: { notice("defined") } } This is because "undef" scope variable are returned as an empty string. This patch introduces a behavior change: Now, unassigned variable usage returns also undef. This might produce some issues in existing manifests, although care has been taken to allow correct behavior in the most commonly used patterns. For instance: case $bar { undef: { notice("undef") } default: { notice("defined") } } will print "undef". But matching undef in case/selector/if will also match "". case $bar { "": { notice("empty") } default: { notice("defined") } } will print "empty". Of course "" doesn't match undef :-) Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Merge branch '0.25.x'Luke Kanies2009-12-211-2/+2
|\ | | | | | | | | | | | | | | Conflicts: lib/puppet/agent.rb lib/puppet/application/puppetd.rb lib/puppet/parser/ast/leaf.rb lib/puppet/util/rdoc/parser.rb
| * Possible workaround for #2824 (MRI GC bug)Markus Roberts2009-11-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a moderately ugly workaround for the MRI garbage collection bug (see the ticket for details). I explored several other potential solutions (notably, monkey patching the routines that trigger the bug) but none of them were satisfactory. Monkey patching sub, gsub, sub!, gsub!, etc., for example, either changes the scoping of $~, $1, etc. in a way that could potentially subtly change the meaning of programs or (if you are clever) faithfully reproduces the behaviour of MRI--including the memory leak. I decided to go with the standardized and somewhat obnoxious never- used optional argument as it was easy to automatically insert and should be even easier to automatically find and remove if a better fix is developed. It also should be obtrusive enough to escape accidental removal in refactoring.
| * Fix #2796 - Fix puppetdoc rdoc selector parsingBrice Figureau2009-11-123-0/+12
| | | | | | | | | | | | | | | | | | This patch fix this bug by adding more to_s methods to ast member so that puppetdoc can just to_s the AST to reconstruct the original puppet code. Of course this is not perfect, but should work most of the time. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
| * Al Hoang's patch for #2781, removing obsolete when/: syntaxMarkus Roberts2009-11-051-2/+2
| | | | | | | | | | | | This is just Al's patch with removal of trailing ";"s. Signed-off-by: Markus Roberts <Markus@reality.com>
* | Fixing #2596 - Node, Class, Definition are not ASTLuke Kanies2009-12-095-369/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit extracts these three classes into a single ResourceType class in the Parser heirarchy, now completely independent of the AST heirarchy. Most of the other changes are just changing the interface to the new class, which is greatly simplified over the previous classes. This opens up the possibility of drastically simplifying a lot of this other code, too -- in particular, replacing the reference to the parser with a reference to the (soon to be renamed) LoadedCode class. Signed-off-by: Luke Kanies <luke@madstop.com>
* | Fix #2796 - Fix puppetdoc rdoc selector parsingBrice Figureau2009-11-123-0/+12
|/ | | | | | | | | This patch fix this bug by adding more to_s methods to ast member so that puppetdoc can just to_s the AST to reconstruct the original puppet code. Of course this is not perfect, but should work most of the time. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2672 - Make sure nodenames keep their underscores when used as classnameBrice Figureau2009-09-231-1/+1
| | | | | | | | The #2627 fix was modifying nodename in case of string nodename, but was removing '_'. Since underscores is a valid character in a class name, we now allow it. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2627 - regex node name could lead to invalid tagBrice Figureau2009-09-161-3/+1
| | | | | | | | | We're converting the regex to a straight name to be used as the node class name which later on will be used as tag. It was possible to generate an invalid tag name (containing leading or successive dots). Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fixing #2563 - multiple regex nodes now work togetherLuke Kanies2009-09-011-2/+12
| | | | | | | | | | The problem was that we were needing to convert one of the regexes to a string, which wasn't working well. This adds specific rules for how regexes vs. strings get compared. Signed-off-by: Luke Kanies <luke@madstop.com>
* Implement node matching with regexesBrice Figureau2009-08-013-4/+40
| | | | | | | This patch enhance AST::HostName to support regexes, and modifies the parser to allow regex to be used as node name. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>]
* Make sure node are referenced by their namesBrice Figureau2009-08-012-6/+17
| | | | | | | | | This patch uses the unused AST::HostName as the only way to reference a node in the AST nodes array. The AST::HostName respect the hash properties of the underlying string, to keep the O(1) hash properties. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Enhance selector and case statements to match with regexpBrice Figureau2009-08-013-56/+33
| | | | | | | | | | | | | | | | | | | | | | | | | The case and selector statements define ephemeral vars, like 'if'. Usage: case statement: $var = "foobar" case $var { "foo": { notify { "got a foo": } } /(.*)bar$/: { notify{ "hey we got a $1": } } } and for selector: $val = $test ? { /^match.*$/ => "matched", default => "default" } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2033 - Allow regexp in if expressionBrice Figureau2009-08-012-6/+42
| | | | | | | | | | | | | | | | | | | This changeset introduces regexp in if expression with the use of the =~ (match) and !~ (not match) operator. Usage: if $uname =~ /Linux|Debian/ { ... } Moreover this patch creates ephemeral variables ($0 to $9) in the current scope which contains the regex captures: if $uname =~ /(Linux|Debian)/ { notice("this is a $1 system") } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Add AST::Regex, an AST leaf node representing a regexBrice Figureau2009-08-011-0/+42
| | | | | | Add a regex rule (unused for the moment) to the parser. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Implement ephemeral scope variablesBrice Figureau2009-08-011-1/+1
| | | | | | | | | | Those variables have been created to be short lived and used mainly to define temporary special variables. They do not persist after a call to unset_ephemeral_var. Also Scope#set_ephemeral_from can be used to promote a regexp MatchData to ephemeral values. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2422 & #2433 - make sure puppetdoc transform AST::Leaf boolean correctlyBrice Figureau2009-07-254-1/+30
| | | | | | | | | | AST nodes don't have a valid to_s that is producing a correct representation of said node. This patch adds some of the AST node to_s to produce correct values that can be used verbatim by puppetdoc to render the documentation. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Switching to LoadedCode from ASTSetLuke Kanies2009-07-053-4/+4
| | | | | | | | I also took the opportunity to clean up and simplify the interface to the parts of the parser that interact with this. Mostly it was method renames. Signed-off-by: Luke Kanies <luke@madstop.com>
* Make sure virtual and rails query use tags when tag are searchedBrice Figureau2009-06-061-4/+11
| | | | | | | | | | | | Up to now, when trying to match with tags: File<<| tag == 'value' |>> in fact we were querying parameters. Hopefully all the user tags are stored in parameters so it was working. But it wasn't possible to search on auto-tags (like class name). This patch makes sure searching by tag is done on tags both on the rails side and the resource side. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2246 - Array tagged resources can't be collected or exportedBrice Figureau2009-06-061-1/+1
| | | | | | | | | | | | I don't know why we imposed the restriction that we shouldn't match with parameter containing arrays in exported mode. That doesn't seem right, as the produced rails query works fine with arrays. Note: the user tags are not stored in the rails database except under the special resource parameter tag. This also doesn't seem right. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Removed extra whitespace from end of linesIan Taylor2009-06-069-12/+12
|
* Merge branch '0.24.x'Luke Kanies2009-04-022-3/+3
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: bin/ralsh lib/puppet/executables/client/certhandler.rb lib/puppet/parser/functions/versioncmp.rb lib/puppet/parser/resource/reference.rb lib/puppet/provider/augeas/augeas.rb lib/puppet/provider/nameservice/directoryservice.rb lib/puppet/provider/ssh_authorized_key/parsed.rb lib/puppet/type.rb lib/puppet/type/file/checksum.rb spec/integration/defaults.rb spec/integration/transaction/report.rb spec/unit/executables/client/certhandler.rb spec/unit/indirector/ssl_rsa/file.rb spec/unit/node/catalog.rb spec/unit/provider/augeas/augeas.rb spec/unit/rails.rb spec/unit/type/ssh_authorized_key.rb spec/unit/type/tidy.rb test/executables/filebucket.rb test/executables/puppetbin.rb
| * Using the FileCollection where appropriate.Luke Kanies2009-02-282-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit just replaces the :file and :line accessors with the use of the new FileCollection Lookup module. This should mean that we've normalized all file names in a given process, which *might* have drastic RAM improvements. For initial simplicity, I've gone with a single global collection of file names, but it's built so it's easy to use individual file collections instead. Signed-off-by: Luke Kanies <luke@madstop.com>
* | Fix #1088 - Collections overridesBrice Figureau2009-03-141-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset defines a new syntax to override collection of resources (virtual or not). This feature is not constrained to the override in inherited context as usual resource override. The collection of resource supports a query like regular collection of virtual or exported resources. Usage example: file { "/tmp/testing": content => "whatever" } File<| |> { mode => 0600 } It also introduces a different behaviour for collection of catalog resources. Before this patch, only virtual resources were collected, now all resources (virtual or no) are collected and can be overriden. That means it is now possible to do: File <| |> { mode => 0600 } And all the Files resources will have mode 0600. It is then possible to have this puppet pattern: file { "/tmp/a": content => "a" } file { "/tmp/b": content => "b" } File <| title != "/tmp/a" |> { require => File["/tmp/b"] } which means that every File requires a file. Moreover it is now possible to define resource overriding without respecting the override on inheritance rule: class a { file { "/tmp/testing": content => "whatever" } } class b { include a File<| |> { mode => 0600 } } include b Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* | Fixed #1849 - Ruby 1.9 portability: `when' doesn't like colons, replace with ↵James Turnbull2009-02-262-8/+8
| | | | | | | | semicolons
* | Merge branch '0.24.x'Luke Kanies2009-02-112-21/+22
|\| | | | | | | | | | | Conflicts: CHANGELOG spec/unit/type/file/selinux.rb
| * Fixed #1884 - exported defines are collected by the exporting hostLuke Kanies2009-02-111-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was caused by the fix to #1472. That fix unexported any resources collected from the local catalog. The crux of this fix is that it separates 'exported' and 'virtual' a bit more. It also removes no-longer-needed functionality where resources copied their virtual or exported bits from the enclosing define or class. This is now obsolete because we don't evaluate virtual defined resources. The crux of this commit is that defined resources can stay exported even though they're evaluated, and that exported state won't inherit to contained resources such that those then don't get evaluated. Signed-off-by: Luke Kanies <luke@madstop.com>
| * Cleaning up the AST::Resource code a bitLuke Kanies2009-02-101-20/+21
| | | | | | | | | | | | | | | | | | | | | | Mostly renaming 'obj' to 'resource', since the whole 'obj' thing is a holdover from before we had the term 'resource'. Also pulling a bit of code out of a loop, since it didn't need to be there. Signed-off-by: Luke Kanies <luke@madstop.com>
| * Fix #1682 - Resource titles are not flattened as they shouldBrice Figureau2009-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following manifest: $groups = ["foo", "bar"] $type_groups = ["baz", "quux"] $user_groups = [$groups, $type_groups] notify{ $user_groups: } which outputs: notice: foo notice: //Notify[foobar]/message: defined 'message' as 'foo' notice: baz notice: //Notify[bazquux]/message: defined 'message' as 'baz' is not equivalent to $user_groups = [ ["foo", "bar"], ["baz", "quux"] ] notify{ $user_groups: } which outputs: notice: foo notice: //Notify[foo]/message: defined 'message' as 'foo' notice: baz notice: //Notify[baz]/message: defined 'message' as 'baz' notice: bar notice: //Notify[bar]/message: defined 'message' as 'bar' notice: quux notice: //Notify[quux]/message: defined 'message' as 'quux' Obviously the second one manages to flatten the arrays and not the first one. This changeset adds flattening to the resource titles evaluations in order to be consitent in all cases. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
| * Fix #1922 - Functions squash all arguments into a single hashBrice Figureau2009-02-111-1/+2
| | | | | | | | | | | | | | | | Revert "Fix #1682 - ASTArray should flatten product of evaluation of its children" This reverts commit c7ccc4ba7c42d56595564491ae578a1604c628d1. Bug #1824 and #1922 proved the fix for #1682 and #1691 was wrong. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* | Renaming Puppet::ResourceReference to Puppet::Resource::ReferenceLuke Kanies2008-12-091-1/+1
|/ | | | Signed-off-by: Luke Kanies <luke@madstop.com>
* Fix #1759 - Comparison operator was using string comparison for numbersBrice Figureau2008-11-201-0/+4
| | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Move function existance test to parser evaluationBrice Figureau2008-11-171-12/+16
| | | | | | | | The aim is to let --parseonly succeeds even if the function is not (yet) present. This is usefull in commit-hooks and for the inline documentation generation system. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Add a doc attribute to AST nodes and fill it with the last seen commentsBrice Figureau2008-11-1712-0/+32
| | | | | | | | | | | | | The lexer maintains a stack of last seen comments. On blank lines the lexer flush the comments. On each opening brace the lexer enters a new stack level. On each block AST nodes, the stack is popped. Each AST nodes has a doc property that is filled with the last seen comments on node creation (in fact only on important node creation representing statements). Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #1682 - ASTArray should flatten product of evaluation of its childrenBrice Figureau2008-10-291-2/+1
| | | | | If the ASTArray contains children that evaluate to arrays themselves, they aren't flattened.
* Fixed #1104 - Classes and nodes should set $name variablesBrice Figureau2008-10-281-1/+6
| | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #1202 - Collection attribute matching doesn't parse arraysBrice Figureau2008-10-081-1/+6
| | | | | | | | | | | | This patch allows to do this: User <| groups == leads |> @user { "foo": ensure => "present", groups => ["bar","baz","leads"] } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #1109 - allow empty if or else branchesBrice Figureau2008-10-071-0/+11
| | | | | | | | | | | | This changesets allow empty if or else branches: if true { } else { } It works by emitting on the parser stack an AST node that doesn't do anything (a no-op). This allows the less intrusive code as no part of the if evaluation code has been touched.
* Fix #381 - Allow multiple resource overrides or referencesBrice Figureau2008-10-052-22/+33
| | | | | | | | | | | | | | | | | | | | | | | Allow this syntax: Resource[title1,title2] { param => value } as a compact form of Resource[title1] { param => value } Resource[title2] { param => value } This patch also introduces for free the possibility to group class references by type: exec { test: require => File["file1","file2","File3"] } which is completely equivalent to: exec { test: require => [ File["file1"],File["file2"],File["File3"] ] }
* Add arithmetic operators to ASTBrice Figureau2008-09-302-0/+64
| | | | | This changeset adds +,-,/,*,<< and >> computation and AST parse nodes.
* Add not operator to ASTBrice Figureau2008-09-301-0/+19
|