summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-10-04 16:23:19 -0400
committerAdrian Thurston <thurston@complang.org>2015-10-04 16:23:19 -0400
commit6fb0cdffbafb135edaec7d927e5e508997c1d826 (patch)
tree878b580f8c8cdd4ae4dc1ea942b14c8f17940fc0
parent514d1771d7956df29ea8e9f0c5f0a35d47bc8bc4 (diff)
downloadragel-6fb0cdffbafb135edaec7d927e5e508997c1d826.tar.gz
sketched a grammar for reduction sections
-rw-r--r--colm.vim6
-rw-r--r--src/colm.lm48
-rw-r--r--src/consinit.cc16
-rw-r--r--src/loadinit.cc7
4 files changed, 68 insertions, 9 deletions
diff --git a/colm.vim b/colm.vim
index 3a5f1a5d..562fb2f7 100644
--- a/colm.vim
+++ b/colm.vim
@@ -59,15 +59,15 @@ syntax keyword Type
\ namespace lex reducefirst global include export
\ construct cons parse parse_tree parse_stop match require send send_tree
\ preeof left right nonassoc prec context struct alias
- \ end eos print
+ \ end eos print reduction nonterm
syntax keyword typeKeywords
- \ int str bool any ref ptr void
+ \ int str bool any ref ptr void list_el map_el
syntax keyword Keyword
\ reject else elsif return yield for while if
\ typeid in break
- \ new new2 deref ni cast switch case default
+ \ new deref ni cast switch case default
syntax match tokenName "[a-zA-Z_][a-zA-Z_0-9]*" contained
syntax match varCapture "[a-zA-Z_][a-zA-Z_0-9]*:"
diff --git a/src/colm.lm b/src/colm.lm
index 85c86f73..a5f15b9c 100644
--- a/src/colm.lm
+++ b/src/colm.lm
@@ -19,6 +19,7 @@ lex
token SEND / 'send' /
token SEND_TREE / 'send_tree' /
token NAMESPACE / 'namespace' /
+ token REDUCTION / 'reduction' /
token FOR / 'for' /
token IF / 'if' /
token YIELD / 'yield' /
@@ -221,6 +222,7 @@ def root_item
| [precedence_def] :Precedence commit
| [alias_def] :Alias commit
| [include] :Include commit
+| [reduction_def] :Reduction commit
def include
[INCLUDE SQ SqConsDataList: sq_cons_data* sq_lit_term]
@@ -331,6 +333,52 @@ def no_ignore_right
[MINUS NI] :Ni
| []
+def reduction_def
+ [REDUCTION id ItemList: reduction_item* END]
+
+lex
+ token ROPEN / '{' /
+ token RCLOSE / '}' /
+
+ token red_id /
+ ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) .
+ ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' ) *
+ /
+
+ token red_comment /
+ '//' . ( ^'\n' )* . '\n' |
+ '/*' . any* :> '*/'
+ /
+
+ token red_ws /
+ ( '\n' | '\t' | ' ' )+
+ /
+
+ token red_lit /
+ '\'' . ( ^( '\'' | '\\' ) | '\\' . any )* . ( '\'' | '\'i' ) |
+ '\"' . ( ^( '\"' | '\\' ) | '\\' . any )* . ( '\"' | '\"i' )
+ /
+
+ token red_any / any /
+end
+
+def red_nonterm
+ [id ROPEN host_item* RCLOSE]
+
+def red_action
+ [id COLON id ROPEN host_item* RCLOSE]
+
+def host_item
+ [red_id]
+| [red_lit]
+| [red_comment]
+| [red_ws]
+| [red_any]
+
+def reduction_item
+ [red_nonterm] commit
+| [red_action] commit
+
def namespace_def
[NAMESPACE id ItemList: namespace_item* END]
diff --git a/src/consinit.cc b/src/consinit.cc
index 794c07ae..0ef8aee2 100644
--- a/src/consinit.cc
+++ b/src/consinit.cc
@@ -554,14 +554,19 @@ void ConsInit::lexFactorRep()
void ConsInit::lexTerm()
{
ProdEl *prodEl1 = prodRefName( "Term", "lex_term" );
- ProdEl *prodEl2 = prodRefLit( "'.'" );
+ ProdEl *prodEl2 = prodRefName( "Dot", "DOT" );
ProdEl *prodEl3 = prodRefName( "FactorRep", "lex_factor_rep" );
Production *prod1 = production( prodEl1, prodEl2, prodEl3 );
+
+ ProdEl *prodEl4 = prodRefName( "Term", "lex_term" );
+ ProdEl *prodEl5 = prodRefName( "ColonLt", "COLON_LT" );
+ ProdEl *prodEl6 = prodRefName( "FactorRep", "lex_factor_rep" );
+ Production *prod2 = production( prodEl4, prodEl5, prodEl6 );
- ProdEl *prodEl4 = prodRefName( "FactorRep", "lex_factor_rep" );
- Production *prod2 = production( prodEl4 );
+ ProdEl *prodEl7 = prodRefName( "FactorRep", "lex_factor_rep" );
+ Production *prod3 = production( prodEl7 );
- definition( "lex_term", prod1, prod2 );
+ definition( "lex_term", prod1, prod2, prod3 );
}
void ConsInit::lexExpr()
@@ -858,7 +863,8 @@ void ConsInit::go( long activeRealm )
keyword( "'|'" );
keyword( "'/'" );
keyword( "':'" );
- keyword( "'.'" );
+ keyword( "DOT", "'.'" );
+ keyword( "COLON_LT", "':>'" );
keyword( "'('" );
keyword( "')'" );
keyword( "'..'" );
diff --git a/src/loadinit.cc b/src/loadinit.cc
index f14ea174..e6117d6a 100644
--- a/src/loadinit.cc
+++ b/src/loadinit.cc
@@ -180,7 +180,12 @@ LexTerm *LoadInit::walkLexTerm( lex_term &lexTerm )
lex_factor_rep LexFactorRepTree = lexTerm.FactorRep();
LexFactorAug *factorAug = walkLexFactorAug( LexFactorRepTree );
- LexTerm *term = LexTerm::cons( leftTerm, factorAug, LexTerm::ConcatType );
+
+ LexTerm::Type type = lexTerm.Dot() != 0 ?
+ LexTerm::ConcatType : LexTerm::RightFinishType;
+
+ LexTerm *term = LexTerm::cons( leftTerm, factorAug, type );
+
return term;
}
else {