Generalize parsing and add handling for byte_string_literal and file_header (#23)

* Add 'warn_on_unhandled_token' to Config

- Add a new bool to control printing a warning if we don't recognize a
  token durng parsing
- Update the call hierarchy to pass a reference to a Config rather than
  the KeyboardLayout alone.

* Handle 'file_version'

* Add byte_string_literal and generalize more parsing

- Adds support for byte_string_literal which is exposed by treesitter as
  just text for the most part
- Consolidate Node & Property since handling of their top-level token is
  the same in the grammar from the perspective of being a parent with
  some child nodes to traverse now that identifier handling was added in
  a previous commit
- Identifiers, string_literals, and unit-address can all now be handled
  generically
- Consolidated Zephyr syntax handling slightly
7 files changed
tree: 7f186b93ad81035e2822ae27de260d206d1d1513
  1. .github/
  2. scripts/
  3. src/
  4. tests/
  5. .gitignore
  6. .gitmodules
  7. build.rs
  8. Cargo.lock
  9. Cargo.toml
  10. LICENSE
  11. README.md
  12. rustfmt.toml
README.md

dtsfmt

Auto formatter for device tree files.

Installation

You can install dtsfmt by running the install script which will download the latest release.

curl -LSfs https://go.mskelton.dev/dtsfmt/install | sh

Or you can build from source.

git clone --recurse-submodules https://github.com/mskelton/dtsfmt.git
cd dtsfmt
cargo install --path .

Usage

To run dtsfmt, simply provide a file/directory path to the dtsfmt command.

dtsfmt .

Config

The following configuration options are available for dtsfmt. Configuration should be added to a .dtsfmtrc.toml file at the root of your project.

layout = "kinesis:adv360" # Required
# Available options are ["kinesis:adv360", "sweep", "moergo:glove80"]

Ignoring code

You can add a .dtsfmtignore file at the root of your project to exclude files and paths from formatting. This file follows the same rules as .gitignore.

Flags

--check

When you want to check if your files are formatted, you can run dtsfmt with the --check flag (or -c). This will output a human-friendly message and a list of unformatted files, if any.

dtsfmt --check .

--emit

You can change the way dtsfmt emits the changes with the --emit flag.

dtsfmt --emit=stdout