nasl 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nasl-parse +1 -1
- data/lib/nasl.rb +1 -1
- data/lib/nasl/cli.rb +1 -1
- data/lib/nasl/command.rb +1 -1
- data/lib/nasl/commands/benchmark.rb +1 -1
- data/lib/nasl/commands/parse.rb +1 -1
- data/lib/nasl/commands/test.rb +1 -1
- data/lib/nasl/commands/tokenize.rb +2 -2
- data/lib/nasl/commands/xml.rb +1 -1
- data/lib/nasl/context.rb +1 -1
- data/lib/nasl/grammar.racc +23 -2
- data/lib/nasl/parser.rb +1 -1
- data/lib/nasl/parser/argument.rb +1 -1
- data/lib/nasl/parser/assigment.rb +1 -1
- data/lib/nasl/parser/block.rb +1 -1
- data/lib/nasl/parser/break.rb +1 -1
- data/lib/nasl/parser/call.rb +1 -1
- data/lib/nasl/parser/comment.rb +46 -0
- data/lib/nasl/parser/continue.rb +1 -1
- data/lib/nasl/parser/decrement.rb +1 -1
- data/lib/nasl/parser/empty.rb +1 -1
- data/lib/nasl/parser/export.rb +1 -1
- data/lib/nasl/parser/expression.rb +1 -1
- data/lib/nasl/parser/for.rb +1 -1
- data/lib/nasl/parser/foreach.rb +1 -1
- data/lib/nasl/parser/function.rb +1 -1
- data/lib/nasl/parser/global.rb +1 -1
- data/lib/nasl/parser/identifier.rb +1 -1
- data/lib/nasl/parser/if.rb +1 -1
- data/lib/nasl/parser/import.rb +1 -1
- data/lib/nasl/parser/include.rb +1 -1
- data/lib/nasl/parser/increment.rb +1 -1
- data/lib/nasl/parser/integer.rb +1 -1
- data/lib/nasl/parser/ip.rb +1 -1
- data/lib/nasl/parser/local.rb +1 -1
- data/lib/nasl/parser/lvalue.rb +1 -1
- data/lib/nasl/parser/node.rb +1 -1
- data/lib/nasl/parser/repeat.rb +1 -1
- data/lib/nasl/parser/repetition.rb +1 -1
- data/lib/nasl/parser/return.rb +1 -1
- data/lib/nasl/parser/string.rb +1 -1
- data/lib/nasl/parser/tree.rb +1 -1
- data/lib/nasl/parser/undefined.rb +1 -1
- data/lib/nasl/parser/while.rb +1 -1
- data/lib/nasl/test.rb +1 -1
- data/lib/nasl/token.rb +1 -1
- data/lib/nasl/tokenizer.rb +66 -5
- data/lib/nasl/version.rb +1 -1
- data/test/unit/parser/test_assignment.rb +1 -1
- data/test/unit/parser/test_blank.rb +1 -1
- data/test/unit/parser/test_block.rb +1 -1
- data/test/unit/parser/test_call.rb +1 -1
- data/test/unit/parser/test_comment.rb +140 -0
- data/test/unit/parser/test_constant.rb +1 -1
- data/test/unit/parser/test_empty.rb +1 -1
- data/test/unit/parser/test_expressions.rb +1 -1
- data/test/unit/parser/test_function.rb +1 -1
- data/test/unit/parser/test_if.rb +1 -1
- data/test/unit/parser/test_include.rb +1 -1
- data/test/unit/parser/test_incr_decr.rb +1 -1
- data/test/unit/parser/test_ip.rb +1 -1
- data/test/unit/parser/test_return.rb +1 -1
- data/test/unit/parser/test_string.rb +1 -1
- data/test/unit/parser/test_whitespace.rb +1 -1
- data/test/unit/test_context.rb +1 -1
- data/test/unit/tokenizer/test_comment.rb +218 -0
- data/test/unit/tokenizer/test_empty.rb +1 -9
- data/test/unit/tokenizer/test_integer.rb +1 -1
- data/test/unit/tokenizer/test_string.rb +1 -1
- metadata +34 -11
data/bin/nasl-parse
CHANGED
@@ -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
|
data/lib/nasl.rb
CHANGED
data/lib/nasl/cli.rb
CHANGED
data/lib/nasl/command.rb
CHANGED
data/lib/nasl/commands/parse.rb
CHANGED
data/lib/nasl/commands/test.rb
CHANGED
@@ -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
|
data/lib/nasl/commands/xml.rb
CHANGED
data/lib/nasl/context.rb
CHANGED
data/lib/nasl/grammar.racc
CHANGED
@@ -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)
|
data/lib/nasl/parser.rb
CHANGED
data/lib/nasl/parser/argument.rb
CHANGED
data/lib/nasl/parser/block.rb
CHANGED
data/lib/nasl/parser/break.rb
CHANGED
data/lib/nasl/parser/call.rb
CHANGED
@@ -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
|
data/lib/nasl/parser/continue.rb
CHANGED
data/lib/nasl/parser/empty.rb
CHANGED
data/lib/nasl/parser/export.rb
CHANGED
data/lib/nasl/parser/for.rb
CHANGED
data/lib/nasl/parser/foreach.rb
CHANGED
data/lib/nasl/parser/function.rb
CHANGED
data/lib/nasl/parser/global.rb
CHANGED
data/lib/nasl/parser/if.rb
CHANGED
data/lib/nasl/parser/import.rb
CHANGED
data/lib/nasl/parser/include.rb
CHANGED
data/lib/nasl/parser/integer.rb
CHANGED
data/lib/nasl/parser/ip.rb
CHANGED
data/lib/nasl/parser/local.rb
CHANGED
data/lib/nasl/parser/lvalue.rb
CHANGED
data/lib/nasl/parser/node.rb
CHANGED
data/lib/nasl/parser/repeat.rb
CHANGED
data/lib/nasl/parser/return.rb
CHANGED
data/lib/nasl/parser/string.rb
CHANGED
data/lib/nasl/parser/tree.rb
CHANGED