# The node stored with the state in the stack
var nodes: nullable Object
-
- init(state: Int, nodes: nullable Object)
- do
- _state = state
- _nodes = nodes
- end
end
# The parser of the Nit language.
var lexer: Lexer
# Stack of pushed states and productions
- private var stack: Array[State]
+ private var stack = new Array[State]
# Position in the stack
- private var stack_pos: Int
+ private var stack_pos: Int = -1
- # Create a new parser based on a given lexer
- init(lexer: Lexer)
+ init
do
- _lexer = lexer
- _stack = new Array[State]
- _stack_pos = -1
build_reduce_table
end
end
end
- private var reduce_table: Array[ReduceAction]
+ private var reduce_table: Array[ReduceAction] is noinit
private fun build_reduce_table is abstract
end
# Location on the first token after the start of a production
# So outside the production for epsilon production
var first_location: nullable Location
+
+ # Join the text of all visited tokens
+ fun collect_text: String
+ do
+ var v = new TextCollectorVisitor
+ v.enter_visit(self)
+ assert v.text != ""
+ return v.text
+ end
end
# Find location of production nodes
end
end
+private class TextCollectorVisitor
+ super Visitor
+ var text: String = ""
+ redef fun visit(n)
+ do
+ if n isa Token then text += n.text
+ n.visit_all(self)
+ end
+end
+
+
# Each reduce action has its own class, this one is the root of the hierarchy.
private abstract class ReduceAction
fun action(p: Parser) is abstract
return l1
end
var goto: Int
- init(g: Int) do _goto = g
end