Skip to content

Commit

Permalink
Old progress on detached rulesets #186 . Plenty of tests are failing and
Browse files Browse the repository at this point in the history
the approach can not possibly work. See detached ruleset in list tests to
see the problem.
  • Loading branch information
jurcovicovam committed May 31, 2014
1 parent 91f317f commit 637497d
Show file tree
Hide file tree
Showing 46 changed files with 742 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ top_level_element
: (mixinReferenceWithSemi)=>mixinReferenceWithSemi
| (namespaceReferenceWithSemi)=>namespaceReferenceWithSemi
| (reusableStructureName LPAREN)=>reusableStructure
| (detachedRulesetReference)=>detachedRulesetReference
| (variabledeclaration)=>variabledeclaration
| ruleSet
| media_top_level
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/github/sommeri/less4j/LessSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ public FileSource(FileSource parent, String filename) {

@Override
public URI getURI() {
if (inputFile==null)
return null;

try {
String path = inputFile.toString();
path = URIUtils.convertPlatformSeparatorToUri(path);
Expand All @@ -231,7 +234,7 @@ public URI getURI() {

@Override
public String getName() {
return inputFile.getName();
return inputFile==null? null: inputFile.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public abstract class ASTCssNode implements PubliclyCloneable {
//I'm using underlying structure as identified in cycle detector. If it stops to be identifying,
//cycle detector must be modified. !
private HiddenTokenAwareTree underlyingStructure;
// //A scope used
// private IScope primaryScope;
// //
private List<Comment> openingComments = new ArrayList<Comment>();
private List<Comment> orphanComments = new ArrayList<Comment>();
private List<Comment> trailingComments = new ArrayList<Comment>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.sommeri.less4j.core.ast;

public interface BodyOwner<T extends Body> {
import com.github.sommeri.less4j.utils.PubliclyCloneable;

public interface BodyOwner<T extends Body> extends PubliclyCloneable {

public BodyOwner<T> clone();

void setBody(T body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class DetachedRulesetReference extends ASTCssNode {

public DetachedRulesetReference(HiddenTokenAwareTree token, Variable variable) {
super(token);
this.variable = variable;
}

public Variable getVariable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.github.sommeri.less4j.core.ast.ASTCssNode;
import com.github.sommeri.less4j.core.ast.ASTCssNodeType;
import com.github.sommeri.less4j.core.ast.AbstractVariableDeclaration;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpressionOperator.Operator;
import com.github.sommeri.less4j.core.ast.ComparisonExpression;
import com.github.sommeri.less4j.core.ast.ComparisonExpressionOperator;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.CssString;
import com.github.sommeri.less4j.core.ast.EmbeddedScript;
import com.github.sommeri.less4j.core.ast.EscapedValue;
Expand All @@ -40,8 +40,9 @@
import com.github.sommeri.less4j.core.compiler.expressions.strings.StringInterpolator;
import com.github.sommeri.less4j.core.compiler.scopes.BasicScope;
import com.github.sommeri.less4j.core.compiler.scopes.FullMixinDefinition;
import com.github.sommeri.less4j.core.compiler.scopes.FullNodeDefinition;
import com.github.sommeri.less4j.core.compiler.scopes.ILocalScope;
import com.github.sommeri.less4j.core.compiler.scopes.IScope;
import com.github.sommeri.less4j.core.compiler.scopes.ScopeFactory;
import com.github.sommeri.less4j.core.compiler.scopes.ScopesTree;
import com.github.sommeri.less4j.core.compiler.scopes.local.LocalScope;
import com.github.sommeri.less4j.core.problems.BugHappened;
Expand Down Expand Up @@ -103,22 +104,6 @@ public List<Expression> evaluateAll(List<Expression> expressions) {
return values;
}

public IScope evaluateValues(IScope scope) {
IScope result = ScopeFactory.createDummyScope();
result.addFilteredVariables(toEvaluationFilter(), scope);
return result;
}

private ExpressionFilter toEvaluationFilter() {
return new ExpressionFilter() {

@Override
public Expression apply(Expression input) {
return evaluate(input);
}
};
}

public Expression evaluate(CssString input) {
String value = stringInterpolator.replaceIn(input.getValue(), this, input.getUnderlyingStructure());
return new CssString(input.getUnderlyingStructure(), value, input.getQuoteType());
Expand All @@ -140,42 +125,64 @@ public Expression evaluate(Variable input) {
return new FaultyExpression(input);
}

Expression value = scope.getValue(input);
if (value == null) {
FullNodeDefinition value = scope.getValue(input);
if (value == null || value.getNode()==null) {
problemsHandler.undefinedVariable(input);
return new FaultyExpression(input);
}
if (!(value.getNode() instanceof Expression)) {
//FIXME !!!!!!!!!!!!!!!!! what to do here????
return input;
}
Expression expression = (Expression)value.getNode();

cycleDetector.enteringVariableValue(input);
Expression result = evaluate(value);
Expression result = evaluate(expression);
cycleDetector.leftVariableValue();
return result;
}

public Expression evaluateIfPresent(Variable input) {
Expression value = scope.getValue(input);
FullNodeDefinition value = scope.getValue(input);
if (value == null) {
return null;
}

return evaluate(value);
if (!(value.getNode() instanceof Expression)) {
//FIXME !!!!!!!!!!!!!!!!! what to do here????
return input;
}
Expression expression = (Expression)value.getNode();
return evaluate(expression);
}

public Expression evaluate(IndirectVariable input) {
Expression value = scope.getValue(input);
if (!(value instanceof CssString)) {
FullNodeDefinition value = scope.getValue(input);
if (!(value.getNode() instanceof Expression)) {
//FIXME !!!!!!!!!!!!!!!!! what to do here????
return input;
}
Expression expression = (Expression)value.getNode();
if (!(expression instanceof CssString)) {
problemsHandler.nonStringIndirection(input);
return new FaultyExpression(input);
}

CssString realName = (CssString) value;
CssString realName = (CssString) expression;
String realVariableName = "@" + realName.getValue();
//FIXME: !!!!!!!!!!!! bypassing cycle detector!!!!!! (test also less.js)
value = scope.getValue(realVariableName);
if (value == null) {
problemsHandler.undefinedVariable(realVariableName, realName);
return new FaultyExpression(realName.getUnderlyingStructure());
}
return evaluate(value);
if (!(value.getNode() instanceof Expression)) {
//FIXME !!!!!!!!!!!!!!!!! what to do here????
return input;
}
//FIXME !!!!!!!!!!!!!!!!! reusing variable ugly
expression = (Expression)value.getNode();
return evaluate(expression);
}

public Expression evaluate(Expression input) {
Expand Down Expand Up @@ -442,35 +449,27 @@ public boolean hasParent() {
}

@Override
public void registerVariable(AbstractVariableDeclaration declaration) {
public void registerVariable(AbstractVariableDeclaration node, FullNodeDefinition replacementValue) {
}

@Override
public void registerVariable(AbstractVariableDeclaration node, Expression replacementValue) {
public void registerVariableIfNotPresent(String name, FullNodeDefinition replacementValue) {
}

@Override
public void registerVariableIfNotPresent(String name, Expression replacementValue) {
}

@Override
public Expression getValue(Variable variable) {
public FullNodeDefinition getValue(Variable variable) {
return null;
}

@Override
public Expression getValue(String name) {
public FullNodeDefinition getValue(String name) {
return null;
}

@Override
public void registerMixin(ReusableStructure mixin, IScope mixinsBodyScope) {
}

// @Override
// public void setParent(IScope parent) {
// }

@Override
public void removedFromAst() {
}
Expand Down Expand Up @@ -500,11 +499,11 @@ public String toFullName() {
}

@Override
public void registerVariable(String name, Expression replacementValue) {
public void registerVariable(String name, FullNodeDefinition replacementValue) {
}

@Override
public void addFilteredVariables(ExpressionFilter filter, IScope source) {
public void addFilteredContent(LocalScopeFilter filter, ILocalScope source) {
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.sommeri.less4j.core.compiler.expressions;

import com.github.sommeri.less4j.core.compiler.scopes.FullNodeDefinition;
import com.github.sommeri.less4j.core.compiler.scopes.IScope;

public interface LocalScopeFilter {

IScope apply(IScope input);

FullNodeDefinition apply(FullNodeDefinition value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import com.github.sommeri.less4j.core.ast.ASTCssNode;
import com.github.sommeri.less4j.core.ast.Expression;
import com.github.sommeri.less4j.core.ast.Variable;

public class BasicScope extends ComposedDumbScope implements IScope {
Expand All @@ -17,16 +16,16 @@ public IScope firstChild() {
return getChilds().get(0);
}

public Expression getValue(Variable variable) {
public FullNodeDefinition getValue(Variable variable) {
return getValue(variable.getName());
}
public Expression getValue(String name) {
Expression value = getLocalValue(name);

public FullNodeDefinition getValue(String name) {
FullNodeDefinition value = getLocalValue(name);

if (value == null && hasParent())
value = getParent().getValue(name);

return value;
}

Expand Down Expand Up @@ -62,7 +61,6 @@ public boolean seesLocalDataOf(IScope otherScope) {
return getParent().seesLocalDataOf(otherScope);
}


public IScope getRootScope() {
if (!hasParent())
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import com.github.sommeri.less4j.core.ast.ASTCssNode;
import com.github.sommeri.less4j.core.ast.AbstractVariableDeclaration;
import com.github.sommeri.less4j.core.ast.Expression;
import com.github.sommeri.less4j.core.ast.ReusableStructure;
import com.github.sommeri.less4j.core.ast.ReusableStructureName;
import com.github.sommeri.less4j.core.ast.Variable;
import com.github.sommeri.less4j.core.compiler.expressions.ExpressionFilter;
import com.github.sommeri.less4j.core.compiler.expressions.LocalScopeFilter;
import com.github.sommeri.less4j.core.compiler.scopes.local.LocalScopeData;
import com.github.sommeri.less4j.core.compiler.scopes.local.MixinsDefinitionsStorage;
import com.github.sommeri.less4j.core.compiler.scopes.local.VariablesDeclarationsStorage;
Expand Down Expand Up @@ -47,24 +46,20 @@ public boolean hasTheSameLocalData(ILocalScope otherScope) {
return localScope.hasTheSameLocalData(otherScope);
}

public void registerVariable(AbstractVariableDeclaration declaration) {
localScope.registerVariable(declaration);
}

public void registerVariable(AbstractVariableDeclaration node, Expression replacementValue) {
public void registerVariable(AbstractVariableDeclaration node, FullNodeDefinition replacementValue) {
localScope.registerVariable(node, replacementValue);
}

public void registerVariableIfNotPresent(String name, Expression replacementValue) {
public void registerVariableIfNotPresent(String name, FullNodeDefinition replacementValue) {
localScope.registerVariableIfNotPresent(name, replacementValue);
}

public void registerVariable(String name, Expression replacementValue) {
public void registerVariable(String name, FullNodeDefinition replacementValue) {
localScope.registerVariable(name, replacementValue);
}

public void addFilteredVariables(ExpressionFilter filter, IScope source) {
localScope.addFilteredVariables(filter, source);
public void addFilteredContent(LocalScopeFilter filter, ILocalScope source) {
localScope.addFilteredContent(filter, source);
}

public void registerMixin(ReusableStructure mixin, IScope mixinsBodyScope) {
Expand Down Expand Up @@ -144,11 +139,11 @@ public boolean isBodyOwnerScope() {
return localScope.isBodyOwnerScope();
}

public Expression getLocalValue(Variable variable) {
public FullNodeDefinition getLocalValue(Variable variable) {
return localScope.getValue(variable);
}

public Expression getLocalValue(String name) {
public FullNodeDefinition getLocalValue(String name) {
return localScope.getValue(name);
}

Expand Down

This file was deleted.

Loading

0 comments on commit 637497d

Please sign in to comment.