Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tz-lom/NTM
base: 665b36145e
...
head fork: tz-lom/NTM
compare: 478c90efad
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 25, 2011
Nuzhdin Urii Tests closed b5450ec
Commits on Oct 26, 2011
Nuzhdin Urii css parser and lexer became nicer 478c90e
View
11 library/NTM/CSS/AttributeTest.php
@@ -13,10 +13,19 @@ class AttributeTest
protected $value;
protected $testcase;
protected $ext;
+ protected $namespace;
public function __construct($attr,$test,$value,$ext=NULL)
{
- $this->attr = $attr;
+ if(is_array($attr))
+ {
+ $this->namespace = $attr[0];
+ $this->attr = $attr[1];
+ }
+ else
+ {
+ $this->attr = $attr;
+ }
$this->testcase = $test;
$this->value = $value;
$this->ext = $ext;
View
12 library/NTM/CSS/SimpleSelector.php
@@ -19,6 +19,7 @@ class SimpleSelector
protected $attributes = array();
protected $pseudo = array();
protected $parent = NULL;
+ protected $namespace;
/**
* @return SimpleSelector
@@ -121,5 +122,16 @@ public function getRoot()
return $this;
}
}
+
+ /**
+ *
+ * @param type $namespace
+ * @return SimpleSelector
+ */
+ public function setNamespace($namespace)
+ {
+ $this->namespace = $namespace;
+ return $this;
+ }
}
View
22 library/NTM/CSS3Parser.y
@@ -51,17 +51,18 @@ selector_variance(r) ::= attrib(v). { r = SimpleSelector::instance()->add
selector_variance(r) ::= pseudo(v). { r = SimpleSelector::instance()->addPseudoClass(v); }
selector_variance(r) ::= negation. { r = SimpleSelector::instance(); }
-type_selector(t) ::= namespace_prefix IDENT(i). { t = SimpleSelector::instance()->setElement(i->value); }
-type_selector(t) ::= IDENT(i). { t = SimpleSelector::instance()->setElement(i->value); }
+type_selector(t) ::= namespace_prefix(n) IDENT(i). { t = SimpleSelector::instance()->setElement(i->value)->setNamespace(n); }
+type_selector(t) ::= IDENT(i). { t = SimpleSelector::instance()->setElement(i->value); }
-namespace_prefix ::= IDENT PIPE.
-namespace_prefix ::= STAR PIPE.
+namespace_prefix(p) ::= IDENT(i) PIPE. { p = i->value; }
+namespace_prefix(p) ::= STAR PIPE. { p = '*'; }
+namespace_prefix(p) ::= PIPE. { p = ''; }
-universal(u) ::= namespace_prefix STAR. { u = SimpleSelector::instance()->setElement('*'); }
-universal(u) ::= STAR. { u = SimpleSelector::instance()->setElement('*'); }
+universal(u) ::= namespace_prefix(n) STAR. { u = SimpleSelector::instance()->setElement('*')->setNamespace(n); }
+universal(u) ::= STAR. { u = SimpleSelector::instance()->setElement('*'); }
-identity(i) ::= namespace_prefix IDENT(s). { i = s->value; }
-identity(i) ::= IDENT(s). { i = s->value; }
+identity(i) ::= namespace_prefix(n) IDENT(s). { i = array(n,s->value); }
+identity(i) ::= IDENT(s). { i = s->value; }
attrib(a) ::= ATTR_OPEN identity(i) relation(r) value(v) ATTR_CLOSE. { a = new AttributeTest(i,r,v); }
attrib(a) ::= ATTR_OPEN identity(i) relation(r) value(v) S IDENT(x) ATTR_CLOSE. { a = new AttributeTest(i,r,v,x); }
@@ -80,7 +81,7 @@ pseudo(p) ::= COLON IDENT(i). { p = new PseudoClass(i->value); }
pseudo(p) ::= COLON COLON IDENT(i). { p = new PseudoClass(':'.i->value); }
pseudo(p) ::= COLON functional_pseudo(f). { p = f; }
-functional_pseudo(f) ::= FUNCTION(n) expression_list(l) FUNCTION_CLOSE. { f = new PseudoClass(n,l); }
+functional_pseudo(f) ::= FUNCTION(n) expression_list(l) FUNCTION_CLOSE. { f = new PseudoClass(n->value,l); }
expression_list(l) ::= expression(e). { l = e; }
expression_list(l) ::= expression_list(o) expression(e). { l = o.e; }
@@ -89,9 +90,10 @@ expression_list(l) ::= expression_list(o) S expression(e). { l = o.' '.e; }
expression(e) ::= PLUS. { e = '+'; }
expression(e) ::= DIMENSION(d). { e = d->value; }
expression(e) ::= NUMBER(n). { e = n->value; }
-expression(e) ::= STRING(s). { e = s->value; }
+expression(e) ::= STRING(s). { e = '"'.s->value; }
expression(e) ::= IDENT(i). { e = i->value; }
expression(e) ::= MINUS. { e = '-'; }
+expression(e) ::= CLASS(s). { e = '.'.s->value; }
negation(n) ::= NOT negation_arg(a) FUNCTION_CLOSE. { n = new PseudoClass('not',a); }
View
2  library/NTM/build.cssparser.sh
@@ -1,7 +1,7 @@
#!/bin/bash
echo "=== Generate lexer"
-#java -cp ../../3dparty/JLexPHP/JLexPHP.jar JLexPHP.Main CSS3Lexer
+java -cp ../../3dparty/JLexPHP/JLexPHP.jar JLexPHP.Main CSS3Lexer
echo
echo "=== Generate parser"
../../3dparty/lemon-php/lemon -LPHP -m CSS3Parser.y
View
18 tests/NTM/LexerAndParserTest.php
@@ -147,11 +147,11 @@ public function parserTestProvider()
)
),
array(
- ':column(col.selected)',
+ ':column(col.select)',
array(
SimpleSelector::instance()->addPseudoClass(new CSS\PseudoClass(
'column',
- SimpleSelector::instance()->setElement('col')->addClass('selected')
+ 'col.select'
))
)
),
@@ -192,6 +192,20 @@ public function parserTestProvider()
))
)
)
+ ),
+ array(
+ 'ns|div[ns2|attr$=value]',
+ array(
+ SimpleSelector::instance()->setElement('div')->setNamespace('ns')->addAttribute(
+ new CSS\AttributeTest(array('ns2','attr'), '$=', 'value')
+ )
+ )
+ ),
+ array(
+ '|*',
+ array(
+ SimpleSelector::instance()->setElement('*')->setNamespace('')
+ )
)
);

No commit comments for this range

Something went wrong with that request. Please try again.