/usr/lib/falcon/parser/genparser/context.fal is in libfalcon-engine1 0.9.6.9-git20120606-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | /*
FALCON - Generic Parser
FILE: context.fal
Generic parser, Syntactic Tree context.
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: Thu, 19 Aug 2010 01:34:20 +0200
-------------------------------------------------------------------
(C) Copyright 2010: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
import from .node
/*# Syntree context.
Has support to create the syntree as the parsing proceeds.
*/
class Context()
row = 1
topNode = node.Node( node.node_top_type )
nodeStack = [ self.topNode ]
standouts = []
currentNode = self.topNode
listDepth = 0
/*# Adds a node in the context stack.
@param lnode Node to be added.
*/
function pushNode( lnode )
self.currentNode.add( lnode )
self.nodeStack.add( lnode )
self.currentNode = lnode
if lnode provides standout and lnode.standout
self.standouts.add( lnode )
end
end
/*# Remove last node in the stack.
@return The topmost stack node.
*/
function popNode()
ns = self.nodeStack
lnode = ns[-1]
if ns.len() == 1
raise ParseError( 10010, "Context empty in pop" )
end
ns.resize(ns.len()-1)
self.currentNode = ns[-1]
return lnode
end
/*# Adds data to the current node.
@param Data the data to be added.
The data may be either a string or a full node-headed structure.
*/
function add( data )
self.currentNode.add( data )
if data provides standout and data.standout
self.standouts.add( data )
end
end
/*# Creates a list and sets the list depth.
@param lvl Current level of the list.
@param ltype Type of list.
Can make a list deeper or flatter. Setting level to 0 is the same as closing the list.
The type of the list may be "ol" or "ul".
*/
function setListDepth( lvl, ltype )
if lvl == self.listDepth
self.popNode()
self.pushNode( node.Node("li") )
elif lvl < self.listDepth
// we must go back of 2 elements per level
i = lvl
while i++ < self.listDepth
self.popNode()
self.popNode()
end
self.listDepth = lvl
// but also, change the item that was li-ing if the list continues
if lvl > 0
self.popNode()
self.pushNode( node.Node("li") )
end
else
// we must go forward of 2 elements per level
i = self.listDepth
while i++ < lvl
self.pushNode(node.Node(ltype))
self.pushNode(node.Node("li"))
end
end
self.listDepth = lvl
end
end
|