// <label1>&<label2>&... => p(label1),p(label2),... private ArrayList<Predicate> getPredicateListFromArc(String placeName, Arc arc) throws ParseException { if (!MIDParser.isIdentifier(placeName)) throw new ParseException( placeName + " " + LocaleBundle.bundleString("should start with a letter")); String activeTokenClassID = CreateGui.getModel().getActiveTokenClassID(); int pos = CreateGui.getModel().getPosInList(activeTokenClassID, arc.getWeight()); if (pos >= 0) { String arcLabel = arc.getWeight().get(pos).getCurrentMarking().trim(); ArrayList<Predicate> predicates = new ArrayList<Predicate>(); try { ArrayList<ArrayList<String>> arcLabelList = MIDParser.parseArcLabelString(arcLabel); for (ArrayList<String> labelArguments : arcLabelList) predicates.add(new Predicate(placeName, labelArguments, arc instanceof InhibitorArc)); return predicates; } catch (ParseException e) { throw new ParseException( LocaleBundle.bundleString("Arc label") + " " + arcLabel + " (" + arc.getSource().getName() + " , " + arc.getTarget().getName() + "). " + e.toString()); } } return new ArrayList<Predicate>(); }
private void parseConstants(String text, String keyword) throws ParseException { String constantsString = text.substring(keyword.length()); if (constantsString.equals("")) return; try { MIDParser.parseNamedIntegersString(constantsString); } catch (ParseException e) { throw new ParseException( XMIDProcessor.CONSTANTS_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + "\n" + e.toString()); } catch (TokenMgrError e) { throw new ParseException( XMIDProcessor.CONSTANTS_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + ": " + LocaleBundle.bundleString("Lexical error")); } }
private void parseTokens(Marking marking, PipePlace place) throws ParseException { String activeTokenClassID = CreateGui.getModel().getActiveTokenClassID(); DataLayerInterface net = mainNet.getModel(); int pos = net.getPosInList(activeTokenClassID, place.getCurrentMarking()); if (pos >= 0) { String tokenString = place.getCurrentMarking().get(pos).getCurrentMarking().trim(); if (tokenString != null && !tokenString.equals("")) { ArrayList<Tuple> tokenList = new ArrayList<Tuple>(); try { tokenList = MIDParser.parseTokenString(tokenString); } catch (ParseException e) { throw new ParseException(place.getName() + ": " + tokenString + ". " + e.toString()); } if (tokenList.size() > 0) { // check arity consistency int firstArity = tokenList.get(0).arity(); for (int index = 1; index < tokenList.size(); index++) if (tokenList.get(0).arity() != firstArity) throw new ParseException( place.getName() + " " + LocaleBundle.bundleString("has inconsistent token length")); // check duplication checkDuplicateTokens(tokenList, place.getName(), tokenString); } marking.addTuples(place.getName(), tokenList); } } }
private void parseUnitTests(MID mid, String text, String keyword) throws ParseException { String unitTestString = text.substring(keyword.length()); if (unitTestString.trim().equals("")) return; ArrayList<Predicate> unitTests = null; try { unitTests = MIDParser.parseConditionString(unitTestString); } catch (ParseException e) { throw new ParseException( keyword + " " + LocaleBundle.bundleString("annotation") + " " + text + "\n" + e.toString()); } catch (TokenMgrError e) { throw new ParseException( keyword + " " + LocaleBundle.bundleString("annotation") + " " + text + ": " + LocaleBundle.bundleString("Lexical error")); } for (Predicate test : unitTests) mid.addUnitTest(test); }
private void parseNonNegativeEvents(MID mid, String text, String keyword) throws ParseException { String nonNegativeEventsString = text.substring(keyword.length()); if (nonNegativeEventsString.equals("")) return; try { ArrayList<String> nonNegativeEvents = MIDParser.parseIdentifierListString(nonNegativeEventsString); mid.setNonNegativeEvents(nonNegativeEvents); } catch (ParseException e) { throw new ParseException( XMIDProcessor.NONNEGATIVE_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + "\n" + e.toString()); } catch (TokenMgrError e) { throw new ParseException( XMIDProcessor.NONNEGATIVE_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + ": " + LocaleBundle.bundleString("Lexical error")); } }
private void parseEnumeration(String text, String keyword) throws ParseException { String enumerationString = text.substring(keyword.length()); if (enumerationString.equals("")) return; try { MIDParser.parseEnumerationString(enumerationString); } catch (ParseException e) { throw new ParseException( XMIDProcessor.ENUM_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + "\n" + e.toString()); } catch (TokenMgrError e) { throw new ParseException( XMIDProcessor.ENUM_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + ": " + LocaleBundle.bundleString("Lexical error")); } }
protected void parseMainModelAnnotationMarking(MID mid, String text) throws ParseException { String markingString = text.substring(XMIDProcessor.INIT_KEYWORD.length()); if (markingString.trim().equals("")) return; Marking marking = null; try { marking = MIDParser.parseMarkingString(markingString); mid.addInitialMarking(marking); } catch (ParseException e) { throw new ParseException( XMIDProcessor.INIT_KEYWORD + " " + LocaleBundle.bundleString("annotation") + " " + text + ". " + e.toString()); } }
private void parseAssertionPropertyAnnotations(MID mid) throws ParseException { DataLayerInterface net = mainNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.ASSERTION_KEYWORD)) { String assertionString = text.substring(XMIDProcessor.ASSERTION_KEYWORD.length()); if (!assertionString.trim().equals("")) { try { AssertionProperty assertion = MIDParser.parseAssertionPropertyString(assertionString); mid.addAssertionProperty(assertion); } catch (ParseException e) { throw new ParseException(text + ". " + e.toString()); } } } } }
protected Marking parseSubModelAnnotationMarking(String text, String markingKeyword) throws ParseException { String markingString = text.substring(markingKeyword.length()); if (markingString.trim().equals("")) return null; Marking marking = null; try { marking = MIDParser.parseMarkingString(markingString); } catch (ParseException e) { throw new ParseException( markingKeyword + " " + LocaleBundle.bundleString("annotation") + " " + text + ". " + e.toString()); } return marking; }