Comby

Comby

  • Get started
  • Docs
  • Projects & Talks
  • GitHub
  • Blog

›Usage

Getting Started

  • Overview
  • Get Started

Usage

  • Basic Usage
  • Rewrite Properties
  • Syntax Reference
  • Advanced Usage
  • Configuration Files
  • Cheat Sheet

API

  • API Reference

Resources

  • Get Help
  • FAQ
Edit

Syntax Reference

The Comby syntax below has special meaning for matching. Bind match contents to identifiers like hole using Named Match syntax. Using names is useful when replacing contents or writing rules. To just match patterns without giving a meaningful name, use any of the Just Match syntax.

Match and Rewrite Syntax

Named MatchJust MatchDescription
:[var]...

:[_]
match zero or more characters in a lazy fashion. When used is inside delimiters, as in {:[v1], :[v2]} or (:[v]), holes match within that group or code block, including newlines. Holes outside of delimiters stop matching at a newline, or the start of a code block, whichever comes first.
:[var~regex]:[~regex]match an arbitrary PCRE regular expression regex. Avoid regular expressions that match special syntax like ) or .*, otherwise your pattern may fail to match balanced blocks.
:[[var]]:[~\w+]
:[[_]]
match one or more alphanumeric characters and _.
:[var:e]:[_:e]Expression-like syntax matches contiguous non-whitespace characters like foo or foo.bar, as well as contiguous character sequences that include valid code block structures like balanced parentheses in function(foo, bar) (notice how whitespace is allowed inside the parentheses). Language-dependent.
:[var.]:[_.]match one or more alphanumeric characters and punctuation like ., ;, and - that do not affect balanced syntax. Language dependent.
:[var\n]:[~.*\n]
:[_\n]
match zero or more characters up to a newline, including the newline.
:[ var]:[var~[ \t]+]
:[ ]
match only whitespace characters, excluding newlines.

Rewrite Properties

String converters

PropertyBehavior
.lowercaseConvert letters to lowercase
.UPPERCASEConvert letters to uppercase
.CapitalizeCapitalize the first character if it is a letter
.uncapitalizeLowercase the first character if it is a letter
.UPPER_SNAKE_CASEConvert camelCase to snake_case (each capital letter in camelCase gets a _ prepended). Then uppercase letters.
.lower_snake_caseConvert camelCase to snake_case (each capital letter in camelCase gets a _ prepended). Then lowercase letters.
.UpperCamelCaseConvert snake_case to CamelCase (each letter after _ in snake_case is capitalized, and the _ removed). Then capitalize the first character.
.lowerCamelCaseConvert snake_case to CamelCase (each letter after _ in snake_case is capitalized, and the _ removed). Then lowercase the first character.

Sizes

PropertyBehavior
.lengthSubstitute the number of characters of the hole value
.linesSubstitute the number of lines of the hole value

Positions

PropertyBehavior
.lineSubstitute the starting line number of this hole
.line.startAlias of .line
.line.endSubstitute the ending line number of this hole
.columnSubstitute the starting column number of this hole (also known as character)
.column.startAlias of .column
.column.endSubstitute the ending column number of this hole
.offsetSubstitute the starting byte offset of this hole in the file
.offset.startAlias of .offset
.offset.endSubstitute the ending byte offset of this hole in the file

File context

PropertyBehavior
.fileSubstitute the absolute file path of the file where this hole matched
.file.pathAlias of .file
.file.nameSubstitute the file name of the file where this hole matched (basename)
.file.directorySubstitute the file directory of the file where hole matched (dirname)

Identity

PropertyBehavior
.valueSubstitute the text value of this hole
← Rewrite PropertiesAdvanced Usage →
  • Match and Rewrite Syntax
  • Rewrite Properties
    • String converters
    • Sizes
    • Positions
    • File context
    • Identity

© 2022 @rvtond · Get started · Docs · Projects & Talks · Blog · Twitter