From 9171923637c1d7f3effb72d44559f0ac1d60b07d Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Thu, 4 Oct 2018 16:36:24 +0900 Subject: [PATCH 1/4] PuppetManifest: allow to use a underscore char and a hyphen char in a name Close #1901. I refereed https://puppet.com/docs/puppet/6.0/lang_data_string.html#bare-words for fixing this. I also add a hyphen char to the list of acceptable chars. --- Units/parser-puppetManifest.r/fix-1901.d/expected.tags | 4 ++++ Units/parser-puppetManifest.r/fix-1901.d/input.pp | 8 ++++++++ optlib/puppetManifest.c | 4 ++-- optlib/puppetManifest.ctags | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Units/parser-puppetManifest.r/fix-1901.d/expected.tags create mode 100644 Units/parser-puppetManifest.r/fix-1901.d/input.pp diff --git a/Units/parser-puppetManifest.r/fix-1901.d/expected.tags b/Units/parser-puppetManifest.r/fix-1901.d/expected.tags new file mode 100644 index 0000000000..28a1090bb1 --- /dev/null +++ b/Units/parser-puppetManifest.r/fix-1901.d/expected.tags @@ -0,0 +1,4 @@ +/tmp/12 input.pp /^ file { "\/tmp\/12": ensure => $ensure }$/;" r definition:one_one::two +/tmp/34 input.pp /^ file { "\/tmp\/34": ensure => $ensure }$/;" r definition:three::four_four +one_one::two input.pp /^define one_one::two($ensure) {$/;" d +three::four_four input.pp /^define three::four_four($ensure) {$/;" d diff --git a/Units/parser-puppetManifest.r/fix-1901.d/input.pp b/Units/parser-puppetManifest.r/fix-1901.d/input.pp new file mode 100644 index 0000000000..2fbdcd0411 --- /dev/null +++ b/Units/parser-puppetManifest.r/fix-1901.d/input.pp @@ -0,0 +1,8 @@ +define one_one::two($ensure) { + file { "/tmp/12": ensure => $ensure } +} + +define three::four_four($ensure) { + file { "/tmp/34": ensure => $ensure } +} + diff --git a/optlib/puppetManifest.c b/optlib/puppetManifest.c index 0e06555189..11f3744046 100644 --- a/optlib/puppetManifest.c +++ b/optlib/puppetManifest.c @@ -366,10 +366,10 @@ static void initializePuppetManifestParser (const langType language CTAGS_ATTR_U "^\\#", "", "", "{tenter=comment_oneline}", NULL); addLanguageTagMultiTableRegex (language, "defineStart", - "^([a-zA-Z:][a-zA-Z0-9:]*)[ \n\t]*\\(", + "^([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\\(", "\\1", "d", "{tenter=skipArgs,blockHeadPopAtLast}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "defineStart", - "^([a-zA-Z:][a-zA-Z0-9:]*)[ \n\t]*\\{", + "^([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\\{", "\\1", "d", "{tenter=block,endWithPop}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "caseStart", "^/\\*", diff --git a/optlib/puppetManifest.ctags b/optlib/puppetManifest.ctags index bb9dc579b1..9a4659cc51 100644 --- a/optlib/puppetManifest.ctags +++ b/optlib/puppetManifest.ctags @@ -277,8 +277,8 @@ # define # --_mtable-extend-PuppetManifest=defineStart+comment ---_mtable-regex-PuppetManifest=defineStart/([a-zA-Z:][a-zA-Z0-9:]*)[ \n\t]*\(/\1/d/{tenter=skipArgs,blockHeadPopAtLast}{scope=push} ---_mtable-regex-PuppetManifest=defineStart/([a-zA-Z:][a-zA-Z0-9:]*)[ \n\t]*\{/\1/d/{tenter=block,endWithPop}{scope=push} +--_mtable-regex-PuppetManifest=defineStart/([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\(/\1/d/{tenter=skipArgs,blockHeadPopAtLast}{scope=push} +--_mtable-regex-PuppetManifest=defineStart/([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\{/\1/d/{tenter=block,endWithPop}{scope=push} # # case From d99a273560d541d8cfc5a6ea8d35bbda10a03d47 Mon Sep 17 00:00:00 2001 From: Hakan Baba Date: Thu, 4 Oct 2018 23:07:49 -0700 Subject: [PATCH 2/4] Minor fix on the puppetManifest parser regular expressions. fixes #1901 According to puppet docs: https://puppet.com/docs/puppet/5.3/lang_reserved.html#classes-and-defined-resource-types calss or a definition name can contain an underscore anywhere except the first char. Also added tests. A minor name change for a test directory --- .../fix-1901.d/expected.tags | 4 --- .../fix-1901.d/input.pp | 8 ------ .../puppet-classname.d/args.ctags | 2 ++ .../puppet-classname.d/expected.tags | 10 +++++++ .../puppet-classname.d/input.pp | 26 ++++++++++++++++++ .../puppet-definitionname.d/args.ctags | 2 ++ .../puppet-definitionname.d/expected.tags | 10 +++++++ .../puppet-definitionname.d/input.pp | 27 +++++++++++++++++++ optlib/puppetManifest.c | 8 +++--- optlib/puppetManifest.ctags | 8 +++--- 10 files changed, 85 insertions(+), 20 deletions(-) delete mode 100644 Units/parser-puppetManifest.r/fix-1901.d/expected.tags delete mode 100644 Units/parser-puppetManifest.r/fix-1901.d/input.pp create mode 100644 Units/parser-puppetManifest.r/puppet-classname.d/args.ctags create mode 100644 Units/parser-puppetManifest.r/puppet-classname.d/expected.tags create mode 100644 Units/parser-puppetManifest.r/puppet-classname.d/input.pp create mode 100644 Units/parser-puppetManifest.r/puppet-definitionname.d/args.ctags create mode 100644 Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags create mode 100644 Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp diff --git a/Units/parser-puppetManifest.r/fix-1901.d/expected.tags b/Units/parser-puppetManifest.r/fix-1901.d/expected.tags deleted file mode 100644 index 28a1090bb1..0000000000 --- a/Units/parser-puppetManifest.r/fix-1901.d/expected.tags +++ /dev/null @@ -1,4 +0,0 @@ -/tmp/12 input.pp /^ file { "\/tmp\/12": ensure => $ensure }$/;" r definition:one_one::two -/tmp/34 input.pp /^ file { "\/tmp\/34": ensure => $ensure }$/;" r definition:three::four_four -one_one::two input.pp /^define one_one::two($ensure) {$/;" d -three::four_four input.pp /^define three::four_four($ensure) {$/;" d diff --git a/Units/parser-puppetManifest.r/fix-1901.d/input.pp b/Units/parser-puppetManifest.r/fix-1901.d/input.pp deleted file mode 100644 index 2fbdcd0411..0000000000 --- a/Units/parser-puppetManifest.r/fix-1901.d/input.pp +++ /dev/null @@ -1,8 +0,0 @@ -define one_one::two($ensure) { - file { "/tmp/12": ensure => $ensure } -} - -define three::four_four($ensure) { - file { "/tmp/34": ensure => $ensure } -} - diff --git a/Units/parser-puppetManifest.r/puppet-classname.d/args.ctags b/Units/parser-puppetManifest.r/puppet-classname.d/args.ctags new file mode 100644 index 0000000000..fb884c1049 --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-classname.d/args.ctags @@ -0,0 +1,2 @@ +--sort=no +--fields=+KZlne diff --git a/Units/parser-puppetManifest.r/puppet-classname.d/expected.tags b/Units/parser-puppetManifest.r/puppet-classname.d/expected.tags new file mode 100644 index 0000000000..5324d83536 --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-classname.d/expected.tags @@ -0,0 +1,10 @@ +t input.pp /^class t {$/;" class line:1 language:PuppetManifest end:3 +/tmp/multipleclasst input.pp /^ file { "\/tmp\/multipleclasst": content => "one" }$/;" resource line:2 language:PuppetManifest scope:class:t end:2 +one_ input.pp /^class one_ {$/;" class line:5 language:PuppetManifest end:7 +/tmp/multipleclassone_ input.pp /^ file { "\/tmp\/multipleclassone_": content => "one" }$/;" resource line:6 language:PuppetManifest scope:class:one_ end:6 +on_e input.pp /^class on_e {$/;" class line:9 language:PuppetManifest end:11 +/tmp/multipleclasson_e input.pp /^ file { "\/tmp\/multipleclasson_e": content => "one" }$/;" resource line:10 language:PuppetManifest scope:class:on_e end:10 +o_ne::tw_o input.pp /^class o_ne::tw_o {$/;" class line:14 language:PuppetManifest end:16 +/tmp/multipleclasso_netw_o input.pp /^ file { "\/tmp\/multipleclasso_netw_o": content => "two" }$/;" resource line:15 language:PuppetManifest scope:class:o_ne::tw_o end:15 +o_ne::two_ input.pp /^class o_ne::two_ {$/;" class line:18 language:PuppetManifest end:20 +/tmp/multipleclasso_netwo_ input.pp /^ file { "\/tmp\/multipleclasso_netwo_": content => "two" }$/;" resource line:19 language:PuppetManifest scope:class:o_ne::two_ end:19 diff --git a/Units/parser-puppetManifest.r/puppet-classname.d/input.pp b/Units/parser-puppetManifest.r/puppet-classname.d/input.pp new file mode 100644 index 0000000000..258157111c --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-classname.d/input.pp @@ -0,0 +1,26 @@ +class t { + file { "/tmp/multipleclasst": content => "one" } +} + +class one_ { + file { "/tmp/multipleclassone_": content => "one" } +} + +class on_e { + file { "/tmp/multipleclasson_e": content => "one" } +} + + +class o_ne::tw_o { + file { "/tmp/multipleclasso_netw_o": content => "two" } +} + +class o_ne::two_ { + file { "/tmp/multipleclasso_netwo_": content => "two" } +} + +include t +include one_ +include on_e +include o_ne::tw_o +include o_ne::two_ diff --git a/Units/parser-puppetManifest.r/puppet-definitionname.d/args.ctags b/Units/parser-puppetManifest.r/puppet-definitionname.d/args.ctags new file mode 100644 index 0000000000..fb884c1049 --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-definitionname.d/args.ctags @@ -0,0 +1,2 @@ +--sort=no +--fields=+KZlne diff --git a/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags b/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags new file mode 100644 index 0000000000..e63236afe2 --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags @@ -0,0 +1,10 @@ +t input.pp /^define t {$/;" definition line:2 language:PuppetManifest end:4 +/tmp/multipledefinet input.pp /^ file { "\/tmp\/multipledefinet": content => "one" }$/;" resource line:3 language:PuppetManifest scope:definition:t end:3 +one_ input.pp /^define one_ {$/;" definition line:6 language:PuppetManifest end:8 +/tmp/multipledefineone_ input.pp /^ file { "\/tmp\/multipledefineone_": content => "one" }$/;" resource line:7 language:PuppetManifest scope:definition:one_ end:7 +on_e input.pp /^define on_e {$/;" definition line:10 language:PuppetManifest end:12 +/tmp/multipledefineon_e input.pp /^ file { "\/tmp\/multipledefineon_e": content => "one" }$/;" resource line:11 language:PuppetManifest scope:definition:on_e end:11 +o_ne::tw_o input.pp /^define o_ne::tw_o {$/;" definition line:15 language:PuppetManifest end:17 +/tmp/multipledefineo_netw_o input.pp /^ file { "\/tmp\/multipledefineo_netw_o": content => "two" }$/;" resource line:16 language:PuppetManifest scope:definition:o_ne::tw_o end:16 +o_ne::two_ input.pp /^define o_ne::two_ {$/;" definition line:19 language:PuppetManifest end:21 +/tmp/multipledefineo_netwo_ input.pp /^ file { "\/tmp\/multipledefineo_netwo_": content => "two" }$/;" resource line:20 language:PuppetManifest scope:definition:o_ne::two_ end:20 diff --git a/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp b/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp new file mode 100644 index 0000000000..5078e7532d --- /dev/null +++ b/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp @@ -0,0 +1,27 @@ + +define t { + file { "/tmp/multipledefinet": content => "one" } +} + +define one_ { + file { "/tmp/multipledefineone_": content => "one" } +} + +define on_e { + file { "/tmp/multipledefineon_e": content => "one" } +} + + +define o_ne::tw_o { + file { "/tmp/multipledefineo_netw_o": content => "two" } +} + +define o_ne::two_ { + file { "/tmp/multipledefineo_netwo_": content => "two" } +} + +include t +include one_ +include on_e +include o_ne::tw_o +include o_ne::two_ diff --git a/optlib/puppetManifest.c b/optlib/puppetManifest.c index 11f3744046..6308a95844 100644 --- a/optlib/puppetManifest.c +++ b/optlib/puppetManifest.c @@ -234,10 +234,10 @@ static void initializePuppetManifestParser (const langType language CTAGS_ATTR_U "^\\#", "", "", "{tenter=comment_oneline}", NULL); addLanguageTagMultiTableRegex (language, "classStart", - "^(::[a-zA-Z0-9:]+)", + "^(::[a-z][_a-zA-Z0-9:]*)", "\\1", "c", "{tenter=blockHead,endWithPop}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "classStart", - "^([a-zA-Z][a-zA-Z0-9:]*)", + "^([a-z][_a-zA-Z0-9:]*)", "\\1", "c", "{tenter=blockHead,endWithPop}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "resourceBlock", "^/\\*", @@ -366,10 +366,10 @@ static void initializePuppetManifestParser (const langType language CTAGS_ATTR_U "^\\#", "", "", "{tenter=comment_oneline}", NULL); addLanguageTagMultiTableRegex (language, "defineStart", - "^([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\\(", + "^([a-z][_a-zA-Z0-9:]*)[ \n\t]*\\(", "\\1", "d", "{tenter=skipArgs,blockHeadPopAtLast}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "defineStart", - "^([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\\{", + "^([a-z][_a-zA-Z0-9:]*)[ \n\t]*\\{", "\\1", "d", "{tenter=block,endWithPop}{scope=push}", NULL); addLanguageTagMultiTableRegex (language, "caseStart", "^/\\*", diff --git a/optlib/puppetManifest.ctags b/optlib/puppetManifest.ctags index 9a4659cc51..c5ab0c7cd0 100644 --- a/optlib/puppetManifest.ctags +++ b/optlib/puppetManifest.ctags @@ -209,8 +209,8 @@ # TODO: inherits: # --_mtable-extend-PuppetManifest=classStart+comment ---_mtable-regex-PuppetManifest=classStart/(::[a-zA-Z0-9:]+)/\1/c/{tenter=blockHead,endWithPop}{scope=push} ---_mtable-regex-PuppetManifest=classStart/([a-zA-Z][a-zA-Z0-9:]*)/\1/c/{tenter=blockHead,endWithPop}{scope=push} +--_mtable-regex-PuppetManifest=classStart/(::[a-z][_a-zA-Z0-9:]*)/\1/c/{tenter=blockHead,endWithPop}{scope=push} +--_mtable-regex-PuppetManifest=classStart/([a-z][_a-zA-Z0-9:]*)/\1/c/{tenter=blockHead,endWithPop}{scope=push} # # resource @@ -277,8 +277,8 @@ # define # --_mtable-extend-PuppetManifest=defineStart+comment ---_mtable-regex-PuppetManifest=defineStart/([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\(/\1/d/{tenter=skipArgs,blockHeadPopAtLast}{scope=push} ---_mtable-regex-PuppetManifest=defineStart/([a-z:][-_a-zA-Z0-9:]*)[ \n\t]*\{/\1/d/{tenter=block,endWithPop}{scope=push} +--_mtable-regex-PuppetManifest=defineStart/([a-z][_a-zA-Z0-9:]*)[ \n\t]*\(/\1/d/{tenter=skipArgs,blockHeadPopAtLast}{scope=push} +--_mtable-regex-PuppetManifest=defineStart/([a-z][_a-zA-Z0-9:]*)[ \n\t]*\{/\1/d/{tenter=block,endWithPop}{scope=push} # # case From b6b46df14d82fd57dca10a6e0ccfcf43aa1bfa46 Mon Sep 17 00:00:00 2001 From: Hakan Baba Date: Fri, 5 Oct 2018 00:03:55 -0700 Subject: [PATCH 3/4] Instantiate the defined resources correctly --- .../puppet-definitionname.d/input.pp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp b/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp index 5078e7532d..79648acae5 100644 --- a/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp +++ b/Units/parser-puppetManifest.r/puppet-definitionname.d/input.pp @@ -20,8 +20,8 @@ file { "/tmp/multipledefineo_netwo_": content => "two" } } -include t -include one_ -include on_e -include o_ne::tw_o -include o_ne::two_ +t { 't': } +one_ { 'one_': } +on_e { 'on_e': } +o_ne::tw_o { 'o_ne::tw_o': } +o_ne::two_ { 'o_ne::two_': } From f2703d5dc0836c0deef78017796068c7bf2324c2 Mon Sep 17 00:00:00 2001 From: Hakan Baba Date: Fri, 5 Oct 2018 00:11:48 -0700 Subject: [PATCH 4/4] Fix failing tests by adding the diff of the tags file --- .../puppet-definitionname.d/expected.tags | 1 + 1 file changed, 1 insertion(+) diff --git a/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags b/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags index e63236afe2..9b3060e864 100644 --- a/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags +++ b/Units/parser-puppetManifest.r/puppet-definitionname.d/expected.tags @@ -8,3 +8,4 @@ o_ne::tw_o input.pp /^define o_ne::tw_o {$/;" definition line:15 language:Puppet /tmp/multipledefineo_netw_o input.pp /^ file { "\/tmp\/multipledefineo_netw_o": content => "two" }$/;" resource line:16 language:PuppetManifest scope:definition:o_ne::tw_o end:16 o_ne::two_ input.pp /^define o_ne::two_ {$/;" definition line:19 language:PuppetManifest end:21 /tmp/multipledefineo_netwo_ input.pp /^ file { "\/tmp\/multipledefineo_netwo_": content => "two" }$/;" resource line:20 language:PuppetManifest scope:definition:o_ne::two_ end:20 +t input.pp /^t { 't': }$/;" resource line:23 language:PuppetManifest end:23