Skip to content

Commit

Permalink
Updates syntax description for GoodLooking
Browse files Browse the repository at this point in the history
It's not optimal, but at least we have something describing the current
syntax once again (rather than something horribly outdated).

This resolves #63.
  • Loading branch information
JasperHorn committed Feb 23, 2014
1 parent c091ad7 commit cdde2e3
Showing 1 changed file with 91 additions and 102 deletions.
193 changes: 91 additions & 102 deletions Good/Looking/syntax.txt
Original file line number Diff line number Diff line change
@@ -1,112 +1,101 @@
- scripts will be delimited by "<:" and ":>" (no apostrophes of course)
- comments will be delimited by "<:-" and "-:>" (still no apostrophes)
- comment can be inside and outside script tags
- a script can have either one or more statements, if more they must be seperated by semicolons (";")
- each statement does one of the following:
- print a value to the file
- executes a function (there are only two functions for now)
- defines a part of a control structure

The functions are:
- include(filename) - this includes another file, at the point where it is written
the included file will be parsed like any other contents of the template
- nameForCounter(varName) - this will bind the varName to the counter that counts the loops
the most recent for or foreach loop, for use in the file
NameForCounter will only be executed the first time a loop is
in for loops the counter can count up or down, in foreach loops it
always counts down.
Please note that fileName will be a string, encapsulated by (single?) apostrophes if a literal (and thus
variables can be used in it), while varName will not be. It will always be a literal and it won't
have anything around it.
Script and comment tags

The control structures are:
- if (condition) - the following code and/or literal text will only be executed if condition is true
- end if - the following code and/or literal text will no longer be influenced by the last if
must be present for if statement to work
- foreach(varName in array) - the following code and/or literal will be executed once for each
element the array has, that element being stored varName during
any code it applies to. varName will be accessible like any
registered variable under any circumstances
- end foreach - end of the block that will be executed for each member of the array
must be present for foreach statement to work
- for(beginValue {--> or ++>} endValue) - will execute the following content a number fo times,
namely, when a variable has gotten from beginValue to
endValue by increasing (++>) or decreasing (-->) by one
every time through the loop. Executes for both beginValue
and endValue as well (if reached, that is. With beginValue 1
and endValue 9.5, 9.5 won't be executed).
Should give an error if with chosen operation endValue will
not be reached from beginValue
-------------- Rethinking this (while I like the --> notation (it just looks good :D)
the ++> is just plain ugly and confusing. All the same,
one symbol would be enough - as only one route is to be
used - the correct one, the one that would not cause
an infinte loop ;)
- end for - denotes the end of a for structure
must be present for the for statement to work
- Code is "<:" and ":>" (obviously, there's not quotes)
- Comments are between "<:-" and "-:>" (again, no quotes)
- Comments can be inside or outside code tags

Code

The rules for printing values to the screen are:
- Types of content that may be used are:
- variables
- literal numbers
Note that literal strings may not be used, simply close the script if you need to
print a literal string to the file
---- Rethinking this (even though there may just be an easy other solution,
why should I prohibit printing a literal string?)
- Code consists of expressions and control structures.
- Expressions are closed off by either a semicolon (;)
or the end of a code block (:>)
- Control structures consists of:
- an "opener", which is closed by a colon (:)
- a body of a mix of zero or more other expressions,
direct text (between ":>" and "<:"...) and further
control structures.
- the matching "closer" followed by a semicolon (;)

- Operations that may be used are:
- adding (+)
- subtracting (-)
- multiplying (*)
- dividing (/)
- modulus (%)
Expressions

Concatenating is not allowed - just print two things right after each other if you need to
Parentheses may be used to alter the order in which operations should be executed
These operations may also be used in if-statements, function calls or choosing an array
- A statement that prints a value to the file must consist of one or more variables
or literal numbers. If more than one value is used, there must be a operations between each
value. Parentheses may be used to prioritise operations
- The value of an expression used at the top level will be
escaped and then printed to the output.
- Each expression is either a single term or a a number of terms
with operators between them
- A term is one of:
- an exprression between brackets ('(' and ')')
- a call to a function, in the form of:
"functionname(argument)" where arguments is a comma-seperated
list of of expressions
- A literal:
- Integer (e.g. 12331)
- Float (e.g. 546.456)
- String (e.g. "bla" or 'asdas')
- Boolean (true or false, case insensitive)
- A variable:
- consisting of a dollar sign ($) one letter and one or more
letters and/or numbers
- a variable will evaluate to the value it was registered with
by the php code that requested this template to be parsed or
to the current value assigned to it by a control structure

Functions

- No functions have been implemented yet, so it's not yet valid
to use them
- Quite a number of function are planned, but the some of the
most urgent ones are:
- include() (what's the value of a template system without it?)
- noEscape() (print things to the output without escaping)

Other operations that may be used are:
Operators

- Logical operations:
these are only to be used inside if statements
---- Rethinking this (why make a fuss - it's probably going to be the same function
---- doing the work anyway)
slashes indicate that there are two ways to invoke the operation
- and / && - returns true if the preceding and the following statements are true
- or / || - returns true if the preceeding or the following statements are true
- Comparison operations
these are only to be used inside if statements
slashes indicate that there are two ways to invoke the operation
- == / = - equals, returns true if the preceeding and following statements are true
preference is given to "==", but since there is no other use for "=" you may use it as well
- != - does not equal, returns true if the preceeding and following statement are not the same
- ! - not, returns true if the following statements is false
- > - more than, returns true if the preceeding number is larger than the following
- < - less than, returns true if the preceeding number is less than the following
- <= - less than or equal to, returns true if either < or == would
- >= - more than or equal to, returns true if either > or == would
- The available operators are:
- + (addition)
- - (subtraction)
- * (multiplication)
- / (division)
- % (modulus)
- . (concatenation)
- == (type insensitive equality)
- === (type sensitive equality)
- != (type insensitive inequality)
- !== (type sensitive inequality)
- > (greater than)
- < (less than)
- <= (less or equal)
- >= (greater or equal)
- && (logical and)
- and (alternative logical and)
- || (logical or)
- or (alternative logical or)
- xor (logical exclusive or)
- the unary operator logical not (!) is planned, but not implemented
if you need it now, you can use "!= true" instead

- Concatenation
Concatenation may only be used in function calls and choosing an array element
---- rethinking this (why make a fuss, it'll probably be the same function called anyway)
To please all programmers both '+' and '.' may be used for concatenation
(it's not like I am going to be short on symbols)
When trying to concatenate when not allowed an error might be thrown about an
unexpected symbol, or not being able to add up strings
If the '+' operator is used, if both arguments are strings, or the first is a string and the second a
number they will be concatenated, if both arguments are numbers they will be added up
If you would supply a number for the first and a string for the second value, an error will be thrown
If the '.' operator is used, the two values will always be concatenated, even if they are both numbers
-> Allowing '+' for both concatenation and addition while using variables
that may have any type and making compiled code will only result in
messy compiled code and extra (complicated) code needed in the compile
script - thus I will restrict concatenation to only the dot
----> I am not so sure about my previous comment, as even in the compiled
version we can of course draw upon functions that are from the
templating system
-------> Final conclusion: not in the earlier versions, maybe later (double using +)
Control Structures:

The control structures are:
- if (condition): {body} endif;
{body} will be if the expression condition evaluates to true

- foreach(array as $varName): {body} endforeach;
{body} will be executed once for each element in the collection
(arrray or Traversable) - $varName will take the value of one of
the elements in the collection each time, following the order of
the collection

- forrange(beginValue --> endValue) {body} endforrange;
{body} will be executed once for beginValue, once for
endValue and once for each integer in between.
Both beginValue and endValue are expressions which will
be casted to integers.

- forrange(beginValue --> endValue as $var) {body} endforrange;
behaves like the previous entry, but also has $var take the
values in the range (starting as beginValue, decreasing one
each time if endValue is lower than beginValue and increasing
once each time if endValue is higher than beginValue)
$var will take the number of elements in the range after the
loop is done

0 comments on commit cdde2e3

Please sign in to comment.