Module: POECSS
- Defined in:
- lib/poe-css.rb,
lib/poe-css/parser.rb,
lib/poe-css/version.rb,
lib/poe-css/generator.rb,
lib/poe-css/simplifier.rb,
lib/poe-css/preprocessor.rb
Defined Under Namespace
Modules: Generator, Parser, Preprocessor, Simplifier Classes: Clause, CommandClause, MatchClause, ParseError, RGBColorSpec, SimpleClause
Constant Summary collapse
- VERSION =
'0.0.1'
Class Method Summary collapse
Class Method Details
.compile(input) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/poe-css.rb', line 67 def compile(input) # Strip comments, which is anything after a # in any line. No # preprocessor or POE CSS syntax uses the #, and it doesn't appear in any # strings (it could, but no item has a # in it), so it's safe to # disregard all syntax when removing comments. input_without_comments = input.split("\n").map { |l| l.gsub(/#.*$/, '') }.join("\n") # Use the preprocessor to expand constants and macros. preprocessed_program = Preprocessor.compile(input_without_comments) # Hand the contents over to the main parser, which returns a list of Clauses. parsed_clauses = Parser.parse_input(preprocessed_program) # These Clauses, each of which can contain alternations (ORs) or nested # clauses, get transformed into SimpleClauses. A SimpleClause is just a # list of ANDed match clauses and a list of commands. The nesting and # alternations have been expanded. We also simplify clauses here to # minimize inputs into the next step as well as to collapse/minimize # duplicated match and command keys for speed/simplicity. = (parsed_clauses).map { |r| Simplifier.simplify_clause(r) }.compact # SimpleClauses are then converted into a list of rules in else-if form, # the logical flow style used by PoE. The datatype is still SimpleClause, # but the clauses have all been transformed and expanded to meet the # else-if form (I call them rules to distinguish them conceptually from # clauses). else_ifed_rules = clauses_to_else_if_rules() # Finally, rules that will never be hit or contribute nothing to to final # result are deleted. This does not remove every useless clause but is # likely good enough to suffice. rules_without_dead_rules = rules_without_dead_rules(else_ifed_rules) # Finally, we hand the results to the generator, which outputs them in # PoE item filter format. Generator.generate_poe_rules(rules_without_dead_rules) end |