RSL SEMANTIC VALIDATION RULES

This document lists semantic validation rules enforced OUTSIDE the grammar. Use this as a knowledge base to validate generated RSL code.

Purpose: Ensure generated code passes all semantic checks that cannot be validated by grammar alone.

Severity:
- Error = Code is invalid, must fix
- Warning = Code should be improved, aim for zero warnings
- Info = Optional suggestion

ERRORS (must fix)

Reserved Words
Rule: Cannot use reserved words as element identifiers (name/ID).
Reserved words:
- Core keywords: Package, Import, System, TestSuite, IncludeAll, Include, View, Theme, StateMachine, state
- System concepts: Stakeholder, Actor, DataEntity, DataEntityCluster, DataEnumeration, Data, Goal, FR, QR, Constraint, UserStory, UseCase, Risk, Vulnerability, GlossaryTerm, Term
- Behavior: Task, Event, TaskFlow, Scenario, mainScenario, acceptanceCriteria, Setup, Teardown
- Relations: SystemsRelation, RequirementsRelation, TestsRelation, ElementsRelation
- Types: Integer, Double, Decimal, Boolean, Bit, Currency, Date, Time, Datetime, String, Text, Regex, URL, Email, File, Image, XML, Binary, FilePath
- Literals: True, False, Other
- Actions: aCreate, aRead, aUpdate, aDelete
Solution: Use lower case (e.g., gender instead of Gender, email instead of Email).

Unique IDs
Rule: Every SystemConcept ID must be unique within its System.
Example violation:
Goal g_Performance "Performance goal" : Performance
Goal g_Performance "Another performance goal" : Performance  // ERROR: duplicate ID
Solution: Use unique IDs or add suffix: g_Performance_2

Type/Subtype Consistency
Rule: When both type and subtype are specified, the subtype must be a valid subtype of the type.
Applies to: System, Constraint, Goal, QR, Risk, Stakeholder, Vulnerability
Example violation:
QR qr1 "Response time" : Performance : Security_Authentication  // ERROR: Security_Authentication is not a Performance subtype
Valid subtypes by type:
- Performance: Performance_SystemResponseTime, Performance_NetworkResponseTime, Performance_MemoryCapacity, Performance_DiskCapacity, Performance_Other
- Security: Security_Authentication, Security_Authorization, Security_Confidentiality, Security_Integrity, etc.
(see grammar for complete list)

Multiple DataEntity References in One Element
Rule: 
Example violation:
UseCase uc_ProcessOrder "Process Order" : EntitiesManage [When an element needs to refer to multiple DataEntities, you must create one DataEntityCluster and reference that cluster instead. Directly referencing multiple DataEntities inside the same element is not allowed.
    primaryActor a_Customer
    dataEntity e_Customer
    dataEntity e_Order  // ERROR: multiple DataEntities referenced directly in one element
]
Solution:
DataEntityCluster dec_ReportingData "Reporting Data Cluster" : Master [
    main e_Order
    child e_Customer
]
UseCase uc_ProcessOrder "Process Order" : EntitiesManage [
    primaryActor a_Customer
    dataEntity ec_ReportingData
]

ActiveFlow Condition
Rule: condition property is only allowed when type is SequenceConditional.
Example violation:
TaskFlow tf1 "My flow" : Parallel [
    condition "some condition"  // ERROR: Parallel cannot have condition
    ...
]

ActiveTask Participant
Rule: participantTarget property is only allowed when type is Send or Receive.
Example violation:
Task t1 "Manual task" : Manual [
    participantExternal stk_External  // ERROR: Manual cannot have participantExternal
]

UseCase Self-Extension
Rule: A UseCase cannot extend itself.
Example violation:
UseCase uc1 "Login" : Login [
    extends uc1 onExtensionPoint ep1  // ERROR: cannot extend itself
]

Relation Source/Target
Rule: In SystemsRelation and RequirementsRelation, source and target cannot be the same.
Example violation:
SystemsRelation sr1 "Self relation" : Requires [
    source sys1
    target sys1  // ERROR: same as source
]

Hierarchy Cycles
Rule: No cycles allowed in hierarchical relationships.
Applies to:
- isA: Actor, Stakeholder, DataEntity, GlossaryTerm, Vulnerability
- partOf: ActiveTask, Goal, FR, QR, Constraint, Risk, Stakeholder, UserStory, GlossaryTerm, Vulnerability
- nextStep: Step
Example violation:
Actor a1 "Actor1" : User [isA a2]
Actor a2 "Actor2" : User [isA a1]  // ERROR: cycle in isA hierarchy

LinguisticLanguage Uniqueness
Rule: Only one LinguisticLanguage is allowed per System.
Example violation:
System s1 "MySystem" : Application
    LinguisticLanguage lang1 "English" : English
    LinguisticLanguage lang2 "Spanish" : Spanish  // ERROR: only one allowed

WARNINGS (should fix - aim for zero)

StateMachine Completeness
Rule: Every StateMachine should have at least one initial state (isInitial) and one final state (isFinal).
Example warning:
StateMachine sm1 "Order SM" : Simple [
    dataEntity e_Order
    state s1 "Pending" isInitial  // has initial
    state s2 "Active"
    // WARNING: missing final state
]
Solution: Add at least one state with isFinal:
state s3 "Completed" isFinal

Glossary Synonym Usage
Rule: When a GlossaryTerm defines synonyms, using those synonyms in element names/descriptions triggers a warning to use the canonical term instead.
Example:
Term t_Customer "Customer" : Noun [
    synonyms "Client", "Buyer"
]
// Later:
Goal g1 "Improve client satisfaction" : Usability  // WARNING: replace "client" with "Customer"

LINGUISTIC RULES (when LinguisticRules are defined)

If LinguisticRules are defined in the System, the following elements are validated against those patterns:
BehaviorElement, DataAttribute, LinguisticFragment, LinguisticRule, MainScenario, OtherElement, Requirement, Scenario, Step, StructureElement, SystemRelation, SystemSet, Test

Validation scope: id, nameAlias, description properties
Languages supported: English, Spanish, German, French, Italian, Portuguese, Japanese
Severity: Can be configured as Error or Warning per rule

NOTES

- All references must resolve: Unresolved references (e.g., [Actor:NonExistent]) produce linking errors.
- Grammar syntax: This document covers ONLY semantic rules. For syntax rules, refer to the Langium grammar file.