summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-05-25 11:05:24 -0400
committerAdrian Thurston <thurston@complang.org>2013-05-25 11:05:24 -0400
commit7bdaf9ff9d73abae7032cbab8d0e1f9c8f8a908d (patch)
tree329a77627cb79a7f7597e3f35c9ad5228fb5f979
parent353fa84e4cb1848b04ce1a5e3fd3ad3a55a860eb (diff)
downloadcolm-7bdaf9ff9d73abae7032cbab8d0e1f9c8f8a908d.tar.gz
more conversion to prod name switches in the loader
-rw-r--r--colm/colm.lm28
-rw-r--r--colm/loadcolm.cc105
2 files changed, 75 insertions, 58 deletions
diff --git a/colm/colm.lm b/colm/colm.lm
index e925c597..a4823501 100644
--- a/colm/colm.lm
+++ b/colm/colm.lm
@@ -685,8 +685,8 @@ def lex_factor_neg
| [Factor: lex_factor] :Base
def lex_range_lit
- [Lit: lex_lit]
-| [Number: lex_num]
+ [Lit: lex_lit] :Lit
+| [Number: lex_num] :Number
def lex_num
[lex_uint]
@@ -695,19 +695,19 @@ def lex_num
#| [LEX_DASH num]
def lex_factor
- [Literal: lex_lit]
-| [Id: lex_id]
-| [Number: lex_uint]
-| [Hex: lex_hex]
-| [LEX_POPEN Expr: lex_expr LEX_PCLOSE]
-| [Low: lex_range_lit LEX_DOTDOT High: lex_range_lit]
-| [LEX_SQOPEN_POS PosData: reg_or_data RE_SQCLOSE]
-| [LEX_SQOPEN_NEG NegData: reg_or_data RE_SQCLOSE]
+ [Literal: lex_lit] :Literal
+| [Id: lex_id] :Id
+| [Number: lex_uint] :Number
+| [Hex: lex_hex] :Hex
+| [Low: lex_range_lit LEX_DOTDOT High: lex_range_lit] :Range
+| [LEX_SQOPEN_POS PosData: reg_or_data RE_SQCLOSE] :PosOrBlock
+| [LEX_SQOPEN_NEG NegData: reg_or_data RE_SQCLOSE] :NegOrBlock
+| [LEX_POPEN Expr: lex_expr LEX_PCLOSE] :Paren
def reg_or_data
- [Data: reg_or_data Char: reg_or_char]
-| []
+ [Data: reg_or_data Char: reg_or_char] :Data
+| [] :Base
def reg_or_char
- [Char: RE_CHAR]
-| [Low: RE_CHAR RE_DASH High: RE_CHAR]
+ [Char: RE_CHAR] :Char
+| [Low: RE_CHAR RE_DASH High: RE_CHAR] :Range
diff --git a/colm/loadcolm.cc b/colm/loadcolm.cc
index 68727e25..065f3838 100644
--- a/colm/loadcolm.cc
+++ b/colm/loadcolm.cc
@@ -95,61 +95,73 @@ struct LoadColm
Literal *walkLexRangeLit( lex_range_lit lexRangeLit )
{
Literal *literal = 0;
- if ( lexRangeLit.Lit() != 0 ) {
+ switch ( lexRangeLit.prodName() ) {
+ case lex_range_lit::_Lit: {
String lit = lexRangeLit.Lit().text().c_str();
literal = Literal::cons( lexRangeLit.Lit().loc(), lit, Literal::LitString );
+ break;
}
- else if ( lexRangeLit.Number() != 0 ) {
+ case lex_range_lit::_Number: {
String num = lexRangeLit.Number().text().c_str();
literal = Literal::cons( lexRangeLit.Number().loc(), num, Literal::Number );
- }
+ break;
+ }}
return literal;
}
- LexFactor *walkLexFactor( lex_factor LexFactorTree )
+ LexFactor *walkLexFactor( lex_factor lexFactor )
{
LexFactor *factor = 0;
- if ( LexFactorTree.Literal() != 0 ) {
- String litString = LexFactorTree.Literal().text().c_str();
- Literal *literal = Literal::cons( LexFactorTree.Literal().loc(),
+ switch ( lexFactor.prodName() ) {
+ case lex_factor::_Literal: {
+ String litString = lexFactor.Literal().text().c_str();
+ Literal *literal = Literal::cons( lexFactor.Literal().loc(),
litString, Literal::LitString );
factor = LexFactor::cons( literal );
+ break;
}
- else if ( LexFactorTree.Id() != 0 ) {
- String id = LexFactorTree.Id().text().c_str();
- factor = lexRlFactorName( id, LexFactorTree.Id().loc() );
- }
- else if ( LexFactorTree.Expr() != 0 ) {
- lex_expr LexExpr = LexFactorTree.Expr();
- LexExpression *expr = walkLexExpr( LexExpr );
- LexJoin *join = LexJoin::cons( expr );
- factor = LexFactor::cons( join );
+ case lex_factor::_Id: {
+ String id = lexFactor.Id().text().c_str();
+ factor = lexRlFactorName( id, lexFactor.Id().loc() );
+ break;
}
- else if ( LexFactorTree.Low() != 0 ) {
- Literal *low = walkLexRangeLit( LexFactorTree.Low() );
- Literal *high = walkLexRangeLit( LexFactorTree.High() );
+ case lex_factor::_Range: {
+ Literal *low = walkLexRangeLit( lexFactor.Low() );
+ Literal *high = walkLexRangeLit( lexFactor.High() );
Range *range = Range::cons( low, high );
factor = LexFactor::cons( range );
+ break;
}
- else if ( LexFactorTree.PosData() != 0 ) {
- ReOrBlock *block = walkRegOrData( LexFactorTree.PosData() );
+ case lex_factor::_PosOrBlock: {
+ ReOrBlock *block = walkRegOrData( lexFactor.PosData() );
factor = LexFactor::cons( ReItem::cons( block, ReItem::OrBlock ) );
+ break;
}
- else if ( LexFactorTree.NegData() != 0 ) {
- ReOrBlock *block = walkRegOrData( LexFactorTree.NegData() );
+ case lex_factor::_NegOrBlock: {
+ ReOrBlock *block = walkRegOrData( lexFactor.NegData() );
factor = LexFactor::cons( ReItem::cons( block, ReItem::NegOrBlock ) );
+ break;
}
- else if ( LexFactorTree.Number() != 0 ) {
- String number = LexFactorTree.Number().text().c_str();
- factor = LexFactor::cons( Literal::cons( LexFactorTree.Number().loc(),
+ case lex_factor::_Number: {
+ String number = lexFactor.Number().text().c_str();
+ factor = LexFactor::cons( Literal::cons( lexFactor.Number().loc(),
number, Literal::Number ) );
+ break;
}
- else if ( LexFactorTree.Hex() != 0 ) {
- String number = LexFactorTree.Hex().text().c_str();
- factor = LexFactor::cons( Literal::cons( LexFactorTree.Hex().loc(),
+ case lex_factor::_Hex: {
+ String number = lexFactor.Hex().text().c_str();
+ factor = LexFactor::cons( Literal::cons( lexFactor.Hex().loc(),
number, Literal::Number ) );
+ break;
}
+ case lex_factor::_Paren: {
+ lex_expr LexExpr = lexFactor.Expr();
+ LexExpression *expr = walkLexExpr( LexExpr );
+ LexJoin *join = LexJoin::cons( expr );
+ factor = LexFactor::cons( join );
+ break;
+ }}
return factor;
}
@@ -789,47 +801,53 @@ struct LoadColm
ReOrItem *walkRegOrChar( reg_or_char regOrChar )
{
ReOrItem *orItem = 0;
- if ( regOrChar.Char() != 0 ) {
+ switch ( regOrChar.prodName() ) {
+ case reg_or_char::_Char: {
String c = unescape( regOrChar.Char().text().c_str() );
orItem = ReOrItem::cons( regOrChar.Char().loc(), c );
+ break;
}
- else {
+ case reg_or_char::_Range: {
String low = unescape( regOrChar.Low().text().c_str() );
String high = unescape( regOrChar.High().text().c_str() );
orItem = ReOrItem::cons( regOrChar.Low().loc(), low[0], high[0] );
- }
+ break;
+ }}
return orItem;
}
ReOrBlock *walkRegOrData( reg_or_data regOrData )
{
ReOrBlock *block = 0;
- if ( regOrData.Data() != 0 ) {
+ switch ( regOrData.prodName() ) {
+ case reg_or_data::_Data: {
ReOrBlock *left = walkRegOrData( regOrData.Data() );
ReOrItem *right = walkRegOrChar( regOrData.Char() );
block = lexRegularExprData( left, right );
+ break;
}
- else {
+ case reg_or_data::_Base: {
block = ReOrBlock::cons();
- }
+ break;
+ }}
return block;
}
-
LexFactorNeg *walkLexFactorNeg( lex_factor_neg lexFactorNeg )
{
+ LexFactorNeg *factorNeg = 0;
switch ( lexFactorNeg.prodName() ) {
case lex_factor_neg::_Caret: {
LexFactorNeg *recNeg = walkLexFactorNeg( lexFactorNeg.FactorNeg() );
- LexFactorNeg *factorNeg = LexFactorNeg::cons( recNeg,
- LexFactorNeg::CharNegateType );
- return factorNeg;
+ factorNeg = LexFactorNeg::cons( recNeg, LexFactorNeg::CharNegateType );
+ break;
}
case lex_factor_neg::_Base: {
LexFactor *factor = walkLexFactor( lexFactorNeg.Factor() );
- LexFactorNeg *factorNeg = LexFactorNeg::cons( factor );
- return factorNeg;
+ factorNeg = LexFactorNeg::cons( factor );
+ break;
}}
+ return factorNeg;
}
LexFactorRep *walkLexFactorRep( lex_factor_rep lexFactorRep )
@@ -1798,7 +1816,7 @@ struct LoadColm
namespaceStack.pop();
}
- void walkRootItem( root_item &rootItem, StmtList *stmtList )
+ void walkRootItem( root_item rootItem, StmtList *stmtList )
{
switch ( rootItem.prodName() ) {
case root_item::_Rl:
@@ -1905,8 +1923,7 @@ struct LoadColm
/* Walk the list of items. */
while ( !rootItemList.end() ) {
- root_item rootItem = rootItemList.value();
- walkRootItem( rootItem, stmtList );
+ walkRootItem( rootItemList.value(), stmtList );
rootItemList = rootItemList.next();
}
return stmtList;