Skip to content

Commit

Permalink
Stricter method:: syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
lijon committed Mar 5, 2012
1 parent 2d9a397 commit ba59e87
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion SCDoc.c
Expand Up @@ -89,7 +89,7 @@ DocNode * doc_node_make_take_children(const char *id, char *text, DocNode *src)


void doc_node_free_tree(DocNode *n) { void doc_node_free_tree(DocNode *n) {
int i; int i;
// printf("freeing %s\n",n->id); if(!n) return;
free(n->text); free(n->text);
for(i=0;i<n->n_childs;i++) { for(i=0;i<n->n_childs;i++) {
doc_node_free_tree(n->children[i]); doc_node_free_tree(n->children[i]);
Expand Down
11 changes: 9 additions & 2 deletions SCDoc.l
Expand Up @@ -20,6 +20,8 @@ int scdoc_start_token = 0;
%x eat2 %x eat2
%x eat3 %x eat3


%x method

%% %%


%{ %{
Expand Down Expand Up @@ -48,7 +50,7 @@ if (scdoc_start_token) {
(?i:[ \t]*section::[ \t]*) return SECTION; (?i:[ \t]*section::[ \t]*) return SECTION;
(?i:[ \t]*subsection::[ \t]*) return SUBSECTION; (?i:[ \t]*subsection::[ \t]*) return SUBSECTION;
(?i:[ \t]*copymethod::[ \t]*) return COPYMETHOD; (?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]*argument::[ \t]*) return ARGUMENT;


(?i:[ \t]*description::[ \t\n]*) return DESCRIPTION; (?i:[ \t]*description::[ \t\n]*) return DESCRIPTION;
Expand Down Expand Up @@ -92,7 +94,7 @@ if (scdoc_start_token) {
\n return NEWLINE; \n return NEWLINE;
\n([ \t]*\n)+ return EMPTYLINES; \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;
\\\#\# scdoclval.str = strdup("##"); return TEXT; \\\#\# scdoclval.str = strdup("##"); return TEXT;
Expand All @@ -101,6 +103,11 @@ if (scdoc_start_token) {
[ \r\t]+ scdoclval.str = strdup(" "); return TEXT; [ \r\t]+ scdoclval.str = strdup(" "); return TEXT;


[a-zA-Z]+:\/\/[^ \t\n:,]+ scdoclval.str = strdup(scdoctext); return URL; [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]+ | [a-zA-Z]+ |
<INITIAL,verbatim,verbatim2>[.!?(){}\[\]'"0-9]+ | <INITIAL,verbatim,verbatim2>[.!?(){}\[\]'"0-9]+ |
Expand Down
29 changes: 23 additions & 6 deletions SCDoc.y
Expand Up @@ -47,8 +47,9 @@ void scdocerror(const char *str);
// symbols // symbols
%token TAGSYM BARS HASHES %token TAGSYM BARS HASHES
// text and whitespace // text and whitespace
%token <str> TEXT URL COMMA %token <str> TEXT URL COMMA METHODNAME METHODARGS
%token NEWLINE EMPTYLINES %token NEWLINE EMPTYLINES
%token BAD_METHODNAME


%type <id> headtag sectiontag listtag rangetag inlinetag blocktag %type <id> headtag sectiontag listtag rangetag inlinetag blocktag
%type <str> anyword words anywordnl wordsnl anywordurl words2 nocommawords %type <str> anyword words anywordnl wordsnl anywordurl words2 nocommawords
Expand All @@ -58,13 +59,13 @@ void scdocerror(const char *str);
%type <doc_node> subsections subsection subsubsection subsubsections %type <doc_node> subsections subsection subsubsection subsubsections
%type <doc_node> optbody optargs args listbody tablebody tablecells tablerow %type <doc_node> optbody optargs args listbody tablebody tablecells tablerow
%type <doc_node> prose proseelem blockA blockB commalist %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 %token START_FULL START_PARTIAL START_METADATA


%start start %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> %destructor { printf("destructing String '%s'\n",$$); free($$); } <str>


%{ %{
Expand Down Expand Up @@ -151,16 +152,32 @@ subsubsections: subsubsections subsubsection { $$ = doc_node_add_child($1,$2); }
| body { $$ = doc_node_make_take_children("(SUBSUBSECTIONS)",NULL,$1); } | body { $$ = doc_node_make_take_children("(SUBSUBSECTIONS)",NULL,$1); }
; ;


subsubsection: METHOD commalist eol methodbody subsubsection: METHOD methnames optMETHODARGS eol methodbody
{ {
$2->id = "METHODNAMES"; $2->id = "METHODNAMES";
$$ = doc_node_make(method_type,NULL,$2); $$ = 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); } | COPYMETHOD words eol { $$ = doc_node_make("COPYMETHOD",$2,NULL); }
| PRIVATE commalist eol { $$ = doc_node_make_take_children("PRIVATE",NULL,$2); } | 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 methodbody: optbody optargs optreturns optdiscussion
{ {
$$ = doc_node_make_take_children("METHODBODY",NULL,$1); $$ = doc_node_make_take_children("METHODBODY",NULL,$1);
Expand Down Expand Up @@ -322,7 +339,7 @@ nocommawords: nocommawords TEXT { $$ = strmerge($1,$2); }
| URL | 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)); } | nocommawords { $$ = doc_node_make("(COMMALIST)",NULL,doc_node_make("STRING",$1,NULL)); }
; ;


Expand Down
2 changes: 2 additions & 0 deletions notes.txt
@@ -1,3 +1,5 @@
- check that argnames match with reality? (in renderer)

- should we deprecate class:: and just use title::? - 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? 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, we could use only title:: but add an isClass boolean to the SCDocument struct,
Expand Down
4 changes: 2 additions & 2 deletions test.schelp
Expand Up @@ -36,7 +36,7 @@ list::
## 1 ## 1
:: ::


method:: auxMethod method:: auxMethod, auxBazoo(1,2,3)
hej hej


CLASSMETHODS:: CLASSMETHODS::
Expand All @@ -58,7 +58,7 @@ blah blah...
private:: prInit, hiddenMethod private:: prInit, hiddenMethod
copymethod:: Classes/SinOsc *ar copymethod:: Classes/SinOsc *ar


method:: zoo method:: zoo, asdf
another method another method
returns:: returns::
An instance An instance
Expand Down

0 comments on commit ba59e87

Please sign in to comment.