~otheb/i

7d89931282b9553b18aca64375d39fd35ac5dc19 — Olie Ayre 3 years ago c266cfb
Add Version parsing
2 files changed, 49 insertions(+), 3 deletions(-)

M model/decldefs.d
M util/parsing.d
M model/decldefs.d => model/decldefs.d +43 -1
@@ 12,7 12,8 @@ import std.variant ;

alias DeclDef = Algebraic!( VarDef , AliasDef , TypeMixin , FnDef , CtorDef ,
                            TypeDef , EnumDef , UnitTest , TemplateDef ,
                            StaticIf , StaticForeach , Mixin , Debug ) ;
                            StaticIf , StaticForeach , Mixin , Debug ,
                            Version ) ;
TypeInfo[] DeclDefSemicolons = [ typeid(VarDef) , typeid(AliasDef) ,
                                 typeid(TypeMixin) , typeid(Mixin) ] ;



@@ 438,3 439,44 @@ class Debug : AstBase {
		log.dbug!"parser"( "Created a Debug" ) ;
	}
}

class Version : AstBase {
	string    name        = "" ;
	string [] subVersions = [] ;
	DeclDef[] declDefs    = [] ;

	this( Token[] buffer ) {
		log.dbug!"parser"( "Trying to create a Version" ) ;
		startLoc( buffer ) ;
		// version
		this.token!Keyword( buffer , [ "version" ] ) ;
		// (
		this.token!Keyword( buffer , [ "(" ] ) ;
		// Id
		name = this.token!Id( buffer ).content ;
		// )
		this.token!Keyword( buffer , [ ")" ] ) ;
		// {
		this.token!Keyword( buffer , [ "{" ] ) ;
		// [{VersionSpec, DeclDef}...]
		log.dbug!"parser"( "bleh" ) ;
		while ( this.opt( {
			log.dbug!"parser"( "Trying a VersionSpec" ) ;
			// version
			this.token!Keyword( buffer , [ "version" ] ) ;
			// =
			this.token!Keyword( buffer , [ "=" ] ) ;
			// Id
			subVersions ~= this.token!Id( buffer ).content ;
			// ;
			this.token!Keyword( buffer , [ ";" ] ) ;
		} , {
			log.dbug!"parser"( "Trying a DeclDef" ) ;
			// DeclDef
			declDefs ~= this.node!DeclDef( buffer , DeclDefSemicolons ) ;
		} ) ) { }
		// }
		this.token!Keyword( buffer , [ "}" ] ) ;
		log.dbug!"parser"( "Created a Version" ) ;
	}
}

M util/parsing.d => util/parsing.d +6 -2
@@ 78,8 78,12 @@ T algebraic(T)( AstBase base , Token[] buffer , TypeInfo[] semicolons = [] )
				                   "Checking for a semicolon after the " ,
				                   typeid(t).text.split( "." )[ $ - 1 ] ) ;
				base.token!Keyword( buffer , [ ";" ] ) ;
			} ) ) perror( buffer[base.length].location , "Invalid " ,
			              typeid(t) ) ;
			} ) ) {
				if ( base.length >= buffer.length )
					error( Location( 0 , 0 ) , "Reached EoF" ) ;
				else perror( buffer[base.length].location , "Invalid " ,
				             typeid(t) ) ;
			}
		} else result = base.node!t( buffer ) ;
		if ( result.length > longestLength ) {
			longest       = T( result )   ;