demangle.go
func (st *state) exprPrimary() AST {
	st.checkChar('L')
	if len(st.str) == 0 {
		st.fail("expected primary expression")

	}

	// Check for 'Z' here because g++ incorrectly omitted the
	// underscore until -fabi-version=3.
	var ret AST
	if st.str[0] == '_' || st.str[0] == 'Z' {
		if st.str[0] == '_' {
			st.advance(1)
		}
		if len(st.str) == 0 || st.str[0] != 'Z' {
			st.fail("expected mangled name")
		}
		st.advance(1)
		ret = st.encoding(true, notForLocalName)
	} else {
		t := st.demangleType(false)

		neg := false
		if len(st.str) > 0 && st.str[0] == 'n' {
			neg = true
			st.advance(1)
		}
		if len(st.str) > 0 && st.str[0] == 'E' {
			st.fail("missing literal value")
		}
		i := 0
		for len(st.str) > i && st.str[i] != 'E' {
			i++
		}
		val := st.str[:i]
		st.advance(i)
		ret = &Literal{Type: t, Val: val, Neg: neg}
	}
	if len(st.str) == 0 || st.str[0] != 'E' {
		st.fail("expected E after literal")
	}
	st.advance(1)
	return ret
}
func (st *state) exprPrimary() AST {
	st.checkChar('L')
	if len(st.str) == 0 {
		st.fail("expected primary expression")

	}

	// Check for 'Z' here because g++ incorrectly omitted the
	// underscore until -fabi-version=3.
	var ret AST
	if st.str[0] == '_' || st.str[0] == 'Z' {
		if st.str[0] == '_' {
			st.advance(1)
		}
		if len(st.str) == 0 || st.str[0] != 'Z' {
			st.fail("expected mangled name")
		}
		st.advance(1)
		ret = st.encoding(true, notForLocalName)
	} else {
		t := st.demangleType(false)

		neg := false
		if len(st.str) > 0 && st.str[0] == 'n' {
			neg = true
			st.advance(1)
		}
		if len(st.str) > 0 && st.str[0] == 'E' {
			st.fail("missing literal value")
		}
		i := 0
		for len(st.str) > i && st.str[i] != 'E' {
			i++
		}
		val := st.str[:i]
		st.advance(i)
		ret = &Literal{Type: t, Val: val, Neg: neg}
	}
	if len(st.str) == 0 || st.str[0] != 'E' {
		st.fail("expected E after literal")
	}
	st.advance(1)
	return ret
}
func ( st * state ) exprPrimary ( ) AST { st . checkChar ( 'L' ) if len ( st . str ) == 0 { st . fail ( " " ) } // Check for 'Z' here because g++ incorrectly omitted the // underscore until -fabi-version=3. var ret AST if st . str [ 0 ] == '_' || st . str [ 0 ] == 'Z' { if st . str [ 0 ] == '_' { st . advance ( 1 ) } if len ( st . str ) == 0 || st . str [ 0 ] != 'Z' { st . fail ( " " ) } st . advance ( 1 ) ret = st . encoding ( true , notForLocalName ) } else { t := st . demangleType ( false ) neg := false if len ( st . str ) > 0 && st . str [ 0 ] == 'n' { neg = true st . advance ( 1 ) } if len ( st . str ) > 0 && st . str [ 0 ] == 'E' { st . fail ( " " ) } i := 0 for len ( st . str ) > i && st . str [ i ] != 'E' { i ++ } val := st . str [ : i ] st . advance ( i ) ret = & Literal { Type : t , Val : val , Neg : neg } } if len ( st . str ) == 0 || st . str [ 0 ] != 'E' { st . fail ( " " ) } st . advance ( 1 ) return ret }
// <expr-primary> ::= L <type> <(value) number> E
//                ::= L <type> <(value) float> E
//                ::= L <mangled-name> E
<expr - primary > :: = L <type > < ( value ) number > E :: = L <type > < ( value ) float > E :: = L <mangled - name > E