nasl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +8 -0
  4. data/bin/nasl-parse +33 -0
  5. data/lib/nasl/cli.rb +94 -0
  6. data/lib/nasl/command.rb +96 -0
  7. data/lib/nasl/commands/benchmark.rb +55 -0
  8. data/lib/nasl/commands/parse.rb +55 -0
  9. data/lib/nasl/commands/test.rb +37 -0
  10. data/lib/nasl/commands/tokenize.rb +46 -0
  11. data/lib/nasl/commands/xml.rb +41 -0
  12. data/lib/nasl/context.rb +102 -0
  13. data/lib/nasl/grammar.racc +513 -0
  14. data/lib/nasl/grammar.tab.rb +1650 -0
  15. data/lib/nasl/parser/argument.rb +50 -0
  16. data/lib/nasl/parser/assigment.rb +45 -0
  17. data/lib/nasl/parser/block.rb +41 -0
  18. data/lib/nasl/parser/break.rb +32 -0
  19. data/lib/nasl/parser/call.rb +48 -0
  20. data/lib/nasl/parser/continue.rb +32 -0
  21. data/lib/nasl/parser/decrement.rb +48 -0
  22. data/lib/nasl/parser/empty.rb +32 -0
  23. data/lib/nasl/parser/export.rb +41 -0
  24. data/lib/nasl/parser/expression.rb +56 -0
  25. data/lib/nasl/parser/for.rb +47 -0
  26. data/lib/nasl/parser/foreach.rb +45 -0
  27. data/lib/nasl/parser/function.rb +45 -0
  28. data/lib/nasl/parser/global.rb +41 -0
  29. data/lib/nasl/parser/identifier.rb +43 -0
  30. data/lib/nasl/parser/if.rb +45 -0
  31. data/lib/nasl/parser/import.rb +41 -0
  32. data/lib/nasl/parser/include.rb +41 -0
  33. data/lib/nasl/parser/increment.rb +48 -0
  34. data/lib/nasl/parser/integer.rb +70 -0
  35. data/lib/nasl/parser/ip.rb +43 -0
  36. data/lib/nasl/parser/local.rb +41 -0
  37. data/lib/nasl/parser/lvalue.rb +43 -0
  38. data/lib/nasl/parser/node.rb +73 -0
  39. data/lib/nasl/parser/repeat.rb +43 -0
  40. data/lib/nasl/parser/repetition.rb +43 -0
  41. data/lib/nasl/parser/return.rb +41 -0
  42. data/lib/nasl/parser/string.rb +48 -0
  43. data/lib/nasl/parser/tree.rb +59 -0
  44. data/lib/nasl/parser/undefined.rb +35 -0
  45. data/lib/nasl/parser/while.rb +43 -0
  46. data/lib/nasl/parser.rb +45 -0
  47. data/lib/nasl/test.rb +98 -0
  48. data/lib/nasl/token.rb +69 -0
  49. data/lib/nasl/tokenizer.rb +327 -0
  50. data/lib/nasl/version.rb +3 -0
  51. data/lib/nasl.rb +52 -0
  52. data/nasl.gemspec +26 -0
  53. data/test/test_helper.rb +6 -0
  54. data/test/unit/parser/test_assignment.rb +111 -0
  55. data/test/unit/parser/test_blank.rb +44 -0
  56. data/test/unit/parser/test_block.rb +35 -0
  57. data/test/unit/parser/test_constant.rb +65 -0
  58. data/test/unit/parser/test_empty.rb +36 -0
  59. data/test/unit/parser/test_expressions.rb +57 -0
  60. data/test/unit/parser/test_function.rb +82 -0
  61. data/test/unit/parser/test_if.rb +85 -0
  62. data/test/unit/parser/test_include.rb +37 -0
  63. data/test/unit/parser/test_incr_decr.rb +51 -0
  64. data/test/unit/parser/test_ip.rb +33 -0
  65. data/test/unit/parser/test_return.rb +51 -0
  66. data/test/unit/parser/test_string.rb +46 -0
  67. data/test/unit/parser/test_whitespace.rb +56 -0
  68. data/test/unit/test_context.rb +240 -0
  69. data/test/unit/tokenizer/test_empty.rb +53 -0
  70. data/test/unit/tokenizer/test_integer.rb +68 -0
  71. data/test/unit/tokenizer/test_string.rb +94 -0
  72. metadata +161 -0
@@ -0,0 +1,94 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011, Mak Kolybabi
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ class TestTokenizerString < Test::Unit::TestCase
28
+ include Nasl::Test
29
+
30
+ def test_empty
31
+ # Tokenize empty single-quoted string.
32
+ tkz = tokenize(%q|''|)
33
+ type, tok = tkz.get_token
34
+ assert_equal(:DATA, type)
35
+ assert_equal("", tok.body)
36
+
37
+ # Tokenize empty double-quoted string.
38
+ tkz = tokenize(%q|""|)
39
+ type, tok = tkz.get_token
40
+ assert_equal(:STRING, type)
41
+ assert_equal("", tok.body)
42
+ end
43
+
44
+ def test_trailing_escapes
45
+ # Tokenize single-quoted string with trailing escape character. This should
46
+ # raise an exception single-quoted strings allow escape sequences, including
47
+ # escaping single quotes.
48
+ tkz = tokenize(%q|'\\'|)
49
+ assert_raise(Nasl::TokenException) { tkz.get_token }
50
+
51
+ # Tokenize double-quoted string with trailing escape character. This should
52
+ # not raise an exception since double-quoted strings do not allow escape
53
+ # sequences.
54
+ tkz = tokenize(%q|"\\"|)
55
+ assert_nothing_raised(Nasl::TokenException) { tkz.get_token }
56
+ end
57
+
58
+ def test_multiple_escapes
59
+ 1.upto(10) do |i|
60
+ tkz = tokenize("'" + ("\\" * i) + "'")
61
+
62
+ # If there are an even number of escape sequences, then each one is
63
+ # 'stuffed' so it is a valid single-quoted string.
64
+ fn = if i % 2 == 0 then :assert_nothing_raised else :assert_raise end
65
+ self.send(fn, Nasl::TokenException) { tkz.get_token }
66
+ end
67
+
68
+ 1.upto(10) do |i|
69
+ # Any number of repeated escape sequences is fine, since they're ignored.
70
+ tkz = tokenize('"' + ("\\" * i) + '"')
71
+ assert_nothing_raised(Nasl::TokenException) { tkz.get_token }
72
+ end
73
+ end
74
+
75
+ def test_missing_quote
76
+ # Tokenize unterminated single-quoted string.
77
+ tkz = tokenize(%q|'|)
78
+ assert_raise(Nasl::TokenException) { tkz.get_token }
79
+
80
+ # Tokenize unterminated double-quoted string.
81
+ tkz = tokenize(%q|"|)
82
+ assert_raise(Nasl::TokenException) { tkz.get_token }
83
+ end
84
+
85
+ def test_multiline
86
+ # Tokenize multiline single-quoted string.
87
+ tkz = tokenize(%q|'\n.\n.\n'|)
88
+ assert_nothing_raised(Nasl::TokenException) { tkz.get_token }
89
+
90
+ # Tokenize multiline double-quoted string.
91
+ tkz = tokenize(%q|"\n.\n.\n"|)
92
+ assert_nothing_raised(Nasl::TokenException) { tkz.get_token }
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nasl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mak Kolybabi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &17200984620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *17200984620
25
+ - !ruby/object:Gem::Dependency
26
+ name: builder
27
+ requirement: &17200984200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *17200984200
36
+ - !ruby/object:Gem::Dependency
37
+ name: racc
38
+ requirement: &17200983780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *17200983780
47
+ - !ruby/object:Gem::Dependency
48
+ name: rainbow
49
+ requirement: &17200983360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *17200983360
58
+ description:
59
+ email:
60
+ - mak@kolybabi.com
61
+ executables:
62
+ - nasl-parse
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - Rakefile
69
+ - bin/nasl-parse
70
+ - lib/nasl.rb
71
+ - lib/nasl/cli.rb
72
+ - lib/nasl/command.rb
73
+ - lib/nasl/commands/benchmark.rb
74
+ - lib/nasl/commands/parse.rb
75
+ - lib/nasl/commands/test.rb
76
+ - lib/nasl/commands/tokenize.rb
77
+ - lib/nasl/commands/xml.rb
78
+ - lib/nasl/context.rb
79
+ - lib/nasl/grammar.racc
80
+ - lib/nasl/parser.rb
81
+ - lib/nasl/parser/argument.rb
82
+ - lib/nasl/parser/assigment.rb
83
+ - lib/nasl/parser/block.rb
84
+ - lib/nasl/parser/break.rb
85
+ - lib/nasl/parser/call.rb
86
+ - lib/nasl/parser/continue.rb
87
+ - lib/nasl/parser/decrement.rb
88
+ - lib/nasl/parser/empty.rb
89
+ - lib/nasl/parser/export.rb
90
+ - lib/nasl/parser/expression.rb
91
+ - lib/nasl/parser/for.rb
92
+ - lib/nasl/parser/foreach.rb
93
+ - lib/nasl/parser/function.rb
94
+ - lib/nasl/parser/global.rb
95
+ - lib/nasl/parser/identifier.rb
96
+ - lib/nasl/parser/if.rb
97
+ - lib/nasl/parser/import.rb
98
+ - lib/nasl/parser/include.rb
99
+ - lib/nasl/parser/increment.rb
100
+ - lib/nasl/parser/integer.rb
101
+ - lib/nasl/parser/ip.rb
102
+ - lib/nasl/parser/local.rb
103
+ - lib/nasl/parser/lvalue.rb
104
+ - lib/nasl/parser/node.rb
105
+ - lib/nasl/parser/repeat.rb
106
+ - lib/nasl/parser/repetition.rb
107
+ - lib/nasl/parser/return.rb
108
+ - lib/nasl/parser/string.rb
109
+ - lib/nasl/parser/tree.rb
110
+ - lib/nasl/parser/undefined.rb
111
+ - lib/nasl/parser/while.rb
112
+ - lib/nasl/test.rb
113
+ - lib/nasl/token.rb
114
+ - lib/nasl/tokenizer.rb
115
+ - lib/nasl/version.rb
116
+ - nasl.gemspec
117
+ - test/test_helper.rb
118
+ - test/unit/parser/test_assignment.rb
119
+ - test/unit/parser/test_blank.rb
120
+ - test/unit/parser/test_block.rb
121
+ - test/unit/parser/test_constant.rb
122
+ - test/unit/parser/test_empty.rb
123
+ - test/unit/parser/test_expressions.rb
124
+ - test/unit/parser/test_function.rb
125
+ - test/unit/parser/test_if.rb
126
+ - test/unit/parser/test_include.rb
127
+ - test/unit/parser/test_incr_decr.rb
128
+ - test/unit/parser/test_ip.rb
129
+ - test/unit/parser/test_return.rb
130
+ - test/unit/parser/test_string.rb
131
+ - test/unit/parser/test_whitespace.rb
132
+ - test/unit/test_context.rb
133
+ - test/unit/tokenizer/test_empty.rb
134
+ - test/unit/tokenizer/test_integer.rb
135
+ - test/unit/tokenizer/test_string.rb
136
+ - lib/nasl/grammar.tab.rb
137
+ homepage: http://github.com/mogigoma/nasl
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project: nasl
157
+ rubygems_version: 1.8.10
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: A parser for the Nessus Attack Scripting Language.
161
+ test_files: []