Task 632: .S7I File Format
Task 632: .S7I File Format
The .S7I file format is used for library and include files in the Seed7 programming language. It is a plain text format containing Seed7 source code for declarations (types, constants, functions, operators, etc.). The format follows the Seed7 Structured Syntax Description (S7SSD), which defines the language's syntax for expressions, operators, and statements. There is no binary structure or header; it's UTF-8 encoded text with Pascal-like syntax. The full specification is detailed in the Seed7 manual.
List of all the properties of this file format intrinsic to its file system:
- Basic structure of a syntax definition:
$ syntax expr: [dot expression] is [associativity] [priority];(uses$for hard-coded statements,:separator,isfor associativity/priority, placeholders like()for expressions). - Associativity options:
->(left),<-(right),<->(neither),-><-(mixed). - Priority: Natural numbers (0 strongest binding; e.g., arithmetic 1-11, comparisons 12, boolean 13-14, assignments 20, statements 25, semicolon 50).
- Operator types: Prefix (e.g.,
.not.()), infix (e.g.,.().and.()), postfix; can have multiple symbols with middle operands of any priority. - Limitations: No optional/repeating notations; complex structures use multiple rules.
- Hard-coded elements: Comments, tokens (identifiers, literals), parentheses expressions, call/dot expressions (not in S7SSD).
- Predefined operators: Unary plus (
+,<- 5), unary minus (-,<- 5), multiplication (*,-> 6), division (/,-> 6), addition (+,-> 7), subtraction (-,-> 7), logical not (not,<- 13), logical and (and,-> 14),div/rem/mdiv/mod(priority 6), assignments (:= / +:= / *:=, priority 20). - Predefined statements (priority 25,
->unless noted): Loop (.loop.().until.().do.().end.loop), while (.while.().do.().end.while), repeat (.repeat.().until.()), if-then-end (.if.().then.().end.if), if-then-else-end (.if.().then.().else.().end.if), if-elsif-else (multiple rules withelsif/elseas<- 60). - Declaration-call consistency: Syntax governs both headers and usage.
- Error handling: Semantic checks for types/context.
- Modular declarations: Extensible with semantic pairings (e.g.,
const funcorconst procwith call-by-name parameters likein proc:,in func boolean:). - Integration: Extends hard-coded elements without redefinition.
Two direct download links for files of format .S7I:
- https://fossies.org/linux/seed7/lib/aes.s7i (AES encryption library file in Seed7)
- https://fossies.org/linux/seed7/lib/cards.s7i (Playing cards library file in Seed7)
Ghost blog embedded HTML JavaScript for drag and drop .S7I file to dump properties to screen:
This can be embedded in a Ghost blog post as raw HTML. It allows dragging a .S7I file, reads it as text, and dumps the content to the screen as the "properties" (since the format is text-based source code).
- Python class for .S7I file handling:
class S7IFile:
def __init__(self, filename):
self.filename = filename
self.content = None
def open_and_decode(self):
"""Open and read/decode the file as text (since .S7I is plain text)."""
with open(self.filename, 'r', encoding='utf-8') as f:
self.content = f.read()
def print_properties(self):
"""Print all properties (full content, as the format is text-based)."""
if self.content is None:
self.open_and_decode()
print("Properties of .S7I file (full decoded content):\n")
print(self.content)
def write(self, new_content):
"""Write new content to the file."""
with open(self.filename, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"Written to {self.filename}")
# Example usage:
# s7i = S7IFile('example.s7i')
# s7i.print_properties()
# s7i.write('$ include "seed7_05.s7i";\nconst proc: main is func\nbegin\nwriteln("hello");\nend func;')
- Java class for .S7I file handling:
import java.io.*;
import java.util.Scanner;
public class S7IFile {
private String filename;
private String content;
public S7IFile(String filename) {
this.filename = filename;
this.content = null;
}
public void openAndDecode() throws IOException {
// Open and read/decode as text (since .S7I is plain text)
StringBuilder sb = new StringBuilder();
try (Scanner scanner = new Scanner(new File(filename), "UTF-8")) {
while (scanner.hasNextLine()) {
sb.append(scanner.nextLine()).append("\n");
}
}
content = sb.toString();
}
public void printProperties() throws IOException {
if (content == null) {
openAndDecode();
}
System.out.println("Properties of .S7I file (full decoded content):\n");
System.out.println(content);
}
public void write(String newContent) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
writer.write(newContent);
}
System.out.println("Written to " + filename);
}
// Example usage:
// public static void main(String[] args) throws IOException {
// S7IFile s7i = new S7IFile("example.s7i");
// s7i.printProperties();
// s7i.write("$ include \"seed7_05.s7i\";\nconst proc: main is func\nbegin\nwriteln(\"hello\");\nend func;");
// }
}
- JavaScript class for .S7I file handling (Node.js, requires 'fs' module):
const fs = require('fs');
class S7IFile {
constructor(filename) {
this.filename = filename;
this.content = null;
}
openAndDecode() {
// Open and read/decode as text (since .S7I is plain text)
this.content = fs.readFileSync(this.filename, 'utf-8');
}
printProperties() {
if (this.content === null) {
this.openAndDecode();
}
console.log('Properties of .S7I file (full decoded content):\n');
console.log(this.content);
}
write(newContent) {
fs.writeFileSync(this.filename, newContent, 'utf-8');
console.log(`Written to ${this.filename}`);
}
}
// Example usage:
// const s7i = new S7IFile('example.s7i');
// s7i.printProperties();
// s7i.write('$ include "seed7_05.s7i";\nconst proc: main is func\nbegin\nwriteln("hello");\nend func;');
- C class for .S7I file handling (using C++ for class support):
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
class S7IFile {
private:
std::string filename;
std::string content;
public:
S7IFile(const std::string& fn) : filename(fn), content("") {}
void openAndDecode() {
// Open and read/decode as text (since .S7I is plain text)
std::ifstream file(filename);
if (file.is_open()) {
std::stringstream buffer;
buffer << file.rdbuf();
content = buffer.str();
file.close();
} else {
std::cerr << "Error opening file: " << filename << std::endl;
}
}
void printProperties() {
if (content.empty()) {
openAndDecode();
}
std::cout << "Properties of .S7I file (full decoded content):\n" << std::endl;
std::cout << content << std::endl;
}
void write(const std::string& newContent) {
std::ofstream file(filename);
if (file.is_open()) {
file << newContent;
file.close();
std::cout << "Written to " << filename << std::endl;
} else {
std::cerr << "Error writing to file: " << filename << std::endl;
}
}
};
// Example usage:
// int main() {
// S7IFile s7i("example.s7i");
// s7i.printProperties();
// s7i.write("$ include \"seed7_05.s7i\";\nconst proc: main is func\nbegin\nwriteln(\"hello\");\nend func;");
// return 0;
// }