Skip to content
Browse files

Stricter method:: syntax

  • Loading branch information...
1 parent 2d9a397 commit ba59e87e12d0a713951dccbe193662eee24f8268 @lijon committed Mar 5, 2012
Showing with 37 additions and 11 deletions.
  1. +1 −1 SCDoc.c
  2. +9 −2 SCDoc.l
  3. +23 −6 SCDoc.y
  4. +2 −0 notes.txt
  5. +2 −2 test.schelp
View
2 SCDoc.c
@@ -89,7 +89,7 @@ DocNode * doc_node_make_take_children(const char *id, char *text, DocNode *src)
void doc_node_free_tree(DocNode *n) {
int i;
-// printf("freeing %s\n",n->id);
+ if(!n) return;
free(n->text);
for(i=0;i<n->n_childs;i++) {
doc_node_free_tree(n->children[i]);
View
11 SCDoc.l
@@ -20,6 +20,8 @@ int scdoc_start_token = 0;
%x eat2
%x eat3
+%x method
+
%%
%{
@@ -48,7 +50,7 @@ if (scdoc_start_token) {
(?i:[ \t]*section::[ \t]*) return SECTION;
(?i:[ \t]*subsection::[ \t]*) return SUBSECTION;
(?i:[ \t]*copymethod::[ \t]*) return COPYMETHOD;
-(?i:[ \t]*method::[ \t]*) return METHOD;
+(?i:[ \t]*method::[ \t]*) BEGIN(method); return METHOD;
(?i:[ \t]*argument::[ \t]*) return ARGUMENT;
(?i:[ \t]*description::[ \t\n]*) return DESCRIPTION;
@@ -92,7 +94,7 @@ if (scdoc_start_token) {
\n return NEWLINE;
\n([ \t]*\n)+ return EMPTYLINES;
-[ \t]*,[ \t]* scdoclval.str = strdup(scdoctext); return COMMA;
+<INITIAL,method>[ \t]*,[ \t]* scdoclval.str = strdup(scdoctext); return COMMA;
\\\|\| scdoclval.str = strdup("||"); return TEXT;
\\\#\# scdoclval.str = strdup("##"); return TEXT;
@@ -101,6 +103,11 @@ if (scdoc_start_token) {
[ \r\t]+ scdoclval.str = strdup(" "); return TEXT;
[a-zA-Z]+:\/\/[^ \t\n:,]+ scdoclval.str = strdup(scdoctext); return URL;
+<method>[a-z][a-zA-Z0-9_]*|[-<>@|&%*+/!?=]+ scdoclval.str = strdup(scdoctext); return METHODNAME;
+<method>\([^()]+\) scdoclval.str = strdup(scdoctext); return METHODARGS;
+<method>[ \r\t]+ /* eat this */
+<method>\n BEGIN(INITIAL); return NEWLINE;
+<method>. return BAD_METHODNAME;
[a-zA-Z]+ |
<INITIAL,verbatim,verbatim2>[.!?(){}\[\]'"0-9]+ |
View
29 SCDoc.y
@@ -47,8 +47,9 @@ void scdocerror(const char *str);
// symbols
%token TAGSYM BARS HASHES
// text and whitespace
-%token <str> TEXT URL COMMA
+%token <str> TEXT URL COMMA METHODNAME METHODARGS
%token NEWLINE EMPTYLINES
+%token BAD_METHODNAME
%type <id> headtag sectiontag listtag rangetag inlinetag blocktag
%type <str> anyword words anywordnl wordsnl anywordurl words2 nocommawords
@@ -58,13 +59,13 @@ void scdocerror(const char *str);
%type <doc_node> subsections subsection subsubsection subsubsections
%type <doc_node> optbody optargs args listbody tablebody tablecells tablerow
%type <doc_node> prose proseelem blockA blockB commalist
-%type <doc_node> deflistbody deflistrow defterms
+%type <doc_node> deflistbody deflistrow defterms methnames optMETHODARGS
%token START_FULL START_PARTIAL START_METADATA
%start start
-%destructor { printf("destructing DocNode %s\n",$$->id); doc_node_free_tree($$); } <doc_node>
+%destructor { printf("destructing DocNode %s\n",$$?$$->id:NULL); doc_node_free_tree($$); } <doc_node>
%destructor { printf("destructing String '%s'\n",$$); free($$); } <str>
%{
@@ -151,16 +152,32 @@ subsubsections: subsubsections subsubsection { $$ = doc_node_add_child($1,$2); }
| body { $$ = doc_node_make_take_children("(SUBSUBSECTIONS)",NULL,$1); }
;
-subsubsection: METHOD commalist eol methodbody
+subsubsection: METHOD methnames optMETHODARGS eol methodbody
{
$2->id = "METHODNAMES";
$$ = doc_node_make(method_type,NULL,$2);
- doc_node_add_child($$, $4);
+ doc_node_add_child($$, $5);
+ doc_node_add_child($2, $3);
}
| COPYMETHOD words eol { $$ = doc_node_make("COPYMETHOD",$2,NULL); }
| PRIVATE commalist eol { $$ = doc_node_make_take_children("PRIVATE",NULL,$2); }
;
+optMETHODARGS: { $$ = NULL; }
+ | METHODARGS
+ {
+ $$ = doc_node_make("ARGSTRING",$1,NULL);
+ if(method_type!="METHOD") {
+ yyerror("METHOD argument string is not allowed inside CLASSMETHODS or INSTANCEMETHODS");
+ YYERROR;
+ }
+ }
+;
+
+methnames: methnames COMMA METHODNAME { free($2); $2 = NULL; $$ = doc_node_add_child($1, doc_node_make("STRING",$3,NULL)); }
+ | METHODNAME { $$ = doc_node_make("(METHODNAMES)",NULL,doc_node_make("STRING",$1,NULL)); }
+;
+
methodbody: optbody optargs optreturns optdiscussion
{
$$ = doc_node_make_take_children("METHODBODY",NULL,$1);
@@ -322,7 +339,7 @@ nocommawords: nocommawords TEXT { $$ = strmerge($1,$2); }
| URL
;
-commalist: commalist COMMA nocommawords { free($2); $$ = doc_node_add_child($1,doc_node_make("STRING",$3,NULL)); }
+commalist: commalist COMMA nocommawords { free($2); $2=NULL; $$ = doc_node_add_child($1,doc_node_make("STRING",$3,NULL)); }
| nocommawords { $$ = doc_node_make("(COMMALIST)",NULL,doc_node_make("STRING",$1,NULL)); }
;
View
2 notes.txt
@@ -1,3 +1,5 @@
+- check that argnames match with reality? (in renderer)
+
- should we deprecate class:: and just use title::?
or do we need a way to mark the actual doc that it's a class ref and not a normal doc?
we could use only title:: but add an isClass boolean to the SCDocument struct,
View
4 test.schelp
@@ -36,7 +36,7 @@ list::
## 1
::
-method:: auxMethod
+method:: auxMethod, auxBazoo(1,2,3)
hej
CLASSMETHODS::
@@ -58,7 +58,7 @@ blah blah...
private:: prInit, hiddenMethod
copymethod:: Classes/SinOsc *ar
-method:: zoo
+method:: zoo, asdf
another method
returns::
An instance

0 comments on commit ba59e87

Please sign in to comment.
Something went wrong with that request. Please try again.