Skip to content

Commit

Permalink
Improves parsing of LangSpecV2, removes LangSpecV1 refs in AbstractJo…
Browse files Browse the repository at this point in the history
…inPointClassGenerator
  • Loading branch information
joaobispo committed Jan 1, 2025
1 parent 698dcd4 commit 7fe30fc
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
/**
* Copyright 2016 SPeCS.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. under the License.
*/

package org.lara.language.specification.dsl;

import org.lara.language.specification.dsl.types.IType;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.lara.language.specification.dsl.types.ArrayType;
import org.lara.language.specification.dsl.types.IType;
import org.lara.language.specification.dsl.types.PrimitiveClasses;

/**
* A basic class that contains a type and a name
*
* @author tiago
*
* @author tiago
*/
public class Attribute extends BaseNode implements Comparable<Attribute> {

private Declaration declaration;
private List<Parameter> parameters;
private List<Def> defs;

public Attribute(IType type, String name) {
this(type, name, new ArrayList<>());
Expand All @@ -39,8 +37,9 @@ public Attribute(IType type, String name) {
public Attribute(IType type, String name, List<Parameter> parameters) {
declaration = new Declaration(type, name);
this.parameters = parameters;
this.defs = new ArrayList<>();
}

public void addParameter(IType type, String name) {
addParameter(type, name, "");
}
Expand All @@ -49,6 +48,14 @@ public void addParameter(IType type, String name, String defaultValue) {
parameters.add(new Parameter(type, name, defaultValue));
}

public void addDef(Def def) {
defs.add(def);
}

public List<Def> getDefs() {
return defs;
}

public IType getType() {
return declaration.getType();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/**
* Copyright 2016 SPeCS.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. under the License.
*/

package org.lara.language.specification.dsl.types;

import org.lara.language.specification.dsl.BaseNode;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.lara.language.specification.dsl.BaseNode;

public class EnumDef extends BaseNode implements IType {

private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright 2016 SPeCS.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. under the License.
Expand Down Expand Up @@ -77,6 +77,9 @@ public String getType() {

@Override
public String toString() {
return values.stream().collect(Collectors.joining("| ", "[", "]"));
//return values.stream().collect(Collectors.joining("| ", "[", "]"));

// To keep compatibility with previous code, since it is dependent on this format
return values.stream().collect(Collectors.joining(",", "{", "}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,23 @@ private static Attribute getAttribute(XmlElement attributeNode, LanguageSpecific
parameterNode.getAttribute("name"), parameterNode.getAttribute("default"));
}

var defNodes = attributeNode.getElementsByName("def");

for (var defNode : defNodes) {
// If def does not have a type, use the attribute type
newAttribute.addDef(parseDef(defNode, type));
}

return newAttribute;
}

private static Def parseDef(XmlElement defNode, String attributeType) {
// Check if it has an optional 'type'
var type = defNode.getAttribute("type", attributeType);

return new Def(type);
}

private static String getType(XmlElement node) {
// Default type is "void"
return node.getAttribute("type", "void");
Expand Down Expand Up @@ -293,7 +307,7 @@ private static List<Select> convertSelects(LanguageSpecificationV2 langSpecV2,
String alias = selectNode.getAttribute("alias");
alias = alias.equals(selectClassName) ? "" : alias; // Is this necessary?
Select newSelect = new Select(selectJP, alias);
newSelect.setToolTip(selectNode.getAttribute("tooltip"));
newSelect.setToolTip(selectNode.getAttribute("tooltip", null));
selects.add(newSelect);
}

Expand Down
Loading

0 comments on commit 7fe30fc

Please sign in to comment.