nasl 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/bin/nasl-parse +1 -1
  2. data/lib/nasl.rb +1 -1
  3. data/lib/nasl/cli.rb +1 -1
  4. data/lib/nasl/command.rb +1 -1
  5. data/lib/nasl/commands/benchmark.rb +1 -1
  6. data/lib/nasl/commands/parse.rb +1 -1
  7. data/lib/nasl/commands/test.rb +1 -1
  8. data/lib/nasl/commands/tokenize.rb +2 -2
  9. data/lib/nasl/commands/xml.rb +1 -1
  10. data/lib/nasl/context.rb +1 -1
  11. data/lib/nasl/grammar.racc +23 -2
  12. data/lib/nasl/parser.rb +1 -1
  13. data/lib/nasl/parser/argument.rb +1 -1
  14. data/lib/nasl/parser/assigment.rb +1 -1
  15. data/lib/nasl/parser/block.rb +1 -1
  16. data/lib/nasl/parser/break.rb +1 -1
  17. data/lib/nasl/parser/call.rb +1 -1
  18. data/lib/nasl/parser/comment.rb +46 -0
  19. data/lib/nasl/parser/continue.rb +1 -1
  20. data/lib/nasl/parser/decrement.rb +1 -1
  21. data/lib/nasl/parser/empty.rb +1 -1
  22. data/lib/nasl/parser/export.rb +1 -1
  23. data/lib/nasl/parser/expression.rb +1 -1
  24. data/lib/nasl/parser/for.rb +1 -1
  25. data/lib/nasl/parser/foreach.rb +1 -1
  26. data/lib/nasl/parser/function.rb +1 -1
  27. data/lib/nasl/parser/global.rb +1 -1
  28. data/lib/nasl/parser/identifier.rb +1 -1
  29. data/lib/nasl/parser/if.rb +1 -1
  30. data/lib/nasl/parser/import.rb +1 -1
  31. data/lib/nasl/parser/include.rb +1 -1
  32. data/lib/nasl/parser/increment.rb +1 -1
  33. data/lib/nasl/parser/integer.rb +1 -1
  34. data/lib/nasl/parser/ip.rb +1 -1
  35. data/lib/nasl/parser/local.rb +1 -1
  36. data/lib/nasl/parser/lvalue.rb +1 -1
  37. data/lib/nasl/parser/node.rb +1 -1
  38. data/lib/nasl/parser/repeat.rb +1 -1
  39. data/lib/nasl/parser/repetition.rb +1 -1
  40. data/lib/nasl/parser/return.rb +1 -1
  41. data/lib/nasl/parser/string.rb +1 -1
  42. data/lib/nasl/parser/tree.rb +1 -1
  43. data/lib/nasl/parser/undefined.rb +1 -1
  44. data/lib/nasl/parser/while.rb +1 -1
  45. data/lib/nasl/test.rb +1 -1
  46. data/lib/nasl/token.rb +1 -1
  47. data/lib/nasl/tokenizer.rb +66 -5
  48. data/lib/nasl/version.rb +1 -1
  49. data/test/unit/parser/test_assignment.rb +1 -1
  50. data/test/unit/parser/test_blank.rb +1 -1
  51. data/test/unit/parser/test_block.rb +1 -1
  52. data/test/unit/parser/test_call.rb +1 -1
  53. data/test/unit/parser/test_comment.rb +140 -0
  54. data/test/unit/parser/test_constant.rb +1 -1
  55. data/test/unit/parser/test_empty.rb +1 -1
  56. data/test/unit/parser/test_expressions.rb +1 -1
  57. data/test/unit/parser/test_function.rb +1 -1
  58. data/test/unit/parser/test_if.rb +1 -1
  59. data/test/unit/parser/test_include.rb +1 -1
  60. data/test/unit/parser/test_incr_decr.rb +1 -1
  61. data/test/unit/parser/test_ip.rb +1 -1
  62. data/test/unit/parser/test_return.rb +1 -1
  63. data/test/unit/parser/test_string.rb +1 -1
  64. data/test/unit/parser/test_whitespace.rb +1 -1
  65. data/test/unit/test_context.rb +1 -1
  66. data/test/unit/tokenizer/test_comment.rb +218 -0
  67. data/test/unit/tokenizer/test_empty.rb +1 -9
  68. data/test/unit/tokenizer/test_integer.rb +1 -1
  69. data/test/unit/tokenizer/test_string.rb +1 -1
  70. metadata +34 -11
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  ################################################################################
4
- # Copyright (c) 2011, Mak Kolybabi
4
+ # Copyright (c) 2011-2012, Mak Kolybabi
5
5
  # All rights reserved.
6
6
  #
7
7
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -34,7 +34,7 @@ module Nasl
34
34
  contents = File.open(path, "rb").read
35
35
 
36
36
  begin
37
- Tokenizer.new(contents).get_tokens
37
+ Tokenizer.new(contents, path).get_tokens
38
38
  rescue TokenException => e
39
39
  puts "The tokenizer raised the following exceptions when processing #{path}:"
40
40
  puts e.message
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -70,8 +70,12 @@ rule
70
70
  { [val[0]] }
71
71
  ;
72
72
 
73
- root : export
73
+ root : COMMENT export
74
+ { c(*val) }
75
+ | export
74
76
  { val[0] }
77
+ | COMMENT function
78
+ { c(*val) }
75
79
  | function
76
80
  { val[0] }
77
81
  | statement
@@ -110,6 +114,8 @@ rule
110
114
  { val[0] }
111
115
  | empty
112
116
  { val[0] }
117
+ | COMMENT global
118
+ { c(*val) }
113
119
  | global
114
120
  { val[0] }
115
121
  | import
@@ -454,6 +460,7 @@ require 'nasl/parser/assigment'
454
460
  require 'nasl/parser/block'
455
461
  require 'nasl/parser/break'
456
462
  require 'nasl/parser/call'
463
+ require 'nasl/parser/comment'
457
464
  require 'nasl/parser/continue'
458
465
  require 'nasl/parser/decrement'
459
466
  require 'nasl/parser/empty'
@@ -496,15 +503,29 @@ def n(cls, *args)
496
503
  end
497
504
  end
498
505
 
506
+ def c(*args)
507
+ n(:Comment, *args)
508
+ args[1]
509
+ end
510
+
499
511
  def on_error(type, value, stack)
500
512
  raise ParseException, "The language's grammar does not permit #{value.name} to appear here", value.context
501
513
  end
502
514
 
503
515
  def next_token
504
516
  @tok = @tkz.get_token
517
+
518
+ if @first && @tok.first == :COMMENT
519
+ n(:Comment, @tok.last)
520
+ @tok = @tkz.get_token
521
+ end
522
+ @first = false
523
+
524
+ return @tok
505
525
  end
506
526
 
507
527
  def parse(env, code, path)
528
+ @first = true
508
529
  @tree = Tree.new(env)
509
530
  @tkz = Tokenizer.new(code, path)
510
531
  @tree.concat(do_parse)
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -0,0 +1,46 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2012, 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
+ require 'nasl/parser/node'
28
+
29
+ module Nasl
30
+ class Comment < Node
31
+ attr_reader :next, :text
32
+
33
+ def initialize(tree, *tokens)
34
+ super
35
+
36
+ @text = @tokens.first
37
+ @next = @tokens.last
38
+
39
+ @next = nil if @tokens.length == 1
40
+ end
41
+
42
+ def to_xml(xml)
43
+ xml.comment(@text)
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without