Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (

require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
Expand All @@ -18,5 +19,8 @@ require (
github.com/klauspost/compress v1.11.2 // indirect
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
Expand All @@ -30,5 +32,12 @@ github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnG
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
139 changes: 123 additions & 16 deletions pkg/codingcontext/task_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,127 @@ func (s *SlashCommand) Params() map[string]string {
return params
}

// stripQuotes removes surrounding double quotes from a string if present.
// Single quotes are not supported as the grammar only allows double-quoted strings.
// stripQuotes removes surrounding quotes from a string if present and processes escape sequences.
// Supports both single (') and double (") quotes.
// Processes escape sequences: \n, \t, \r, \\, \", \', \uXXXX (Unicode), \xHH (hex), \OOO (octal)
Comment on lines +73 to +75
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should clarify the behavior for unknown or invalid escape sequences. According to the implementation, unknown escapes like \z preserve the character after the backslash (resulting in 'z'), and incomplete escapes like \u00a are preserved as-is. Consider adding this to the comment to make the behavior explicit for users of this function.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhanced documentation in commit 61bd580 to explicitly describe behavior for unknown escape sequences (preserves character after backslash) and incomplete escape sequences (preserves literally including backslash).

// Unknown escape sequences (e.g., \z) preserve only the character after the backslash.
// Incomplete escape sequences (e.g., \u00a, \x4) are preserved literally including the backslash.
func stripQuotes(s string) string {
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
// Remove quotes and handle escaped quotes inside
unquoted := s[1 : len(s)-1]
return strings.ReplaceAll(unquoted, `\"`, `"`)
// Check if the string is quoted
if len(s) < 2 {
return s
}
return s

quoteChar := byte(0)
if (s[0] == '"' && s[len(s)-1] == '"') || (s[0] == '\'' && s[len(s)-1] == '\'') {
quoteChar = s[0]
s = s[1 : len(s)-1] // Remove surrounding quotes
}

// If not quoted, return as-is (no escape processing for unquoted values in slash commands)
if quoteChar == 0 {
return s
}

// Process escape sequences
return processEscapeSequences(s)
}

// processEscapeSequences decodes escape sequences in a string.
// Supports: \n, \t, \r, \\, \", \', \uXXXX (Unicode), \xHH (hex), \OOO (octal)
Comment on lines +99 to +100
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should clarify the behavior for unknown or invalid escape sequences. According to the implementation at lines 176-178, unknown escapes preserve only the character after the backslash, and incomplete sequences (lines 136-142, 151-157) are preserved literally including the backslash. Adding this information would make the function's contract more explicit.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhanced documentation in commit 61bd580 to explicitly describe behavior for unknown escape sequences (preserves character after backslash) and incomplete escape sequences (preserves literally including backslash).

// Unknown escape sequences (e.g., \z) preserve only the character after the backslash.
// Incomplete escape sequences (e.g., \u00a, \x4) are preserved literally including the backslash.
func processEscapeSequences(s string) string {
if !strings.Contains(s, "\\") {
return s // Fast path: no escapes
}

var result strings.Builder
result.Grow(len(s))

for i := 0; i < len(s); i++ {
if s[i] != '\\' || i == len(s)-1 {
result.WriteByte(s[i])
continue
}

// We have a backslash and there's at least one more character
i++ // Move past backslash
switch s[i] {
case 'n':
result.WriteByte('\n')
case 't':
result.WriteByte('\t')
case 'r':
result.WriteByte('\r')
case '\\':
result.WriteByte('\\')
case '"':
result.WriteByte('"')
case '\'':
result.WriteByte('\'')
case 'u':
// Unicode escape: \uXXXX
if i+5 <= len(s) {
hexStr := s[i+1 : i+5]
if val, err := strconv.ParseInt(hexStr, 16, 32); err == nil {
result.WriteRune(rune(val))
i += 4
} else {
// Invalid Unicode escape, keep as-is
result.WriteString("\\u")
}
} else {
// Incomplete Unicode escape
result.WriteString("\\u")
}
case 'x':
// Hex escape: \xHH
if i+3 <= len(s) {
hexStr := s[i+1 : i+3]
if val, err := strconv.ParseInt(hexStr, 16, 8); err == nil {
result.WriteByte(byte(val))
i += 2
} else {
// Invalid hex escape, keep as-is
result.WriteString("\\x")
}
} else {
// Incomplete hex escape
result.WriteString("\\x")
}
default:
// Check for octal escape: \OOO (up to 3 digits, 0-7)
if s[i] >= '0' && s[i] <= '7' {
octalStart := i
octalEnd := i + 1
// Read up to 2 more octal digits
for octalEnd-octalStart < 3 && octalEnd < len(s) && s[octalEnd] >= '0' && s[octalEnd] <= '7' {
octalEnd++
}
octalStr := s[octalStart:octalEnd]
if val, err := strconv.ParseInt(octalStr, 8, 16); err == nil {
result.WriteByte(byte(val))
i = octalEnd - 1
} else {
// Invalid octal, keep as-is
result.WriteByte('\\')
result.WriteByte(s[i])
}
} else {
// Unknown escape sequence, keep the character after backslash
result.WriteByte(s[i])
}
}
}

return result.String()
}

// Argument represents either a named (key=value) or positional argument
type Argument struct {
Key string `parser:"(@Term Assign)?"`
Value string `parser:"(@String | @Term)"`
Value string `parser:"(@DQString | @SQString | @Term)"`
}

// Text represents a block of text
Expand All @@ -97,8 +203,8 @@ type Text struct {
// TextLine is a single line of text content (not starting with a slash)
// It matches tokens until the end of the line
type TextLine struct {
NonSlashStart []string `parser:"(@Term | @String | @Assign | @Whitespace)"` // First token can't be Slash
RestOfLine []string `parser:"(@Term | @String | @Slash | @Assign | @Whitespace)*"` // Rest can include Slash
NonSlashStart []string `parser:"(@Term | @DQString | @SQString | @Assign | @Whitespace)"` // First token can't be Slash
RestOfLine []string `parser:"(@Term | @DQString | @SQString | @Slash | @Assign | @Whitespace)*"` // Rest can include Slash
NewlineOpt string `parser:"@Newline?"`
}

Expand All @@ -119,12 +225,13 @@ func (t *Text) Content() string {

// Define the lexer using participle's lexer.MustSimple
var taskLexer = lexer.MustSimple([]lexer.SimpleRule{
{Name: "Slash", Pattern: `/`}, // Any "/"
{Name: "Assign", Pattern: `=`}, // "="
{Name: "String", Pattern: `"(?:\\.|[^"])*"`}, // Quoted strings with escapes
{Name: "Whitespace", Pattern: `[ \t]+`}, // Spaces and tabs (horizontal only)
{Name: "Newline", Pattern: `[\n\r]+`}, // Newlines
{Name: "Term", Pattern: `[^ \t\n\r/"=]+`}, // Any char except space, newline, /, ", =
{Name: "Slash", Pattern: `/`}, // Any "/"
{Name: "Assign", Pattern: `=`}, // "="
{Name: "DQString", Pattern: `"(?:\\.|[^"])*"`}, // Double-quoted strings with escapes
{Name: "SQString", Pattern: `'(?:\\.|[^'])*'`}, // Single-quoted strings with escapes
{Name: "Whitespace", Pattern: `[ \t]+`}, // Spaces and tabs (horizontal only)
{Name: "Newline", Pattern: `[\n\r]+`}, // Newlines
{Name: "Term", Pattern: `[^ \t\n\r/"=']+`}, // Any char except space, newline, /, ", ', =
})

var parser = participle.MustBuild[Input](
Expand Down
Loading