Skip to content

Instantly share code, notes, and snippets.

@highwaycoder
Last active December 30, 2015 01:09
Show Gist options
  • Save highwaycoder/7754801 to your computer and use it in GitHub Desktop.
Save highwaycoder/7754801 to your computer and use it in GitHub Desktop.
Grammar for my proposal for a DSL for laying out websites written in HTML/CSS. I'm just looking for feedback on the grammar, not on the proposal itself (I'm sure there are lots who think it's a stupid idea) nor the beginnings of the implementation.
%{
require("Layout");
// just ignore this line, it's related to my plans to implement the language, but I just want feedback on the grammar right now.
var layout = new Layout();
%}
%lex
%%
\s+ /* Skip whitespace */
"position" return "position";
"rotation" return "rotation";
"origin" return "origin";
"scew" return "scew";
"scale" return "scale";
"relative to"|"rel" return "relative to";
"absolute"|"relative to $viewport" return "absolute";
"x" return "x";
"y" return "y";
"z" return "z";
"xy" return "xy";
"xyz"|"all" return "all";
"%" return "%";
"px" return "px";
"f" return "f";
"$viewport" return "$viewport";
"$self" return "$self";
"$window" return "$window";
"$page" return "$page";
"$screen" return "$screen";
"$parent"|"$$" return "$parent";
[0-9]+\.[0-9]+ return "number";
[0-9]+ return "integer";
. return "selector";
/lex
%start layout
%% /* language grammar */
layout
: statements EOF
{{ layout.compile(); }}
;
statements
: statement
| statements statement
;
statements
: "selector" command relationship value
;
command
: "position"
| "origin"
| "scale"
| "rotation"
| "scew"
;
relationship
: "relative to" selector
| "relative to" special_selector
| "absolute"
;
value
: '{' properties '}'
;
properties
: property
| properties property
;
property
: "x" ":" rvalue
| "y" ":" rvalue
| "z" ":" rvalue
| "xy" ":" rvalue
| "all" ":" rvalue
;
rvalue
: "number" "%"
| "integer" "px"
| "number" "f"
;
special_selector
: "$viewport"
| "$self"
| "$window"
| "$page"
| "$screen"
| "$parent"
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment