### Listing Python Project Dependencies
Source: https://github.com/james-lg/skyscraper/blob/master/tests/lxml_tests/requirements.txt
This snippet lists the Python packages and their exact version requirements needed for the project. It is typically used with tools like pip (`pip install -r requirements.txt`) to ensure a consistent development and deployment environment.
```Python
jsons==1.6.3
lxml==4.6.3
mercurial==5.6.1
Pygments==2.7.1
PyYAML==5.3.1
six==1.16.0
typish==1.9.3
```
--------------------------------
### Traversing HTML Document Tree in Rust
Source: https://github.com/james-lg/skyscraper/blob/master/README.md
This example illustrates how to navigate the structure of a parsed HTML document by accessing child nodes from a parent and finding the parent node of a child. It uses methods like `children()` and `parent()` on `DocumentNode` instances.
```Rust
// Parse the HTML text into a document
let text = r#""#;
let document = html::parse(text)?;
// Get the children of the root node
let parent_node: DocumentNode = document.root_node;
let children: Vec = parent_node.children(&document).collect();
assert_eq!(2, children.len());
// Get the parent of both child nodes
let parent_of_child0: DocumentNode = children[0].parent(&document).expect("parent of child 0 missing");
let parent_of_child1: DocumentNode = children[1].parent(&document).expect("parent of child 1 missing");
assert_eq!(parent_node, parent_of_child0);
assert_eq!(parent_node, parent_of_child1);
```
--------------------------------
### Executing Python Script with Piped Input (Shell)
Source: https://github.com/james-lg/skyscraper/blob/master/tests/lxml_tests/README.md
Demonstrates how to run the Python `xpath.py` script from the command line. It uses `cat` to pipe the content of an HTML file as standard input to the Python script, and passes an XPath expression (e.g., "//div") as a command-line argument to the script.
```sh
cat tests/samples/James-LG_Skyscraper.html | python3 tests/lxml_tests/xpath.py "//div"
```
--------------------------------
### Defining XQuery AST Class Diagram using Mermaid
Source: https://github.com/james-lg/skyscraper/blob/master/src/xpath/grammar/xpath_diagram.md
This snippet provides the Mermaid syntax to generate a class diagram visualizing the structure of an XQuery Abstract Syntax Tree (AST). It defines classes like Expr, PathExpr, SequenceType, and their relationships (composition, aggregation, enumeration) as parsed or represented internally. Requires a Mermaid renderer to be displayed.
```mermaid
classDiagram
XPath *-- Expr
ParamList *-- "1..*" Param
Param *-- EQName
Param *-- "0..1" TypeDeclaration
FunctionBody *-- EnclosedExpr
EnclosedExpr *-- "0..1" Expr
ExprSingle *-- "enum" ForExpr
ExprSingle *-- "enum" LetExpr
ExprSingle *-- "enum" QuantifiedExpr
ExprSingle *-- "enum" IfExpr
ExprSingle *-- "enum" OrExpr
ForExpr *-- SimpleForClause
ForExpr *-- ExprSingle
SimpleForClause *-- "1..*" SimpleForBinding
SimpleForBinding *-- VarName
SimpleForBinding *-- ExprSingle
LetExpr *-- SimpleLetClause
LetExpr *-- ExprSingle
SimpleLetClause *-- "1..*" SimpleLetBinding
SimpleLetBinding *-- VarName
SimpleLetBinding *-- ExprSingle
QuantifiedExpr *-- "1..*" VarName
QuantifiedExpr *-- "2..*" ExprSingle
IfExpr *-- Expr
IfExpr *-- "2" ExprSingle
OrExpr *-- "1..*" AndExpr
AndExpr *-- "1..*" ComparisonExpr
ComparisonExpr *-- StringConcatExpr
ComparisonExpr *-- "0..1" Comparison
Comparison *-- ComparisonType
ComparisonType *-- "enum" ValueComp
ComparisonType *-- "enum" GeneralComp
ComparisonType *-- "enum" NodeComp
Comparison *-- StringConcatExpr
StringConcatExpr *-- "1..*" RangeExpr
RangeExpr *-- "1..2" AdditiveExpr
AdditiveExpr *-- "1..*" MultiplicativeExpr
MultiplicativeExpr *-- "1..*" UnionExpr
UnionExpr *-- "1..*" IntersectExceptExpr
IntersectExceptExpr *-- "1..*" InstanceofExpr
InstanceofExpr *-- TreatExpr
InstanceofExpr *-- "0..1" SequenceType
TreatExpr *-- CastableExpr
TreatExpr *-- "0..1" SequenceType
CastableExpr *-- CastExpr
CastableExpr *-- "0..1" SingleType
CastExpr *-- ArrowExpr
CastExpr *-- "0..1" SingleType
ArrowExpr *-- UnaryExpr
ArrowExpr *-- "0..*" ArrowFunctionSpecifier
ArrowExpr *-- "0..*" ArgumentList
UnaryExpr *-- ValueExpr
ValueExpr *-- SimpleMapExpr
SimpleMapExpr *-- "1..*" PathExpr
PathExpr *-- RelativePathExpr
RelativePathExpr *-- "1..*" StepExpr
StepExpr *-- "enum" PostfixExpr
StepExpr *-- "enum" AxisStep
AxisStep *-- AxisStepType
AxisStepType *-- "enum" ReverseStep
AxisStepType *-- "enum" ForwardStep
AxisStep *-- PredicateList
ForwardStep *-- ForwardStepType
ForwardStepType *-- "enum" FullForwardStep
ForwardStepType *-- "enum" AbbrevForwardStep
AbbrevForwardStep *-- NodeTest
FullForwardStep *-- ForwardAxis
FullForwardStep *-- NodeTest
ReverseStep *-- ReverseStepType
ReverseStepType *-- "enum" FullReverseStep
ReverseStepType *-- "enum" AbbrevReverseStep
FullReverseStep *-- ReverseAxis
FullReverseStep *-- NodeTest
NodeTest *-- "enum" EQName
NodeTest *-- "enum" Wildcard
PostfixExpr *-- PrimaryExpr
PostfixExpr *-- "0..*" PostfixExprItem
PostfixExprItem *-- "enum" Predicate
PostfixExprItem *-- "enum" ArgumentList
PostfixExprItem *-- "enum" Lookup
ArgumentList *-- "1..*" Argument
PredicateList *-- "0..*" Predicate
Predicate *-- Expr
Lookup *-- KeySpecifier
KeySpecifier *-- "enum" NCName
KeySpecifier *-- "enum" IntegerLiteral
KeySpecifier *-- "enum" ParenthesizedExpr
ArrowFunctionSpecifier *-- "enum" EQName
ArrowFunctionSpecifier *-- "enum" VarRef
ArrowFunctionSpecifier *-- "enum" ParenthesizedExpr
PrimaryExpr *-- "enum" Literal
PrimaryExpr *-- "enum" VarRef
PrimaryExpr *-- "enum" ParenthesizedExpr
PrimaryExpr *-- "enum" ContextItemExpr
PrimaryExpr *-- "enum" FunctionCall
PrimaryExpr *-- "enum" FunctionItemExpr
PrimaryExpr *-- "enum" MapConstructor
PrimaryExpr *-- "enum" ArrayConstructor
PrimaryExpr *-- "enum" UnaryLookup
Literal *-- "enum" NumericLiteral
Literal *-- "enum" StringLiteral
NumericLiteral *-- "enum" IntegerLiteral
NumericLiteral *-- "enum" DecimalLiteral
NumericLiteral *-- "enum" DoubleLiteral
VarRef *-- VarName
VarName *-- EQName
ParenthesizedExpr *-- Expr
FunctionCall *-- EQName
FunctionCall *-- ArgumentList
Argument *-- ExprSingle
Argument *-- ArgumentPlaceholder
FunctionItemExpr *-- "enum" NamedFunctionRef
FunctionItemExpr *-- "enum" InlineFunctionExpr
NamedFunctionRef *-- EQName
NamedFunctionRef *-- IntegerLiteral
InlineFunctionExpr *-- "0..1" ParamList
InlineFunctionExpr *-- "0..1" SequenceType
InlineFunctionExpr *-- FunctionBody
MapConstructor *-- "1..*" MapConstructorEntry
MapConstructorEntry *-- MapKeyExpr
MapConstructorEntry *-- MapValueExpr
MapKeyExpr *-- ExprSingle
MapValueExpr *-- ExprSingle
ArrayConstructor *-- "enum" SquareArrayConstructor
ArrayConstructor *-- "enum" CurlyArrayConstructor
SquareArrayConstructor *-- "1..*" ExprSingle
CurlyArrayConstructor *-- EnclosedExpr
UnaryLookup *-- KeySpecifier
SingleType *-- SimpleTypeName
TypeDeclaration *-- SequenceType
SequenceType *-- "enum" EmptySequenceType
SequenceType *-- "enum" SequenceItem
SequenceItem *-- ItemType
SequenceItem *-- "0..1" OccurrenceIndicator
ItemType *-- "enum" KindTest
ItemType *-- "enum" ItemTest
ItemType *-- "enum" FunctionTest
ItemType *-- "enum" MapTest
ItemType *-- "enum" ArrayTest
ItemType *-- "enum" AtomicOrUnionType
ItemType *-- "enum" ParenthesizedItemType
AtomicOrUnionType *-- EQName
KindTest *-- "enum" DocumentTest
KindTest *-- "enum" ElementTest
KindTest *-- "enum" AttributeTest
KindTest *-- "enum" SchemaElementTest
KindTest *-- "enum" SchemaAttributeTest
KindTest *-- "enum" PITest
KindTest *-- "enum" CommentTest
KindTest *-- "enum" TextTest
KindTest *-- "enum" NamespaceNodeTest
KindTest *-- "enum" AnyKindTest
DocumentTest *-- ElementTest
DocumentTest *-- "0..1" SchemaElementTest
PITest *-- "0..1" PITestType
PITestType *-- "enum" NCName
PITestType *-- "enum" StringLiteral
AttributeTest *-- "0..1" AttributeTestItem
AttributeTestItem *-- AttribNameOrWildcard
AttributeTestItem *-- "0..1" TypeName
AttribNameOrWildcard *-- "enum" AttributeName
AttribNameOrWildcard *-- "enum" AttributeWildcard
SchemaAttributeTest *-- AttributeDeclaration
AttributeDeclaration *-- AttributeName
ElementTest *-- "0..1" ElementTestItem
ElementTestItem *-- ElementNameOrWildcard
ElementTestItem *-- "0..1" TypeName
ElementNameOrWildcard *-- "enum" ElementName
ElementNameOrWildcard *-- "enum" ElementWildcard
SchemaElementTest *-- ElementDeclaration
ElementDeclaration *-- ElementName
Attributename *-- EQName
ElementName *-- EQName
SimpleTypeName *-- TypeName
TypeName *-- EQName
FunctionTest *-- "enum" AnyFunctionTest
FunctionTest *-- "enum" TypedFunctionTest
TypedFunctionTest *-- "0..*" SequenceType
MapTest *-- "enum" AnyMapTest
MapTest *-- "enum" TypedMapTest
TypedMapTest *-- AtomicOrUnionType
TypedMapTest *-- SequenceType
ArrayTest *-- "enum" AnyArrayTest
ArrayTest *-- "enum" TypedArrayTest
TypedArrayTest *-- SequenceType
ParenthesizedItemType *-- ItemType
EQName *-- "enum" QName
EQName *-- "enum" URIQualifiedName
```
--------------------------------
### Applying XPath Query in Rust using Skyscraper
Source: https://github.com/james-lg/skyscraper/blob/master/README.md
This code demonstrates how to parse an XPath expression and apply it to an HTML document tree generated by Skyscraper. It shows how to retrieve the resulting items, access node data, and verify the extracted element name.
```Rust
use skyscraper::html;
use skyscraper::xpath::{self, XpathItemTree, grammar::{XpathItemTreeNodeData, data_model::{Node, XpathItem}}};
use std::error::Error;
fn main() -> Result<(), Box> {
let html_text = r##"
Hello world
"##;
let document = html::parse(html_text)?;
let xpath_item_tree = XpathItemTree::from(&document);
let xpath = xpath::parse("//div")?;
let item_set = xpath.apply(&xpath_item_tree)?;
assert_eq!(item_set.len(), 1);
let mut items = item_set.into_iter();
let item = items
.next()
.unwrap();
let element = item
.as_node()?;
.as_tree_node()?;
.data
.as_element_node()?;
assert_eq!(element.name, "div");
Ok(())
}
```
--------------------------------
### Parsing HTML with Skyscraper in Rust
Source: https://github.com/james-lg/skyscraper/blob/master/README.md
This snippet demonstrates the basic process of parsing an HTML string into a traversable document structure using the `skyscraper::html::parse` function. It requires the `skyscraper` crate and handles potential parsing errors.
```Rust
use skyscraper::html::{self, parse::ParseError};
let html_text = r##"
Hello world
"##;
let document = html::parse(html_text)?;
```
--------------------------------
### Showing Rust Stack Overflow Test Output
Source: https://github.com/james-lg/skyscraper/blob/master/tests/stack_overflow_tests/README.md
This snippet displays the console output from a failed execution of the stack overflow test. It illustrates the typical error messages including the thread panic, stack overflow status code (0xc00000fd, STATUS_STACK_OVERFLOW), and compiler output indicating the debug build.
```Rust
---- does_this_run stdout ----
thread 'does_this_run' panicked at tests\run_stack_overflow_tests.rs:20:5:
Compiling skyscraper_stack_overflow_tests v0.1.0 (D:\code\Skyscraper\tests\stack_overflow_tests)
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
Running `tests\stack_overflow_tests\target\debug\skyscraper_stack_overflow_tests.exe`
thread 'main' has overflowed its stack
error: process didn't exit successfully: `tests\stack_overflow_tests\target\debug\skyscraper_stack_overflow_tests.exe` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.