Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7811910eb62469140e16fc37e54bb7b586b3422f (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2018 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.dctools.fsm.ast.util

import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstBracketNode
import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstIdentifierNode
import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstNode
import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstPeriodNode
import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstWhitespaceNode
import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstOtherNode

class DCAstPrinter implements IDCAstNodeVisitor {
	
	val sb = new StringBuilder
	
	def getText() {
		sb.toString
	}
	
	override visitBegin(DCAstNode node) {
		
		switch node {
			DCAstBracketNode: sb.append(node.left)
			DCAstIdentifierNode: sb.append(node.id)
			DCAstPeriodNode: sb.append(".")
			DCAstWhitespaceNode: sb.append(node.text)
			DCAstOtherNode: sb.append(node.text)
		}
		
		return true
	}
	
	override visitEnd(DCAstNode node) {
		switch node {
			DCAstBracketNode: if (node.closed) sb.append(node.right)
		}
	}
}

Back to the top