GOCK3 is a collection of tools written in Go for tokenizing, parsing, and validating PDXScript files used in Crusader Kings 3. This project aims to assist mod developers by providing utilities that can analyze PDXScript code, catch errors, and improve code quality.
This project was inspired by ck3-tiger. Some concepts and code structures have been adapted with gratitude.
The project consists of three main components:
- Lexer: Tokenizes PDXScript code and catches lexical errors, such as unknown tokens (e.g., invalid operators like
!=
). - Parser: Constructs an Abstract Syntax Tree (AST) from the token stream and catches syntax errors (e.g., unclosed curly braces).
Linter: Analyzes the AST for potential issues such as improper structure, deprecated syntax, or inefficient patterns, and suggests improvements to enhance the quality of PDXScript code.Validator: Validates the AST against predefined rules to ensure code correctness and consistency.
To install GOCK3, ensure you have Go installed (version 1.16 or higher), then run:
go get github.com/unLomTrois/gock3
You can use GOCK3 as a command-line tool or as a library in your Go projects.
To lint a PDXScript file:
gock3 lint your_file.txt
Import GOCK3 into your Go project:
import "github.com/unLomTrois/gock3"
Use the lexer, parser, and validator in your code:
tokens, err := gock3.Lexer(fileContent)
if err != nil {
// Handle lexical errors
}
ast, err := gock3.Parser(tokens)
if err != nil {
// Handle syntax errors
}
validationErrors := gock3.Validator(ast)
if len(validationErrors) > 0 {
// Handle validation errors
}
Contributions are welcome! Please fork the repository and submit a pull request.
- Implement Lexer
- Add tests for Lexer
- Implement Parser
- Add tests for Parser
- Implement Linter
- Add tests for Linter
- Implement Validator
- Add tests for Validator
- Create a VSCode extension
- ck3-tiger - Inspiration for code concepts and structure.
If you are new to parsing and compilers, here are some resources to get you started:
- Video Playlist: Building a Parser from scratch
- Book: Compilers: Principles, Techniques, and Tools (First 2-3 chapters recommended)