parser: use xss comments to clean make output
[nit.git] / src / parser / xss / parser.xss
index 3ca1bcd..49c742f 100644 (file)
@@ -1,20 +1,19 @@
-/* This file is part of NIT ( http://www.nitlanguage.org ).
- *
- * Copyright 2008 Jean Privat <jean@pryen.org>
- * Based on algorithms developped for ( http://www.sablecc.org/ ).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+$ // This file is part of NIT ( http://www.nitlanguage.org ).
+$ //
+$ // Copyright 2008 Jean Privat <jean@pryen.org>
+$ // Based on algorithms developped for ( http://www.sablecc.org/ ).
+$ //
+$ // Licensed under the Apache License, Version 2.0 (the "License");
+$ // you may not use this file except in compliance with the License.
+$ // You may obtain a copy of the License at
+$ //
+$ //     http://www.apache.org/licenses/LICENSE-2.0
+$ //
+$ // Unless required by applicable law or agreed to in writing, software
+$ // distributed under the License is distributed on an "AS IS" BASIS,
+$ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+$ // See the License for the specific language governing permissions and
+$ // limitations under the License.
 
 $ template make_parser()
 
@@ -24,7 +23,7 @@ private class State
        readable writable var _state: Int
 
        # The node stored with the state in the stack
-       readable writable var _nodes: nullable Object 
+       readable writable var _nodes: nullable Object
 
        init(state: Int, nodes: nullable Object)
        do
@@ -115,8 +114,8 @@ special ParserTable
                var lexer = _lexer
                while true do
                        var token = lexer.peek
-                       var last_pos = token.pos
-                       var last_line = token.line
+                       var last_pos = token.location.column_start
+                       var last_line = token.location.line_start
 
                        if token isa PError then
                                return new Start(null, token)
@@ -155,10 +154,11 @@ special ParserTable
                                var node1 = pop
                                assert node1 isa ${/parser/prods/prod/@ename}
                                var node = new Start(node1, node2)
-                               (new SearchTokensVisitor).visit(node)
+                               (new SearchTokensVisitor).enter_visit(node)
                                return node
                        else if action_type == 3 then # ERROR
-                               var node2 = new PError.init_error(lexer.filename, last_line, last_pos, error_messages[errors[action_value]])
+                               var location = new Location(lexer.filename, last_line, last_line, last_pos, last_pos)
+                               var node2 = new PError.init_error(error_messages[errors[action_value]],location)
                                var node = new Start(null, node2)
                                return node
                        end
@@ -197,6 +197,20 @@ special Visitor
                        _untokenned_nodes.add(n)
                        n.visit_all(self)
                        n.last_token = _last_token
+
+                       if n.first_token != null then
+                               var start_location = n.first_token.location
+                               var end_location = _last_token.location
+
+                               if start_location != null and end_location != null then
+                                       var file = end_location.file
+                                       var line_start = start_location.line_start
+                                       var line_end = end_location.line_end
+                                       var column_start = start_location.column_start
+                                       var column_end = end_location.column_end
+                                       n.location = new Location(file, line_start, line_end, column_start, column_end)
+                               end
+                       end
                end
        end
        init
@@ -282,9 +296,9 @@ abstract class ParserTable
        var _action_table: Array[Array[Int]]
        private fun build_action_table
        do
-               _action_table = once [ 
+               _action_table = once [
 $ foreach {parser_data/action_table/row}
-                       action_table_row${position()}[-sep ','-]
+                       action_table_row${position()}[-sep ','-]
 $ end foreach
                ]
        end
@@ -294,22 +308,22 @@ $ foreach {parser_data/action_table/row}
        do
                return [
 $   foreach {action}
-                               @from, @action, @to [-sep ','-]
+                               @from, @action, @to[-sep ','-]
 $   end foreach
-                       ]
+                       ]
        end
 $ end foreach
 
        var _goto_table: Array[Array[Int]]
        private fun build_goto_table
        do
-               _goto_table = once [ 
+               _goto_table = once [
 $ foreach {parser_data/goto_table/row}
                        [
 $   foreach {goto}
-                               @from, @to [-sep ','-]
+                               @from, @to[-sep ','-]
 $   end foreach
-                       ] [-sep ','-]
+                       ][-sep ','-]
 $ end foreach
                ]
        end
@@ -318,7 +332,7 @@ $ end foreach
        do
                return once [
 $ foreach {parser_data/error_messages/msg}
-                       "${sablecc:string2escaped_unicode(.)}" [-sep ','-]
+                       "${sablecc:string2escaped_unicode(.)}"[-sep ','-]
 $ end
                ]
        end
@@ -326,7 +340,7 @@ $ end
        private fun errors: Array[Int]
        do
                return once [
-                       [-foreach {parser_data/errors/i}-]${.} [-sep ','-] [-end-]
+                       [-foreach {parser_data/errors/i}-]${.}[-sep ','-][-end-]
                ]
        end