Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed Apr 19, 2024
1 parent 9bbb586 commit d4729ee
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "as3_parser"
version = "0.5.5"
version = "0.5.7"
edition = "2021"
authors = ["hydroper <[email protected]>"]
repository = "https://github.com/hydroper/as3parser"
Expand Down
19 changes: 12 additions & 7 deletions crates/parser/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3951,20 +3951,25 @@ impl<'input> Parser<'input> {
}

fn parse_configuration_primary_expression(&mut self) -> Result<Rc<Expression>, ParserError> {
if let Token::Identifier(id) = &self.token.0.clone() {
if let Token::Identifier(_) = &self.token.0.clone() {
self.mark_location();
self.next()?;
let mut id = id.clone();
let mut id = self.expect_identifier(false)?;
let mut qual: Option<Rc<Expression>> = None;
if self.consume(Token::ColonColon)? {
let (id_1, _) = self.expect_identifier(true)?;
id = id + &"::".to_owned() + &id_1;
qual = Some(Rc::new(Expression::QualifiedIdentifier(QualifiedIdentifier {
location: id.1.clone(),
attribute: false,
qualifier: None,
id: QualifiedIdentifierIdentifier::Id(id.clone()),
})));
id = self.expect_identifier(true)?;
}
let id_location = self.pop_location();
let id = Rc::new(Expression::QualifiedIdentifier(QualifiedIdentifier {
location: id_location.clone(),
attribute: false,
qualifier: None,
id: QualifiedIdentifierIdentifier::Id((id, id_location)),
qualifier: qual,
id: QualifiedIdentifierIdentifier::Id(id.clone()),
}));
let equality: Option<Operator> = if self.consume(Token::Assign)? {
Some(Operator::Equals)
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ mod mxml;
pub use mxml::*;

// CSS
mod css;
pub use css::*;
// mod css;
// pub use css::*;

mod tree_semantics;
pub use tree_semantics::*;
25 changes: 25 additions & 0 deletions crates/parser/tree/configuration_directive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
use crate::ns::*;
use serde::{Serialize, Deserialize};

/// The `configuration {}` directive.
///
/// # Syntax
///
/// The directive consists of a block
/// of `if..else` branches, whose
/// condition is one of the following expressions:
///
/// ```plain
/// // Check whether constant is "true"
/// q::x
/// x
/// // Check whether constant is "v"
/// k="v"
/// k=v // QualifiedIdentifier == StringLiteral
/// // Check whether constant is not "v"
/// k!="v"
/// k!=v // QualifiedIdentifier != StringLiteral
///
/// x && y
/// x || y
///
/// (x)
/// !x
/// ```
#[derive(Clone, Serialize, Deserialize)]
pub struct ConfigurationDirective {
pub location: Location,
Expand Down
1 change: 1 addition & 0 deletions crates/parser/tree/mxml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct MxmlAttribute {
/// Indicates whether the attribute is a `xmlns` or `xmlns:` attribute.
pub xmlns: bool,
pub name: MxmlName,
/// Attribute value. The location data includes the quotes.
pub value: (String, Location),
}

Expand Down
Binary file modified demo/dist/as3_parser_demo_bg.wasm
Binary file not shown.
33 changes: 21 additions & 12 deletions docs/new-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,7 @@ switch type (o) {

## Configuration Directive

`configuration { ... }` means conditional compilation with `if`, `else if` and `else` branches. A limited set of expressions are valid and translate to a different syntactic construct:

* `q::x` translates to an identifier whose name is literally `"q::x"` without a qualifier.
* `x` asks whether a constant `x` is present.
* `k="v"` translates to `k == "v"`.
* `k=v` translates to `k == "v"`.
* `k!="v"` goes as is.
* `k!=v` translates to `k != "v"`.
* `x && y`
* `x || y`
* `(x)`
* `!x`
`configuration { ... }` means conditional compilation with `if`, `else if` and `else` branches. A limited set of conditional expressions are valid and translate to a different syntactic construct:

```
configuration {
Expand All @@ -167,6 +156,26 @@ configuration {
}
```

Conditional expressions:

```actionscript3
// Check whether constant is "true"
q::x
x
// Check whether constant is "v"
k="v"
k=v // QualifiedIdentifier == StringLiteral
// Check whether constant is not "v"
k!="v"
k!=v // QualifiedIdentifier != StringLiteral
x && y
x || y
(x)
!x
```

## Parameterized Types

```
Expand Down

0 comments on commit d4729ee

Please sign in to comment.