Package org.qdl_lang.parsing
Class ParsingMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,ParseRecord>
-
- org.qdl_lang.parsing.ParsingMap
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,ParseRecord>
public class ParsingMap extends HashMap<String,ParseRecord>
Created by Jeff Gaynor
on 1/15/20 at 6:19 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description ParsingMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearMark()
void
endMark()
ParseRecord
findAncestor(org.antlr.v4.runtime.tree.ParseTree parseTree)
Find the parent or grandparent etc.ParseRecord
findFirstChild(org.antlr.v4.runtime.tree.ParseTree parseTree)
In this case we have the id of a node that is not in this map because there are many types of intermediate node created by the parser we just don't record.ParseRecord
findFirstChild(org.antlr.v4.runtime.tree.ParseTree parseTree, boolean returnNullOK)
List<String>
getAddedIds()
ArrayList<Element>
getElements()
At the end of parsing, this has all of the executable elements in it.protected List<String>
getKidIds(String id)
protected List<org.antlr.v4.runtime.tree.ParseTree>
getKids(org.antlr.v4.runtime.tree.ParseTree parseTree)
ParseRecord
getRoot()
Statement
getStatementFromContext(org.antlr.v4.runtime.tree.ParseTree context)
void
nukeIt(org.antlr.v4.runtime.tree.ParseTree parseTree)
This will find all the child nodes in this map and remove the entire tree.void
put(ElementRecord record)
void
put(StatementRecord record)
void
rollback()
void
setAddedIds(List<String> addedIds)
void
setRoot(ParseRecord root)
void
startMark()
void
startMark(boolean clearAdded)
-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
-
-
-
Method Detail
-
startMark
public void startMark()
-
startMark
public void startMark(boolean clearAdded)
-
endMark
public void endMark()
-
rollback
public void rollback()
-
clearMark
public void clearMark()
-
getRoot
public ParseRecord getRoot()
-
setRoot
public void setRoot(ParseRecord root)
-
getElements
public ArrayList<Element> getElements()
At the end of parsing, this has all of the executable elements in it. Get this, grab the included statement(it's just a wrapper class) and you are off.- Returns:
-
put
public void put(ElementRecord record)
-
put
public void put(StatementRecord record)
-
getStatementFromContext
public Statement getStatementFromContext(org.antlr.v4.runtime.tree.ParseTree context)
-
findAncestor
public ParseRecord findAncestor(org.antlr.v4.runtime.tree.ParseTree parseTree)
Find the parent or grandparent etc. of the node in this map. A common pattern is, e.g. having a heavily parenthesized expression in the source like
(((a<b) &&...
which may have arbitrarily many association contexts wrapped around it. Our creation of the standard tree omits such parsing cruft so this will trace back to the ancestor.- Parameters:
parseTree
-- Returns:
-
nukeIt
public void nukeIt(org.antlr.v4.runtime.tree.ParseTree parseTree)
This will find all the child nodes in this map and remove the entire tree. This is useful if, for instance you have defined a bunch of statements in a function definition or some such.- Parameters:
parseTree
-
-
findFirstChild
public ParseRecord findFirstChild(org.antlr.v4.runtime.tree.ParseTree parseTree)
In this case we have the id of a node that is not in this map because there are many types of intermediate node created by the parser we just don't record. This will take an id then look at the parent child relations and return the first child it finds in this map. E.g.,A → B → C → D
In this case, A is in the map, B and C are artifacts of parsing that are not in the map and we need D. So we take the ParseTree for A, look at the childen for B and continue until D is found. Use this sparingly since it may end up snooping through a lot of nodes, however, this is about the best option for finding this.- Parameters:
parseTree
-- Returns:
-
findFirstChild
public ParseRecord findFirstChild(org.antlr.v4.runtime.tree.ParseTree parseTree, boolean returnNullOK)
-
getKids
protected List<org.antlr.v4.runtime.tree.ParseTree> getKids(org.antlr.v4.runtime.tree.ParseTree parseTree)
-
-