# Wasot Selector Examples

This directory contains examples demonstrating the CSS-like selector system for Wasot documents.

## Files

- `selector-showcase.wasot` - Comprehensive example file showcasing all selector capabilities
- `selector-showcase-demo.sh` - Shell script demonstrating various selector queries

## Running Selectors

Use the `wasot select` command to query Wasot documents:

```bash
wasot select <file> -s <selector> [-s <selector2> ...]
```

## Supported Selectors

### Basic Selectors

#### Type Selector
Matches elements by their type name:
```bash
wasot select file.wasot -s "paragraph"
wasot select file.wasot -s "section"
```

#### Universal Selector
Matches all elements:
```bash
wasot select file.wasot -s "*"
```

#### ID Selector
Matches elements with a specific ID (IDs are prefixed with `:` in Wasot):
```bash
wasot select file.wasot -s "#intro"
wasot select file.wasot -s "#main-doc"
```

#### Class Selector
Matches elements with a specific class (classes are positional arguments starting with `.`):
```bash
wasot select file.wasot -s ".highlight"
wasot select file.wasot -s ".important"
```

### Attribute Selectors

#### Attribute Presence
Matches elements that have a specific attribute (positional or keyword):
```bash
wasot select file.wasot -s "[lang]"
wasot select file.wasot -s "[priority]"
```

#### Attribute Negation
Matches elements that don't have a specific attribute:
```bash
wasot select file.wasot -s "[!disabled]"
```

#### Attribute Value Match
Matches elements where an attribute has a specific value:
```bash
wasot select file.wasot -s "[lang=en]"
wasot select file.wasot -s "[priority=high]"
```

#### Attribute Value Negation
Matches elements where an attribute exists but doesn't have a specific value:
```bash
wasot select file.wasot -s "[lang~=fr]"
```

#### Attribute Value Prefix
Matches elements where an attribute value starts with a prefix:
```bash
wasot select file.wasot -s "[href^=https]"
```

#### Attribute Value Suffix
Matches elements where an attribute value ends with a suffix:
```bash
wasot select file.wasot -s "[href$=.pdf]"
```

#### Attribute Value Contains
Matches elements where an attribute value contains a substring:
```bash
wasot select file.wasot -s "[title*=important]"
```

### Combinators

#### Descendant Combinator (space)
Matches elements that are descendants of another element:
```bash
wasot select file.wasot -s "section paragraph"
wasot select file.wasot -s "document section"
```

#### Child Combinator (>)
Matches elements that are direct children of another element:
```bash
wasot select file.wasot -s "section > paragraph"
wasot select file.wasot -s "container > card"
```

#### Adjacent Sibling (+) - Not yet implemented
Would match elements immediately following another element.

#### General Sibling (~) - Not yet implemented
Would match elements that are siblings following another element.

### Multiple Selectors

You can specify multiple selectors (OR logic) using multiple `-s` flags:
```bash
wasot select file.wasot -s "quote" -s "blockquote"
wasot select file.wasot -s "#intro" -s "#summary"
```

## Examples Using selector-showcase.wasot

```bash
# Find all paragraphs
wasot select examples/selector-showcase.wasot -s "paragraph"

# Find elements with ID 'intro'
wasot select examples/selector-showcase.wasot -s "#intro"

# Find elements with class 'highlight'
wasot select examples/selector-showcase.wasot -s ".highlight"

# Find sections with lang=en
wasot select examples/selector-showcase.wasot -s "[lang=en]"

# Find paragraphs inside sections
wasot select examples/selector-showcase.wasot -s "section paragraph"

# Find direct subsection children of sections
wasot select examples/selector-showcase.wasot -s "section > subsection"

# Find multiple: quotes OR blockquotes
wasot select examples/selector-showcase.wasot -s "quote" -s "blockquote"
```

## Running the Demo Script

```bash
cd /path/to/wasot
./examples/selector-showcase-demo.sh
```

## Current Limitations

- Pseudo-class selectors (`:first-child`, `:nth-child()`, etc.) are parsed but not yet implemented in matching
- Sibling combinators (`+`, `~`) are not yet implemented
- Complex combined selectors (e.g., `section[lang=en].highlight`) may not work as expected
- The `:not()` pseudo-class is parsed but not yet implemented

## Wasot Syntax Notes

When creating Wasot files for use with selectors:

1. **IDs**: Use `:id` syntax after the type name (e.g., `.paragraph :my-id`)
2. **Classes**: Use positional arguments starting with `.` (e.g., `.paragraph .. .highlight .featured`)
3. **Attributes**: Use the `..` separator before arguments (e.g., `.section .. lang=en priority=high`)
4. **Inline text**: Comes before the `..` separator (e.g., `.section Title text .. lang=en`)

Example:
```wasot
.section Introduction .. :intro lang=en .highlight priority=high
```
This creates a section with:
- Type: `section`
- Inline text: `Introduction`
- ID: `intro`
- Class: `highlight`
- Attributes: `lang=en`, `priority=high`