[TYPO3-50-general] TypoScript 2.0 EBNF

Robert Lemke robert at typo3.org
Tue May 29 19:28:18 CEST 2007


Hi folks,

this morning I wrote a lengthy mail in response to the TS 2.0 thread,  
but it somehow disappeared. I'll write it again but it could be that  
it's tomorrow until I find the motivation to write everything again ...

Anyway, today I spent more thoughts about the TS 2.0 syntax and  
parsing. I though that it would be a good idea to write down the  
syntax definition of TypoScript, which should make it much easier to  
write the actual lexer / parser. Although I have no experience with  
that, I tried to write down the definition in the EBNF notation. If  
anyone of you knows that better or finds errors in my definition,  
please let me know.

So here is my draft, up for discussion an improvement:

------------------------------------------------------------------------ 
-------------

TypoScript = { TypoScriptLine LineBreak };
TypoScriptLine = { { Whitespace } ( ConfinementBlock | Declaration |  
ParseCondition | Comment | ObjectDefinition) { Whitespace } };

ConfinementBlock = ObjectPath { Whitespace } "{" { Whitespace }  
LineBreak { TypoScriptLine } { WhiteSpace } "}" ;

Declaration = ( IncludeDeclaration | NamespaceDeclaration );
Comment = ( SingleLineComment | BlockComment );
ObjectDefinition = ObjectPath { Whitespace } ValueOperation;

IncludeDeclaration = "include" {Whitespace} ":" "source" {Whitespace}  
"=" {Whitespace} DoubleQuote Resource DoubleQuote;
NamespaceDeclaration = "namespace" { Whitespace } ":"  
NamespaceIdentifier { Whitespace } "=" ComponentName;

SingleLineComment = ( "#" | "//" ) { UnicodeCharacter };
BlockComment = "/*" { UnicodeCharacter} { LineBreak } "*/";

ObjectPath = { "." } ObjectIdentifier { "." ObjectIdentifier } [ "."  
VariableName ];
VariableName = "$" Identifier;

ValueOperation = ( ValueAssignment | ValueCopy | ValueReference |  
ValueUnset );
ValueAssignment = "=" { Whitespace } ( Literal | ObjectType |  
Constant );
ValueCopy = "<" { Whitespace } ObjectPath;
ValueReference = "=<" { Whitespace } ObjectPath;
ValueUnset = ">";

Literal = DoubleQuotedLiteral | SingleQuotedLiteral;
DoubleQuotedLiteral = DoubleQuote EscapedUnicodeCharacter DoubleQuote;
SingleQuotedLiteral = SingleQuote EscapedUnicodeCharacter SingleQuote;

ObjectType = ( NamespaceIdentifier { Whitespace} ":" { Whitespace }  
Identifier ) | ComponentName;

Constant = (* ... to be defined *);

ParseCondition = (* ... to be defined *);

NamespaceIdentifier = Identifier;
ObjectIdentifier = Identifier;
Identifier = Character { CharacterOrDigit };
ComponentName = Character { "_" CharacterOrDigit } { CharacterOrDigit };

CharacterOrDigit = Character | Digit;
UnicodeCharacter = ? All Unicode characters, except line break ?;
EscapedUnicodeCharacter = ? All Unicode characters, except line  
break. Double quote must be escaped when enclosed in double quotes,  
single quote must be escaped, when enclosed in single quotes,  
backslash must be always escaped. Escape character is the backslash ?;
UpperCaseCharacter = ? Character, but only upper case ?
Character = ? All lower- and uppercase characters between "a" and "z" ?
Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
WhiteSpace = " " | Tab;
LineBreak = ? A UNIX linebreak chr(10) ?;
DoubleQuote = ? The double quote " ?;
SingleQuote = ? The single quote ' ?;


-- 
robert



More information about the TYPO3-project-5_0-general mailing list