lib/markdown: allow to ignore the MDlocation on Tokens
authorJean Privat <jean@pryen.org>
Fri, 4 Mar 2016 06:22:51 +0000 (01:22 -0500)
committerJean Privat <jean@pryen.org>
Fri, 4 Mar 2016 06:22:51 +0000 (01:22 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

benchmarks/markdown/engines/nitmd/nitmd.nit
lib/markdown/markdown.nit
lib/markdown/test_markdown.nit

index 2db91b2..09c7d07 100644 (file)
@@ -19,6 +19,7 @@ var n = args[1].to_i
 
 var str = file.to_path.read_all
 var parser = new MarkdownProcessor
+parser.no_location = true
 for i in [1..n] do
        print parser.process(str)
 end
index 0676112..d63f3e4 100644 (file)
@@ -133,6 +133,14 @@ class MarkdownProcessor
        # ~~~
        var ext_mode = true
 
+       # Disable attaching MDLocation to Tokens
+       #
+       # Locations are useful for some tools but they may
+       # cause an important time and space overhead.
+       #
+       # Default = `false`
+       var no_location = false is writable
+
        init do self.emitter = new MarkdownEmitter(self)
 
        # Process the mardown `input` string and return the processed output.
@@ -397,11 +405,16 @@ class MarkdownProcessor
                        c2 = ' '
                end
 
-               var loc = new MDLocation(
-                       current_loc.line_start,
-                       current_loc.column_start + pos,
-                       current_loc.line_start,
-                       current_loc.column_start + pos)
+               var loc
+               if no_location then
+                       loc = null
+               else
+                       loc = new MDLocation(
+                               current_loc.line_start,
+                               current_loc.column_start + pos,
+                               current_loc.line_start,
+                               current_loc.column_start + pos)
+               end
 
                if c == '*' then
                        if c1 == '*' then
@@ -1940,7 +1953,7 @@ end
 abstract class Token
 
        # Location of `self` in the original input.
-       var location: MDLocation
+       var location: nullable MDLocation
 
        # Position of `self` in input independant from lines.
        var pos: Int
index 53c355f..8a2c7a0 100644 (file)
@@ -2830,7 +2830,7 @@ class TestTokenProcessor
        redef fun token_at(input, pos) do
                var token = super
                if token isa TokenNone then return token
-               var res = "{token.class_name} at {token.location}"
+               var res = "{token.class_name} at {token.location or else "?"}"
                var exp = test_stack.shift
                print ""
                print "EXP {exp}"