File tree Expand file tree Collapse file tree
src/main/java/expr_parser/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package expr_parser .utils ;
2+
3+ import java .util .LinkedHashMap ;
4+ import java .util .LinkedList ;
5+ import java .util .Queue ;
6+
7+ import expr_parser .visitors .AntlrExpressionParser ;
8+ import expr_parser .visitors .ExpandSymbols ;
9+
10+ public class SymbolExpander {
11+ public static final LinkedHashMap <String , String > expandSymbols (
12+ LinkedHashMap <String , String > context ) {
13+ // we expect a toposorted context, ergo linkedHM
14+ LinkedList <String > queue = new LinkedList <String >();
15+ queue .addAll (context .keySet ());
16+ return expandSymbols (context , queue );
17+ }
18+
19+ private static final LinkedHashMap <String , String > expandSymbols (
20+ LinkedHashMap <String , String > context , Queue <String > queue ) {
21+ while (!queue .isEmpty ()) {
22+ String s = queue .remove ();
23+ AntlrExpressionParser p = new AntlrExpressionParser (context .get (s ));
24+ ExpandSymbols expander = new ExpandSymbols (context );
25+ context .put (s , p .parseAndVisitWith (expander ));
26+ expandSymbols (context , queue );
27+ }
28+ return context ;
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments