-
Notifications
You must be signed in to change notification settings - Fork 6
Declarative Programming
Shane Brinkman-Davis Delamore edited this page Mar 29, 2018
·
26 revisions
Related: Functional Oriented Programming, React-style programming
A program that describes what computation should be performed, not how to compute it.
Facebook's React and Imikimi's ArtReact are examples of declarative style programming.
Declarative programming in an imperative language like JavaScript typically takes the form of embedded DSLs. CaffeineEight is a DSL for writing parsers. Below is an example of a complete Json parser using CaffeineEight, written in CaffeineScript.
class JsonParser extends &CaffeineEight.Parser
@rule
root: :array :object
array:
"" '[' _? ']'
"" '[' _? value commaValue* _? ']'
object:
"" '{' _? '}'
"" '{' _? pair commaPair* _? '}'
commaValue: "" _? ',' _? value
commaPair: "" _? ',' _? pair
pair: "" string _? ':' _? value
value: :object :array :number :string :true :false :null
string: /"(?:[^"\\]|\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4}))*"/
number: /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/
true: /true/
false: /false/
null: /null/
_: /\ +/
- Class Definition which allows method invocation as well as declaration
- Blocks Instead of Brackets
- Expressive Literals
- Home
- Get Started
- Benefits
- Highlights
- Productivity by Design
- CaffeineScript Design
- What is CaffeineScript Good For?
- Get the most out of JavaScript
- Language Comparison
- CHANGELOG
- Blocks Instead of Brackets
- Binary Line-Starts
- Everything Returns a Value
- Streamlined Modules
- Scopes and Variables
- Optional Commas
- Semantics
- Ambiguities