Basic Syntax
Learn the fundamental syntax of the ForSure language.
File Structure
ForSure files use a hierarchical structure to represent directories and files. The basic syntax follows these rules:
- Each ForSure file starts with a root declaration
- Indentation is used to indicate nesting levels
- Directories and files are prefixed with a hyphen (-)
- Attributes are specified in curly braces {}
root:
- directory_name:
- file_name.ext { attribute: "value" }
Root Declaration
Every ForSure file must start with a root declaration, which represents the top-level directory:
root:
# Contents go here
The root declaration can also include attributes:
root { name: "my-project", version: "1.0.0" }:
# Contents go here
Directories and Files
Directories and files are defined using a hyphen (-) followed by the name:
root:
- src: # This is a directory
- index.js # This is a file
- components: # This is a nested directory
- header.js # This is a file inside a nested directory
The presence of a colon (:) after the name indicates that it's a directory. Without a colon, it's treated as a file.
Comments
ForSure supports comments using the hash symbol (#):
root:
# This is a comment
- src:
# This is another comment
- index.js # Inline comment
Comments are useful for documenting the purpose of files and directories or providing additional context.
Learn more about comments →Attributes
Attributes provide additional information about files and directories. They are specified in curly braces {}:
root:
- src:
- index.js { entry: true, permissions: "644" }
- config.json { env: "production" }
Attributes can be strings, booleans, numbers, or even nested objects.
Learn more about attributes →Import Directives
ForSure allows you to import other ForSure files using the @import directive:
root:
- src:
@import 'common-files.fs'
- index.js
This is useful for reusing common file structures across projects.
Learn more about import directives →Complete Example
Here's a complete example that demonstrates the basic syntax:
root { name: "my-project", version: "1.0.0" }:
# Source code directory
- src:
@import 'common-components.fs'
- index.js { entry: true, permissions: "644" }
- utils:
# Utility functions
- helpers.js
- date.js { timezone: "UTC" }
# Assets directory
- assets:
- images:
- logo.png
- banner.jpg
- styles:
- main.css { minify: true }
# Configuration files
- config.json { env: "production" }
- .gitignore
# Documentation
- README.md
Next Steps
Now that you understand the basic syntax, you can: