diff --git a/core/src/main/java/org/incenp/obofoundry/sssom/transform/SSSOMTransformReader.java b/core/src/main/java/org/incenp/obofoundry/sssom/transform/SSSOMTransformReader.java index c2a737c..9cd2885 100644 --- a/core/src/main/java/org/incenp/obofoundry/sssom/transform/SSSOMTransformReader.java +++ b/core/src/main/java/org/incenp/obofoundry/sssom/transform/SSSOMTransformReader.java @@ -402,28 +402,8 @@ public Void visitPrefixDecl(SSSOMTransformParser.PrefixDeclContext ctx) { @Override public Void visitHeaderDecl(SSSOMTransformParser.HeaderDeclContext ctx) { - String name = ctx.action().FUNCTION().getText(); - int nameLen = name.length(); - name = name.substring(0, nameLen - 1); - - ArrayList arguments = new ArrayList(); - - if ( ctx.action().arglist() != null ) { - for ( ArgumentContext argCtx : ctx.action().arglist().argument() ) { - if ( argCtx.string() != null ) { - arguments.add(unescape(argCtx.string().getText())); - } else if ( argCtx.IRI() != null ) { - String iri = argCtx.IRI().getText(); - int iriLen = iri.length(); - arguments.add(iri.substring(1, iriLen - 1)); - } else if ( argCtx.CURIE() != null ) { - arguments.add(prefixManager.expandIdentifier(argCtx.CURIE().getText())); - } - } - } - try { - application.onHeaderAction(name, arguments); + application.onHeaderAction(getFunctionName(ctx.action()), getFunctionArguments(ctx.action())); } catch ( SSSOMTransformError e ) { errors.add(e); } @@ -490,28 +470,9 @@ public Void visitAction(SSSOMTransformParser.ActionContext ctx) { filter = fs; } - // Get function name - String name = ctx.FUNCTION().getText(); - int nameLen = name.length(); - name = name.substring(0, nameLen - 1); - - // Assemble the arguments list - List arguments = new ArrayList(); - if ( ctx.arglist() != null ) { - for ( ArgumentContext argCtx : ctx.arglist().argument() ) { - if ( argCtx.string() != null ) { - arguments.add(unescape(argCtx.string().getText())); - } else if ( argCtx.IRI() != null ) { - String iri = argCtx.IRI().getText(); - int iriLen = iri.length(); - arguments.add(iri.substring(1, iriLen - 1)); - } else if ( argCtx.CURIE() != null ) { - arguments.add(prefixManager.expandIdentifier(argCtx.CURIE().getText())); - } - } - } - // Get the action from the application + String name = getFunctionName(ctx); + List arguments = getFunctionArguments(ctx); IMappingTransformer preprocessor = null; IMappingTransformer generator = null; try { @@ -543,6 +504,37 @@ public Void visitAction(SSSOMTransformParser.ActionContext ctx) { return null; } + // Remove the trailing '(' to get the name of the function + private String getFunctionName(SSSOMTransformParser.ActionContext ctx) { + String name = ctx.FUNCTION().getText(); + int nameLen = name.length(); + return name.substring(0, nameLen - 1); + } + + // Process arguments in a function call: + // - unescape string arguments + // - remove enclosing brackets of IRI arguments + // - expand CURIE arguments + private List getFunctionArguments(SSSOMTransformParser.ActionContext ctx) { + List arguments = new ArrayList(); + + if ( ctx.arglist() != null ) { + for ( ArgumentContext argCtx : ctx.arglist().argument() ) { + if ( argCtx.string() != null ) { + arguments.add(unescape(argCtx.string().getText())); + } else if ( argCtx.IRI() != null ) { + String iri = argCtx.IRI().getText(); + int iriLen = iri.length(); + arguments.add(iri.substring(1, iriLen - 1)); + } else if ( argCtx.CURIE() != null ) { + arguments.add(prefixManager.expandIdentifier(argCtx.CURIE().getText())); + } + } + } + + return arguments; + } + // Un-quote and un-escape the string as provided by the parser // This is static because it does not depend on any state and is re-used below // by the filter visitor.