Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lexer for the sed scripting language #1935

Merged
merged 3 commits into from
Nov 21, 2021
Merged

Add a lexer for the sed scripting language #1935

merged 3 commits into from
Nov 21, 2021

Conversation

Mango0x45
Copy link
Contributor

@Mango0x45 Mango0x45 commented Oct 31, 2021

Sed is a stream editing scripting language forming part of the POSIX
standard. This means that sed can be found as part of any POSIX compliant
OS such as Linux, MacOS, and the BSDs. This lexer supports the complete
POSIX standard for sed as well as various GNU extensions.

The names 'gsed' and 'ssed' may sometimes be used as part of a file
extension to refer specifically to GNU sed or Super Sed, two popular
implementations of sed.

The sed language is rather simple, here is a quick overview:

  • Comments begin with a '#' and continue to the end of the line.
  • Commands can be prepended with a range that selects lines. This can be
    either a number ([0-9]+), a '$', or a regular expression. Regular
    expressions can either be enclosed in '/' such as /regex/ or they can
    be exclosed in any other character however the opening delimiter must
    be escaped, for example: \@regex@.
  • Some commands such as 'w', 'r', and 'b' take a string as a parameter,
    this string extends either to the next ';' or newline.
  • Some commands such as 'a' can take multiline strings.
  • Commands can be grouped with braces ('{' and '}').
  • The 'y' command takes two strings as parameters, seperated by any
    delimiter ('y/abc/123/' or 'y|abc|123|')
  • The 's' command is like the 'y' command but the fist parameter is a
    regular expression. Additionally it takes an optional 3rd parameter
    which are a sequence of flags ('s|regex|replace|flags').

I chose to add support for GNU sed extensions as it is by far the most
used implementation.

Sed is a stream editing scripting language forming part of the POSIX
standard. This means that sed cn be found as part of any POSIX compliant
OS such as Linux, MacOS, and the BSDs. This lexer supports the complete
POSIX standard for sed as well as various GNU extensions.

The names 'gsed' and 'ssed' may sometimes be used as part of a file
extension to refer specifically to GNU sed or Super Sed, two popular
implementations of sed.

The sed language is rather simple, here is a quick overview:

- Comments begin with a '#' and continue to the end of the line.
- Commands can be prepended with a range that selects lines. This can be
  either a number ([0-9]+), a '$', or a regular expression. Regular
  expressions can either be enclosed in '/' such as /regex/ or they can
  be exclosed in any other character however the opening delimiter must
  be escaped, for example: \@regex@.
- Some commands such as 'w', 'r', and 'b' take a string as a parameter,
  this string extends either to the next ';' or newline.
- Some commands such as 'a' can take multiline strings.
- Commands can be grouped with braces ('{' and '}').
- The 'y' command takes two strings as parameters, seperated by any
  delimiter ('y/abc/123/' or 'y|abc|123|')
- The 's' command is like the 'y' command but the fist parameter is a
  regular expression. Additionally it takes an optional 3rd parameter
  which are a sequence of flags ('s|regex|replace|flags').

I chose to add support for GNU sed extensions as it is by far the most
used implementation.
@Anteru Anteru added this to the 2.11.0 milestone Nov 21, 2021
@Anteru Anteru self-assigned this Nov 21, 2021
@Anteru Anteru merged commit b950ee9 into pygments:master Nov 21, 2021
@Anteru
Copy link
Collaborator

Anteru commented Nov 21, 2021

Merged, thanks a lot for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants