{"id":21061062,"url":"https://github.com/glennsarti/sentinel-parser","last_synced_at":"2025-04-30T10:33:07.874Z","repository":{"id":251497371,"uuid":"749301034","full_name":"glennsarti/sentinel-parser","owner":"glennsarti","description":"Go Packages to parse HashiCorp Sentinel file types","archived":false,"fork":false,"pushed_at":"2025-03-10T19:45:13.000Z","size":245,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T20:16:46.323Z","etag":null,"topics":["golang","hashicorp","parser","sentinel"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glennsarti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-28T06:50:53.000Z","updated_at":"2025-01-16T01:53:26.000Z","dependencies_parsed_at":"2024-09-10T08:34:19.457Z","dependency_job_id":"ac4d887b-c10b-425b-8312-31fb16a1971c","html_url":"https://github.com/glennsarti/sentinel-parser","commit_stats":null,"previous_names":["glennsarti/sentinel-parser"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsarti%2Fsentinel-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsarti%2Fsentinel-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsarti%2Fsentinel-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsarti%2Fsentinel-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glennsarti","download_url":"https://codeload.github.com/glennsarti/sentinel-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243505952,"owners_count":20301617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","hashicorp","parser","sentinel"],"created_at":"2024-11-19T17:21:02.566Z","updated_at":"2025-03-14T00:44:45.730Z","avatar_url":"https://github.com/glennsarti.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub Tag](https://img.shields.io/github/v/tag/glennsarti/sentinel-parser) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/glennsarti/sentinel-parser/test.yml)\n\n\n\u003e [!IMPORTANT]\n\u003e This repository is **not** supported or endorsed by the authors of Sentinel (HashiCorp). Do not contact them if you find any issues with this parser!\n\n---\n\n# Sentinel Parser\n\nThe repository holds a parser for [HashiCorp Sentinel Configuration](https://developer.hashicorp.com/sentinel/docs/configuration) files, and a lexer and parser for [HashiCorp Sentinel Language](https://developer.hashicorp.com/sentinel/docs/language) files. The parsers support different versions of the language specifications.\n\n\u003e [!WARNING]\n\u003e This project is still a work in progress\n\n# Intended usage of these Go modules\n\nThese Go modules are intended to be used by other tools to inspect Sentinel files e.g. development tools like;\n\n* Static analysis tools (Linters etc.)\n\n* Automation tools (Documentation generators)\n\n* Text editor integrations ([Language Servers](https://microsoft.github.io/language-server-protocol/))\n\n## What it shouldn't be used for\n\nThese Go modules are **NOT** intended to replace the [HashiCorp Sentinel CLI tool](https://developer.hashicorp.com/sentinel/docs/commands), for example; While not open-sourced, the parser in that tool would _probably_ be optimised to execute sentinel language which means it will terminate quickly on a parsing error. Whereas this parser is optimised to generate as much of an AST as possible, and be very forgiving of parsing errors.\n\n# Example Usage\n\n## Sentinel Configuration\n\n```go\n  import \"github.com/glennsarti/sentinel-parser/sentinel_config/parser\"\n\n  func main() {\n    // Create a new Sentinel Config parser using `sentinelVersion` language rules\n    //\n    // sentinelVersion can be 'latest' which will use the latest specification\n    // the package knows, or a specific version like 'v0.25.0'. The complete list of\n    // versions is found at `github.com/glennsarti/sentinel-parser/sentinel_config/features`\n    p, err := parser.NewParser(sentinelVersion)\n    if err != nil {\n      return nil, err\n    }\n\n    content := []byte(`\n      param \"number1\" {\n        value = 42\n      }\n    `)\n\n    // Parse a single file. Returns as much AST as possible and any parsing errors\n    ast, diags := p.ParseFileSource(content, \"sentinel.hcl\")\n  }\n\n```\n\n## Sentinel\n\nSimple example\n\n```go\n  import \"github.com/glennsarti/sentinel-parser/sentinel/parser\"\n\n  func main() {\n    content := []byte(`\n      main = rule { true }\n    `)\n\n    // Parse a single file. Returns as much AST as possible, any parsing errors and any terminal errors\n    //\n    // sentinelVersion can be 'latest' which will use the latest specification\n    // the package knows, or a specific version like 'v0.25.0'. The complete list of\n    // versions is found at `github.com/glennsarti/sentinel-parser/sentinel_config/features`\n    ast, _, diags, err := parser.ParseFile(sentinelVersion, \"example.sentinel\", content)\n  }\n```\n\nAdvanced example\n\n```go\n  import (\n    \"github.com/glennsarti/sentinel-parser/sentinel/lexer\"\n    \"github.com/glennsarti/sentinel-parser/sentinel/parser\"\n  )\n\n  func main() {\n    content := []byte(`\n      main = rule { true }\n    `)\n\n    // Create a new lexer using the specific sentinelVersion specification\n    lex, err := lexer.New(sentinelVersion, content)\n    if err != nil {\n      panic(err)\n    }\n\n    // Create a new parser using the specific sentinelVersion\n    p, err := parser.New(sentinelVersion)\n    if err != nil {\n      panic(err)\n    }\n\n    // Parse the tokens from the lexer. The `nil` is to disable debug tracing.\n    // Returns as much AST as possible, any parsing errors and any terminal errors\n    ast, diags, err := p.ParseFile(lex, lex.Locator(), nil)\n  }\n```\n\n# Language Specifications\n\nThese parsers were built according to the [language specifications](https://developer.hashicorp.com/sentinel/docs/language) as published by HashiCorp.\n\n## Additional content used\n\nThe language specifications do not contain an exhaustive list of examples. To supplement these examples, the following locations were used to inspect what \"good\" or \"bad\" examples could look like;\n\n* The publicly published Sentinel policy packs in the [Terraform Registry](https://registry.terraform.io/browse/policies).\n\n# Thanks\n\nA huge thankyou to Thorsten Ball for publishing his book \"Writing an Interpreter in Go\" ([https://interpreterbook.com](https://interpreterbook.com)). This was instrumental in creating the lexer and parser in this project.\n\n# TODO\n\nThere are still many thing to complete\n\n* [ ] Generate Golang documentation\n\n* [ ] Dealing with Unicode multibyte files. Code mostly assumes single-byte characters and positions\n\n* [ ] Does it need more Sentinel language grammar checks\n\n* [ ] Describe more about the generation scripts\n\n* [x] Actually do a 0.0.1 release\n\n* [ ] What does a v1.0 release look like?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsarti%2Fsentinel-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglennsarti%2Fsentinel-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsarti%2Fsentinel-parser/lists"}