From b781e6a473ea680fe982bd0c3aaa184ec78216ff Mon Sep 17 00:00:00 2001 From: Ingy dot Net Date: Sat, 20 Mar 2010 23:48:44 -0700 Subject: [PATCH] stuff --- doc/index.asc | 9 ++ doc/spec.asc | 4 + src/Makefile | 6 + src/cd/grammar.yaml | 44 ++++++++ src/pm/grammar.yaml | 207 +++++++++++++++++++++++++++++++++++ src/py/grammar.yaml | 16 +++ src/py/lib/cdent/__init__.py | 0 src/py/lib/cdent/runtime.py | 0 8 files changed, 286 insertions(+) create mode 100644 doc/index.asc create mode 100644 doc/spec.asc create mode 100644 src/Makefile create mode 100644 src/cd/grammar.yaml create mode 100644 src/pm/grammar.yaml create mode 100644 src/py/grammar.yaml create mode 100644 src/py/lib/cdent/__init__.py create mode 100644 src/py/lib/cdent/runtime.py diff --git a/doc/index.asc b/doc/index.asc new file mode 100644 index 0000000..0141f7e --- /dev/null +++ b/doc/index.asc @@ -0,0 +1,9 @@ += C'Dent + +C'Dent is a programming methodology for writing code in one programming language and creating equivalent code in other programming langauges. + + +The primary focus of C'Dent is to: + +1) Define the structure of a programming language agnostic, object oriented module that can be used to create faithful representations in many backend languages. +2) Define "C'Dent subsets" of several popular diff --git a/doc/spec.asc b/doc/spec.asc new file mode 100644 index 0000000..26936cd --- /dev/null +++ b/doc/spec.asc @@ -0,0 +1,4 @@ += C'Dent Object-Oriented-Module Model Specification + +== Introduction + diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..97da923 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,6 @@ + +../lib/cdent/parser/cdent/grammar.py: cd/grammar.yaml + bin/grammar-module $< $@ + +../lib/cdent/parser/python/grammar.py: py/grammar.yaml + bin/grammar-module $< $@ diff --git a/src/cd/grammar.yaml b/src/cd/grammar.yaml new file mode 100644 index 0000000..6b16ca9 --- /dev/null +++ b/src/cd/grammar.yaml @@ -0,0 +1,44 @@ +--- +# RegExp atoms +ALL: '[\s\S]' # Any unicode character +WS: '[\ \t]' # A space or tab character +BR: '\n' # A newline character +EOL: '\r?\n' # A Unix or DOS line ending +ANY: '.' # Any character except newline +LC: '[a-z]' # Lower case ASCII alphabetic character +UC: '[A-Z]' # Upper case ASCII alphabetic character +AN: '[A-Za-z0-9]' # ASCII alphanumeric character +WC: '\w' # ie '[A-Za-z0-9_]' - A "word" character +NUM: '[0-9]' # A numeric digit +DS: '\$' # A dollar sign +DOT: '\.' # A period character +OCT: '#' # An octothorpe (or hash) character +BS: '\\' # A backslash character +SQ: "'" # A single quote character +DB: '"' # A double quote character + +Line: /$CHAR*$EOL/ +BlankLine: /$WS*$EOL/ + +# Module parsing grammar +Module: +- DocComment +- Comment* +- IncludeCDent +- Comment* +- Class +- (Class|Comment)* +- Ending +- Comments* + +DocComment: +- DocCommentBegin +- DocCommentLine* +- DocCommentEnd + +Comment: (LineComment|BlankLine) + +Ending: // + +LineComment: /$line_comment_start($Line)/ + diff --git a/src/pm/grammar.yaml b/src/pm/grammar.yaml new file mode 100644 index 0000000..300b519 --- /dev/null +++ b/src/pm/grammar.yaml @@ -0,0 +1,207 @@ +--- +ANY: '[\s\S]' # Any unicode character +SPACE: '[\ \t]' # A space or tab character +SPACES: '\ \t' # For use in character classes +BREAK: '\n' # A newline character +EOL: '\r?\n' # A Unix or DOS line ending +NON_BREAK: '.' # Any character except newline +LOWER: '[a-z]' # Lower case ASCII alphabetic character +UPPER: '[A-Z]' # Upper case ASCII alphabetic character +ALPHANUM: '[A-Za-z0-9]' # ASCII alphanumeric character +WORD: '\w' # ie '[A-Za-z0-9_]' - A "word" character +DIGIT: '[0-9]' # A numeric digit +DOLLAR: '\$' # A dollar sign +DOT: '\.' # A period character +HASH: '#' # An octothorpe (or hash) character +BACK: '\' # A backslash character +SINGLE: "'" # A single quote character +DOUBLE: '"' # A double quote character +ESCAPE: '[0nt]' # One of the escapable character IDs + +document: +- meta_section +- test_section +- /: + - data_section + ^: '?' + +meta_section: +- /(?:$comment|$blank_line)*/ +- /: + - meta_testml_statement + - _: No TestML meta directive found +- /: + - meta_statement + - comment + - blank_line + ^: '*' + +comment: /$HASH$line/ +line: /$NON_BREAK*$EOL/ +blank_line: /$SPACE*$EOL/ + +meta_testml_statement: /%TestML:$SPACE+($testml_version)(?:$SPACE+$comment|$EOL)/ + +testml_version: /($DIGIT$DOT$DIGIT+)/ + +meta_statement: /%($meta_keyword):$SPACE+($meta_value)(?:$SPACE+$comment|$EOL)/ + +meta_keyword: /(?:$core_meta_keyword|$user_meta_keyword)/ +core_meta_keyword: /(?:Title|Data|Plan|BlockMarker|PointMarker)/ +user_meta_keyword: /$LOWER$WORD*/ + +meta_value: /(?:$single_quoted_string|$double_quoted_string|$unquoted_string)/ + +single_quoted_string: /(?:$SINGLE(([^$BREAK$BACK$SINGLE]|$BACK$SINGLE|$BACK$BACK)*?)$SINGLE)/ + +double_quoted_string: /(?:$DOUBLE(([^$BREAK$BACK$DOUBLE]|$BACK$DOUBLE|$BACK$BACK|$BACK$ESCAPE)*?)$DOUBLE)/ + +unquoted_string: /[^$SPACES$BREAK$HASH](?:[^$BREAK$HASH]*[^$SPACES$BREAK$HASH])?/ + +test_section: +- /: + - ws + - test_statement + ^: '*' + +ws: /(?:$SPACE|$EOL|$comment)/ + +test_statement: +- test_expression +- =: assertion_expression + ^: '?' +- /: + - /;/ + - _: You seem to be missing a semicolon + +test_expression: +- sub_expression +- /: + - - '!assertion_call_start' + - call_indicator + - sub_expression + ^: '*' + +sub_expression: +- /: + - transform_call + - data_point + - quoted_string + - constant + +transform_call: +- transform_name +- /\($ws*/ +- argument_list +- /$ws*\)/ + +transform_name: + /: + - user_transform + - core_transform + +user_transform: /($LOWER$WORD*)/ + +core_transform: /($UPPER$WORD*)/ + +call_indicator: /(?:$DOT$ws*|$ws*$DOT)/ + +data_point: /($DOLLAR$LOWER$WORD*)/ + +constant: /($UPPER$WORD*)/ + +argument_list: + =: + - argument + - =: + - /$ws*,$ws*/ + - argument + ^: '*' + ^: '?' + +argument: +- sub_expression + +quoted_string: + /: + - single_quoted_string + - double_quoted_string + +assertion_expression: + /: + - assertion_operation + - assertion_call + +assertion_operation: +- /$ws+/ +- assertion_operator +- /$ws+/ +- test_expression + +assertion_operator: /(==)/ + +assertion_call: +- assertion_call_start +- test_expression +- /$ws*\)/ + +assertion_call_start: +- /$call_indicator$assertion_name\($ws*/ + +assertion_name: /EQ/ + +data_section: /($block_marker(?:$SPACE|$EOL)$ANY+|\Z)/ + +data: + =: data_block + ^: '*' + +data_block: +- block_header +- /: + - blank_line + - comment + ^: '*' +- =: block_point + ^: '*' + +block_header: +- block_marker +- =: + - /$SPACE+/ + - block_label + ^: '?' +- /$SPACE*$EOL/ + +block_marker: /===/ + +block_label: +- /([^$SPACES$BREAK]($NON_BREAK*[^SPACES$BREAK])?)/ + +block_point: + /: + - lines_point + - phrase_point + +lines_point: +- /$point_marker$SPACE+/ +- user_point_name +- /$SPACE*$EOL/ +- point_lines + +user_point_name: /($LOWER$WORD*)/ + +point_lines: /((?:(?!$block_marker|$point_marker)$line)*)/ + +phrase_point: +- /$point_marker$SPACE+/ +- user_point_name +- /:$SPACE/ +- point_phrase +- /$EOL/ +- /(?:$comment|$blank_line)*/ + +point_phrase: /($NON_BREAK*)/ + + +point_marker: /---/ diff --git a/src/py/grammar.yaml b/src/py/grammar.yaml new file mode 100644 index 0000000..8151e12 --- /dev/null +++ b/src/py/grammar.yaml @@ -0,0 +1,16 @@ +line_comment_start: '#' + +TQ: '""""' # Python triple quote + +DocCommentBegin: /$TQ$BS$WS*$EOL/ +DocCommentLine: /($ANY*$EOL)/ +DocCommentEnd: /$TQ$WS*$EOL/ + +IncludeCDent: /from cdent import */ + +Class: +- ClassSignatureLine +- ClassBody + +ClassSignatureLine: /class$WS+$Id$OP$Id?$CP$CN$EOL/ + diff --git a/src/py/lib/cdent/__init__.py b/src/py/lib/cdent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/py/lib/cdent/runtime.py b/src/py/lib/cdent/runtime.py new file mode 100644 index 0000000..e69de29