Rich-Text Programming language

Started by
7 comments, last by yahastu 16 years, 5 months ago
I'm working on a scripting language for my Point and Click adventure game, and I have no idea if this will actually work or not but I'd quite like to come up with a language that reads a bit like a film script, so it's as easy as possible to see at a glance what's going on. One of the ideas I'm playing with (I guess vaguely inspired by Python's meaningful indentation) is the idea of writing scripts in a rich-text format, and making things like Bold text or centre-aligned text as part of the syntax of the language. Just as an example, making text bold could indicate that the text is the name of an actor, or making it centre-aligned could indicate that it's dialogue (let me stress that those are just *examples* of how it could be employed - I haven't thought out the specifics yet). Any thoughts?
Advertisement
Building a script language is not easy and if you see how many languages are already build, it's better to use some of them.

I recommend LUA, 'cause it was the one most used last time I checked, but for the purposes you're pointing I may use plane XML. Don't underestimate the power of XML, I've seen the IA of a game purely made with it xD.

Try using some free libraries, eXpat for parsing XML files is quite good...
Quote:Original post by Atridas
Building a script language is not easy and if you see how many languages are already build, it's better to use some of them.

I recommend LUA, 'cause it was the one most used last time I checked, but for the purposes you're pointing I may use plane XML. Don't underestimate the power of XML, I've seen the IA of a game purely made with it xD.

Try using some free libraries, eXpat for parsing XML files is quite good...


I realise it's ambitious, but try humouring me and running with my idea for a while....
Representing source code as plain text is very important, because it allows you to use many of the existing tools for working with it, including text editors, version control tools, preprocessors, copy-pasting from a web browser, and so on.

Of course, if your source files are plain text, but displayed by a smart editor as bold, centered, underlined, and so on depending on contextual hints (many IDEs do a subset of these, and emacs or vim get all of them right IIRC) then you get the readability boost of rich text without the compatibility problems. Then, it becomes a situation of creating a rich-text editor for a classic plain text language, more than it is about creating a rich-text language.
I agree with ToohrVyk. I think it would be possible to approximate the syntax of a movie script anyway:

[Sandra walks to Peter]
Sandra(whispering): Did you hear that?

Etc., and use syntax highlighting to further emphasize the different tokens.

Anyways, if you want to play around with syntax highlighting to see if it'll work that way, I recommend playing around with gedit's (Gnomes notepad-like tool) language definition files. I've just completed a highlighter for my own language, after about 5-8 hours of work, and the result is surprisingly good. The language definition files you produce can be used via GtkSourceView to create your own stand-alone editor with more features if you feel the need.
Your language will need to be context independent anyway if you want to stand any change of reliably parsing it. Then, you syntax will become either interchangeable with other languages, or will remain ambiguous and bug-prone.

Quote:I think it would be possible to approximate the syntax of a movie script anyway


You can write a script parser. But you may find it lacking.

Quote:[Sandra walks to Peter]
Sandra(whispering): Did you hear that?


What happens when Sandra cannot walk to Peter. Or when there are two Peters? Or where there is no Sandra? Or if Sandra gets delayed?

How will Sandra face towards Peter? Will Peter respond to Sandra? What is appropriate distance? In rural areas, inter-personal distance is roughly two arm's lengths, in urban areas, it's half arm's length. In what way does she whisper? Covering her hand with arm? Leaning over to his ear?

Scripts are left to director's interpretation, and it's director that makes movie what it is.

A computer language however will need to define everything into very last details, or leave you with ambiguous mess.

For a more productive approach, develop a regular language first, or define the API in one of existing languages. Then see if anything is to be gained from replacing syntax elements there. Languages will need to remain interchangeable, so if something cannot be done in one, it cannot be done in another.
Antheus, the example I gave is perfectly parseable, and "walks to" can be a command/method call.

action ::= "[" command "]"
command ::= walkCommand | enterCommand
walkCommand ::= name "walks" "to" name
enterCommand ::= name "enters" optionalDirection
optionalDirection ::= | ("from" | "from" "the") direction
direction ::= "west" | "east" | etc.
dialog ::= name optionalTalkMode ":" text punctuation
punctuation ::= "?" | "!"
optionalTalkMode ::= | "(" talkMode ")"
etc.

It's a scripting language, and thus depend on software for interpretation. Same goes for any programming language.

But other than that, I agree with your point. It's questionable if making a custom language will be a benefit at all to the game. It might be educational though.
I'm thinking that actually the approach of using an annotated plain-text system allows you to separate out the human-readable version of the code whilst still providing all of the necessary extra gumph that allows the computer to do useful things.

Here's just a rough example off the top of my head:

<actor>Bob</actor> <action speed="5" animation="3" final_distance="10">walks to</action> <actor>Jane</actor>

A simple IDE could easily render that in a film-script style ("BOB walks to JANE") but the parser can just as easily keep track of all of the fluff.
AnyGeers,

I think it's a good idea, and it's really not that much work if you use a parser generator. I'd say if you already knew how to use lex/yacc or spirit or javacc, you could get the job done in a couple days.

I suggest parsing plain txt instead of RTF though, because it will be a little bit easier and you won't have to clog your grammar up with all kinds of crap about text formatting...and there's no really any advantage I see to using bold/italics. After all a real screenplay does not use these things, although it does make heavy use of whitespace.

[Edited by - yahastu on November 24, 2007 5:59:40 PM]

This topic is closed to new replies.

Advertisement