use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class DefineSharedVariableParser method parseDefinitions.
/**
* Parse defitions.
* @return List of parsed definitions.
*/
public List<Definition> parseDefinitions() {
// Some sanity.
final AstNode parentNode = node.getParent();
final AstNode atomNode = parentNode.getFirstChild();
if (atomNode.isNot(MagikGrammar.ATOM)) {
throw new IllegalStateException();
}
// Assume this is an exemplar.
final String exemplarName = atomNode.getTokenValue();
if (exemplarName == null) {
throw new IllegalStateException();
}
final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.SYMBOL);
if (argument0Node == null || argument2Node == null) {
throw new IllegalStateException();
}
// Figure statement node.
final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
// Figure pakkage.
final String pakkage = this.getCurrentPakkage();
final String variableNameSymbol = argument0Node.getTokenValue();
final String variableName = variableNameSymbol.substring(1);
final String flavor = argument2Node.getTokenValue();
final List<MethodDefinition> methodDefinitions = this.generateVariableMethods(statementNode, pakkage, exemplarName, variableName, flavor);
return List.copyOf(methodDefinitions);
}
use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class DefineSlotAccessParser method parseDefinitions.
/**
* Parse defitions.
* @return List of parsed definitions.
*/
public List<Definition> parseDefinitions() {
final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
// Some sanity.
final AstNode parentNode = node.getParent();
final AstNode atomNode = parentNode.getFirstChild();
if (atomNode.isNot(MagikGrammar.ATOM)) {
throw new IllegalStateException();
}
final String exemplarName = atomNode.getTokenValue();
if (exemplarName == null) {
throw new IllegalStateException();
}
final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SYMBOL);
final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.SYMBOL);
if (argument0Node == null || argument1Node == null) {
throw new IllegalStateException();
}
// Figure statement node.
final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
// Figure pakkage.
final String pakkage = this.getCurrentPakkage();
final String slotNameSymbol = argument0Node.getTokenValue();
final String slotName = slotNameSymbol.substring(1);
final String flag = argument1Node.getTokenValue();
final String flavor = argument2Node != null ? argument2Node.getTokenValue() : // Default is public.
FLAVOR_PUBLIC;
final List<MethodDefinition> methodDefinitions = this.generateSlotMethods(statementNode, pakkage, exemplarName, slotName, flag, flavor);
return List.copyOf(methodDefinitions);
}
use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class DefEnumerationParser method parseDefinitions.
/**
* Parse defitions.
* @return List of parsed definitions.
*/
@Override
public List<Definition> parseDefinitions() {
final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
if (argument0Node == null) {
throw new IllegalStateException();
}
// Figure statement node.
final AstNode statementNode = this.node.getFirstAncestor(MagikGrammar.STATEMENT);
// Figure pakkage.
final String pakkage = this.getCurrentPakkage();
// Figure name.
final String name = argument0Node.getTokenValue().substring(1);
// Figure parents.
final List<String> parents = Collections.emptyList();
final EnumerationDefinition enumerationDefinition = new EnumerationDefinition(statementNode, pakkage, name, parents);
return List.of(enumerationDefinition);
}
use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class DefPackageParser method parseDefinitions.
/**
* Parse defitions.
* @return List of parsed definitions.
*/
@SuppressWarnings("checkstyle:NestedIfDepth")
public List<Definition> parseDefinitions() {
final AstNode argumentsNode = this.node.getFirstChild(MagikGrammar.ARGUMENTS);
final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
if (argument0Node == null) {
throw new IllegalStateException();
}
// Figure statement node.
final AstNode statementNode = this.node.getFirstAncestor(MagikGrammar.STATEMENT);
// Figure package.
final String pakkage = this.getCurrentPakkage();
// Figure name.
final String name = argument0Node.getTokenValue().substring(1);
// Figure uses-list.
final List<String> uses = new ArrayList<>();
final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SYMBOL);
if (argument1Node != null && argument1Node.getTokenValue().equals(":uses")) {
final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.SIMPLE_VECTOR);
if (argument2Node != null) {
for (final AstNode expressionNode : argument2Node.getChildren(MagikGrammar.EXPRESSION)) {
final ExpressionNodeHelper expressionHelper = new ExpressionNodeHelper(expressionNode);
final String usesSymbol = expressionHelper.getConstant();
if (usesSymbol != null) {
final String usesName = usesSymbol.substring(1);
uses.add(usesName);
}
}
}
} else {
uses.add("sw");
}
final PackageDefinition packageDefinition = new PackageDefinition(statementNode, pakkage, name, uses);
return List.of(packageDefinition);
}
use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class Scope method getEndColumn.
/**
* Get the end column of this scope.
* @return End column.
*/
public int getEndColumn() {
final AstNode parentNode = this.node.getParent();
final List<Token> tokens = parentNode.getTokens();
final Token lastToken = tokens.get(tokens.size() - 1);
return lastToken.getColumn();
}
Aggregations